Hi This form would be useful but on line 125 about 18 lines from the bottom is the mysqli query and the $sql variable where I get the fatal error. It also says line 116-123 the variables are undefined.
I might be getting an error from the connection line but I get the alert message connected successfully? I have a blank password. I have the User MySQL db created with the fields but maybe it is myISAM not mysqli? I have MySQL 5.2.6. I have PHP 5. This is line 125.
$mysqli = @new mysqli($hostname, $username, $password, $dbname);
/ check connection /
}//This closing curly bracket was missing (should it end here))
if(!mysqli_connect_errno())
{
There are 2 small related tables, State and Sport for the select list. How do I reference those in the form. Maybe that is the problem it can't find the related fields?
Or maybe it is because of the hidden ID field in the post? Do I assign the $submit variable to 0. That is not assigned.
Thanks,🙂
<?php
//form not yet submitted
if (!$submit)
{
?>
<html>
<head>
<title>Add a Company</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
function toForm() {
document.company.company_name.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=company method="post" action="<?php echo $PHP_SELF; ?>">
<input type="hidden" name="comp_id" value="<?php echo "$comp_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 company</em></strong></font></div></td>
</tr>
</table>
<br>
</div>
<table cellspacing=3 cellpadding=5 align="center" bgcolor='#e7f6b9'>
<tr>
<td> <p><strong>Name:</strong><br>
<input type="text" name="company_name" size=50 maxlength=75>
</p>
<p><strong>Address:</strong><br>
<input type="text" name="company_address" size=50 maxlength=75>
</p>
<p><strong>City:</strong><br>
<input type="text" name="company_city" size=50 maxlength=75>
</p>
<p><strong>State:</strong><br>
<input type="text" name="company_state" size=50 maxlength=75>
</p>
<p><strong>Zip:</strong><br>
<input type="text" name="company_zip" size=50 maxlength=75>
</p>
<p><strong>Company Phone (main number):</strong><br>
<input type="text" name="company_phone" size=50 maxlength=75>
</p>
<p><strong>Company Fax (main number):</strong><br>
<input type="text" name="company_fax" size=50 maxlength=75>
</p>
<p><strong>Company Website:</strong><br>
<input type="text" name="company_website" size=50 maxlength=75>
</p></td>
</tr>
<tr>
<td align="center"> <p>
<input type="submit" name="submit" value="Submit Company">
</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 = 'user';
/*** mysql password ***/
$password = 'password';
/*** mysql database name ***/
$dbname = 'test';
/*** 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 elements set
comp_name = '$company_name',
comp_address = '$company_address',
comp_city = '$company_city',
comp_state = '$company_state',
comp_zip = '$company_zip',
comp_phone = '$company_phone',
comp_fax = '$company_fax',
comp_website = '$company_website'";
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();
}
?>