Hi, I recently started learning PHP and have been reading a tutorial about posting to databases and retrieving data and displaying data from databases. I copied the code from the tutorial EXACTLY as it is (except for filenames and passwords etc.). The code is for a simple contact list. You enter data into form, it sends it to a page to be processed, then you look on another page and it displays the results.
However, the code does not seem to be submitting any data to the database. The correct number of entries are displayed, but the fields are left blank. I will post all of the code...
Creating The Table (test1.php):
<html>
<head>
</head>
<body>
<?
$user="fbacall";
$password="*********";
$database="fbacall_uk_db";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close();
?>
Database Created
</body>
</html>
The Form (test2.php):
<html>
<head>
</head>
<body>
<form action="test3.php" method="get">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit">
</form>
</body>
</html>
The "processing page" (test3.php):
<html>
<head>
</head>
<body>
<?
$username="fbacall";
$password="********";
$database="fbacall_uk_db";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);
mysql_close();
?>
Data inserted
</body>
</html>
Displaying the Results (test4.php):
<html>
<head>
</head>
<body>
<?
$user="fbacall";
$password="********";
$database="fbacall_uk_db";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");
echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";
++$i;
}
?>
</form>
</body>
</html>
Any help would be much appreciated
-Fuzz
PS. I am hosting my PHP on lycos (yes it does support php and mysql)