I asked this question yesterday but I fixed some errors and now I only have one question, sorry. I get the error message mysqli "cannot connect" at the bottom. The fields are right, the database is right, the database user name is right. I checked php.info if I have mysqli and I have it enabled. When I run this code all I get is "unable to connect" and the input form doesn't render. There is an error number alert but I can't see it. How can I tell what the connetion error is?
thanks,
php info
MYSQLI_SOCKET /var/mysql/mysql.sock
Directive Local Value Master Value
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket /tmp/mysql.sock /tmp/mysql.sock
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.reconnect Off Off
<?php
//form not yet submitted
//if (!$submit)
if(isset($_POST['submit']))
{
?>
<html>
<head>
<title>Add a Company</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
function toForm() {
document.user.Fname.focus();
}
</script>
<body onLoad="toForm()" BGCOLOR=#FFFFFF topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 rightmargin=0 bottommargin=0>
<center>
<table border=0 cellpadding=3 cellspacing=0 width=100% vailn=top>
<!-- server side include leftside nav table -->
<table border=0 cellpadding=3 cellspacing=0 width=99%>
<form name=User method="post" action="<?php echo $PHP_SELF; ?>">
<input type="hidden" name="ID" value="<?php echo "$ID"; ?>">
<tr>
<td width=100%><div align="center"><br>
<table width="345" border="0">
<tr>
<td bgcolor="#000066"><div align="center"><font color="#FFFFFF" size="4"><strong><em>Add
a user</em></strong></font></div></td>
</tr>
</table>
<br>
</div>
<table cellspacing=3 cellpadding=5 align="center" bgcolor='#e7f6b9'>
<tr>
<td> <p><strong>First Name:</strong><br>
<input type="text" name="User.Fname" size=50 maxlength=75>
</p>
<p><strong>Middle Initial</strong><br>
<input type="text" name="MIname" size=50 maxlength=75>
</p>
<p><strong>Lname</strong><br>
<input type="text" name="Lname" size=50 maxlength=75>
</p>
<p><strong>Apt. or Suite</strong><br>
<input type="text" name="Addrs1" size=50 maxlength=75>
</p>
<p><strong>Street Address</strong><br>
<input type="text" name="Addrs2" size=50 maxlength=75>
</p>
<p><strong>City</strong><br>
<input type="text" name="City" size=50 maxlength=75>
</p>
<p><strong>State</strong><strong>Zip</strong><strong>4 digit Zip extension</strong><br>
<input type="text" name="State" size=2 maxlength=2>
<input type="text" name="Zip1" size=5 maxlength=5>
<input type="text" name="Zip2" size=4 maxlength=4>
</p>
<p><strong>Select available sport(s):</strong>
<select name="name" size="8">
<option value="Swimming">Swimming</option>
<option value="Biking">Biking</option>
<option value="Hiking">Hiking</option>
<option value="Golfing">Golfing</option>
<option value="Skiing">Skiing</option>
<option value="Basketball">Basketball</option>
<option value="Soccer">Soccer</option>
<option value="Tennis">Tennis</option>
<option value="Football">Football</option>
<option value="Basketball">Basketball</option></select>
</p></td>
</tr>
<tr>
<td align="center"> <p>
<input type="submit" name="submit" value="Submit User">
</p></td>
</tr>
<tr> </tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
}//Is this the close of the first if statement?
else
{//Where is this else block supposed to end?
/ mysql hostname /
$hostname = 'localhost';
/ mysql username /
$username = 'dhandler';
/ mysql password /
$password = '';
/ mysql database name /
$dbname = 'Greythorne';
/ create a new mysqli object with default database/
$mysqli = @new mysqli($hostname, $username, $password, $dbname);
/ check connection /
}//This closing curly bracket was missing (should it end here))
if(!mysqli_connect_errno())
{
/ if we are successful /
echo 'Connected Successfully<br />';
/ sql to INSERT a new record /
$sql = "INSERT INTO User set
Fname = '$Fname',
MIname = '$MIname',
Lname = '$Lname',
Addrs1 = '$Addrs1',
Addrs2 = '$Addrs2',
City = '$City',
State = '$State_ID',
Zip1 = '$Zip1',
Zip2 = '$Zip2',
Sports = '$Sport_ID'";
if($mysqli->query($sql) === TRUE)
{//this appears to be a nested if else statement, is this correct?
echo 'New record created successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
/ close connection /
$mysqli->close();
}//should this be where the if($mysqli->query($sql)==TRUE)is supposed to end)
else
{
/ if we are unable to connect /
echo 'Unable to connect';
exit();
}
?>