不插入phpmyadmin数据库

时间:2015-05-19 10:52:37

标签: php html mysql forms post

我一直在大学里做一个项目,到目前为止它的进展相当顺利,但我已经碰壁了......

通过此传递的信息不会在phpmyadmin数据库中更新。我不明白为什么。小部件2包含更新表的所有代码,但它不会出于某种原因。

有人可以帮忙,因为我还有2天的时间可以帮忙。我附上了我的代码。

<!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>

更改信息的页面

<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>

1 个答案:

答案 0 :(得分:0)

声明$ customerno

修改为:

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