-1

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>
  • What is there at line 33 ? which on the above is `updateaccount.php` – Makesh May 19 '15 at 10:59
  • From where you are getting $_POST['username'], $_POST['password'] , etc ?? These variables not exists in $_POST , so you are getting the this error. – Sameer K May 19 '15 at 11:00
  • In code snippet-2, where you defined `$customerno` . check at line :9 : `$firstname=$_POST['customerno'];` – Makesh May 19 '15 at 11:02
  • 1
    Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 19 '15 at 11:54

1 Answers1

0

declare $customerno

Modify to :

echo "<pre>\$_post", print_r($_POST),"</pre>";
$customerno =$_POST['customerno']; // Focus this line:9
$firstname=$_POST['firstname'];
Makesh
  • 1,236
  • 1
  • 11
  • 25