I am using Yahoo as my webhosting company for my website using MySQL 3.23.49 and PHP Version 4.3.6.
I am trying to create a simple HTML form that a user fills out then calls upon a php file to display the message that I received their information and then I would like it to add the information to mySQL database.
I am able to INSERT a first name and last name into the database using the GUI which I did successfully, however, I am not sure what I am doing wrong with the php code. If someone could assist I would greatly appreciate it! I have searched on google, w3schools, this forum and could not find my answer.
I am a newbie, so please be gentle. THANK YOU IN ADVANCE!
HTML FORM:
<form method=post action="create_db.php">
<table width="70%" align="center">
<tr>
<td width="7%" height="26" bgcolor="#FFFFFF"> <div align="center"><font color="#FFFFFF" face="Arial"></font></div></td>
<td width="86%" bgcolor="#660033"> <div align="center"><font color="#FFFFFF" face="Arial"><strong>Personal
Information </strong></font></div></td>
<td width="7%" bgcolor="#FFFFFF"> </td>
</tr>
</table>
<table width=516 border=0 align="center" cellpadding=0>
<tr valign="bottom">
<td width="102" height="33" align=right> <div align="left"><font face=arial size=-1>
</font><font face=arial size=-1><b> First Name:</b></font>
</div></td>
<td width="147" align=right><div align="left">
<input name="firstname" type=textsize=20>
</div></td>
<td width="106" align=left> <div align="left"><font face=arial size=-1>
</font><font face=arial size=-1><b>Last Name:</b></font>
</div></td>
<td width="151" align=left><input name="lastname" type=text size=20></td>
</tr>
<tr valign="bottom">
<td height="33" align=right> <div align="left"><font face=arial size=-1> <b>Address:</b></font>
</div></td>
<td height="33" align=right><div align="left">
<input name="address" type=textsize=20>
</div></td>
<td align=left> <font face=arial size=-1><b>City:</b></font>
</td>
<td align=left><input name="city" type=text size=20></td>
</tr>
<tr valign="bottom">
<td height="33" align=right> <div align="left"><font face=arial size=-1> <b>State:</b></font>
</div></td>
<td height="33" align=right><div align="left">
<input name="state" type=text size=20>
</div></td>
<td align=left> <font face=arial size=-1><b>Zip:</b></font>
</td>
<td align=left><input name="zip" type=text size=20></td>
</tr>
<tr valign="bottom">
<td height="33" align=right> <div align="left"><font face=arial size=-1> <b>Phone:</b></font>
</div></td>
<td height="33" align=right><div align="left">
<input name="phone" type=text size=20>
</div></td>
<td align=left> <font face=arial size=-1><b>Fax:</b></font>
</td>
<td align=left><input name="fax" type=text size=20></td>
</tr>
<tr valign="bottom">
<td height="33" align=right> <div align="left"><font face=arial size=-1> <b>Email:</b></font>
</div></td>
<td height="33" align=right><div align="left">
<input name="email" type=text size=20>
</div></td>
<td align=left> <font face=arial size=-1><b>Business Name:</b></font>
</td>
<td align=left><input name="busname" type=text size=20></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td height="33" align=right valign="bottom"> <div align="left"><font face=arial size=-1><b>URL:</b></font>
</div></td>
<td height="33" align=right valign="bottom"><div align="left">
<input name="url" type=text id="url" size=20>
</div></td>
</tr>
<tr>
<td colspan=4 valign=top align=center> <font face=arial size=-1>
</font> <p>
<input type="submit" value="Send">
<input type="reset" value="Clear the form">
</td>
</tr>
</table>
</div>
</form>
PHP CODE:
<?php
$db=mysql_connect("localhost", "un", "pw") or die("Could not connect to localhost."); mysql_select_db("clients", $db) or die("Could not find clients.");
//the above host, un and pw was replaced with my actual information
$querymySQL = "INSERT INTO users (firstname, lastname) VALUES ('$firstname', '$lastname')";
if(!$querymySQL) error_message(mysql_error());
echo "Hello, $firstname";
echo "<BR>";
echo "Your information has been received!";
?>