i have been doing a project in college and so far it is going rather well but i have hit a brick wall...
The information that is passed through this does not update in the phpmyadmin database. I can't see why. Snippet 2 contains all the code for updating the table but it wont for some reason.
Could someone please help as i only have 2 days left to hand this in. I have attached my code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Book library</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
ini_set ( 'display_errors', 'On' );
$username = $_POST ['username'];
$password = $_POST ['password'];
$customerno = $_POST ['customerno'];
echo "<pre>\$_post", print_r ( $_POST ), "</pre>";
@ $db = mysql_pconnect ( 'localhost', 'root', '' );
if (! $db) {
echo 'Error: Could not connect to database. Please
try again later.';
exit ();
}
mysql_select_db ( "assessment" );
$query = "select * from customers where username = '$username'
and password = '$password'";
$result = mysql_query ( $query );
$num_results = mysql_num_rows ( $result );
$row = mysql_fetch_array ( $result );
extract ( $row ); //extract -
creates variables with the same name as the fields in the
array if ($num_results != 0) {
echo "<p>If you would
like to change your information below, enter it in the boxes
below.</p>";
echo "<form action='updateaccount.php'
method='post'> Customer No<br> <input type = 'text' name =
'customerno' value = '$customerno' readonly> </br> First name<br
> <input type = 'text' name = 'firstname' value = '$firstname'>
</br> Last name<br> <input type = 'text' name = 'lastname'
value = '$lastname'> </br> Address<br> <input type =
'text' name = 'address' value = '$address'> </br> Town<br>
<input type = 'text' name = 'town' value = '$town'> </br>
Postcode<br> <input type = 'text' name = 'postcode' value =
'$postcode'> </br> Email<br> <input type='text' name='email'
maxlength='60' size='30' value = '$email'></br> <input name=
'submit' type='submit' value='Continue'> </form>";
} else {
echo "Incorrect try again!!";
}
?> </p>
</body>
</html>
The page that changes the info
<html>
<head>
<title>Scotia Books Entry Results</title>
</head>
<body>
<h1>Scotia Books Entry Results</h1> <?php
echo "<pre>\$_post", print_r ( $_POST ), "</pre>";
$firstname = $_POST ['customerno'];
$firstname = $_POST ['firstname'];
$lastname = $_POST ['lastname'];
$address = $_POST ['address'];
$town = $_POST ['town'];
$postcode = $_POST ['postcode'];
$email = $_POST ['email'];
if (! $firstname || ! $lastname || ! $address || ! $town || ! $postcode || ! $email) {
echo 'You have not entered all the information<br />' . 'Please go back and try again.';
exit ();
}
$db = mysql_connect ( 'localhost', 'root', '' );
if (! $db) {
echo 'Error: Could not connect to database. Please try again later.';
exit ();
} else
mysql_select_db ( 'assessment' );
$query = "update customers set firstname = '$firstname', lastname = '$lastname', address = '$address', town='$town', postcode = '$postcode, email = '$email' where customerno = '$customerno'";
$result = mysql_query ( $query );
if ($result)
echo mysql_affected_rows () . ' Information updated';
else
echo 'did not work';
mysql_close ( $db );
?> </body>
</html>