I have just set up serve on my pc and got php and mysql and stuff
I am trying to get started by using a very simple script to gather data from a form and add it to the database and then read all teh data into a table. I am using a book and i have all the code right i am sure but it is not working. What i do not understand is that it worked the first tiem i did it but not anymore :S
Can anyone maybe help me by testign the files on there server or somthing? or shall i post code on this site?
OR does anyone know of anything (any settings) that i might have to change? Thanks veyr much James
I know i have the db and table set up ok!
THE FORM
<form name="form1" method="post" action="handle_form.php">
<p>First Name
<input name="Array[firstName]" type="text" id="sadfsdf">
</p>
<p>Last Name
<input name="Array[lastName]" type="text" id="Array[firstName]">
</p>
<p>EMail Address
<input type="text" name="Array[email]">
</p>
<p>DOB
<input type="text" name="Array[DOB]">
</p>
<p>Info
<textarea name="Array[info]"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
HANDLE PAGE
<?php
//Database Info
$host = "localhost";
$user = "";
$password = "";
$dbName = "jmusers";
$tableName = "userInfo";
//Connect to the database
$link = mysql_connect($host, $user, $password);
$query = "INSERT into $tableName values
(\'0\', \'$Array[firstName]\',\'$Array[lastName]\',\'$Array[email]\',\'$Array[DOB]\',\'$Array[info]\')";
print "The query is:<BR>$query<P>n";
if (mysql_db_query($dbName, $query, $link)) {
print "The query was successfully executed<br><br>";
}
else {
print "The query could not be executed";
}
//close the link to the database
mysql_close($link);
?>
GET DB DATA PAGE
<?php
//Database Info
$host = "localhost";
$user = "";
$password = "";
$dbName = "jmusers";
$tableName = "userInfo";
//Connect to the database
$link = mysql_connect($host, $user, $password);
$query = "SELECT * from $tableName";
$result = mysql_db_query ($dbName, $query, $link);
//creat a table to show the table results in
print "<table border=1 width ="100%" cellspacing=2 cellpadding=2 align=center>n";
print "<tr align=center valign=top>n";
print "<td align=center valigntop>Name</td>n";
print "<td align=center valigntop>EMail</td>n";
print "<td align=center valigntop>DOB</td>n";
print "<td align=center valigntop>Comments/Info</td>n";
print "</tr>n";
//fetch the results from the database
while ($row = mysql_fetch_array($result)) {
print "<tr align=center valign=top>n";
print "<td align=center valign=top>$row[firstName] $row[firstName]</td>n";
print "<td align=center valign=top>$row[email]</td>n";
print "<td align=center valign=top>$row[DOB]</td>n";
print "<td align=center valign=top>$row[info]</td>n";
print "</tr>n";
}
//close the link to the database
mysql_close($link);
print "</table>n";
?>