Unable to update and delete

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kashigal
    New Member
    • Jul 2007
    • 1

    #1

    Unable to update and delete

    [PHP]
    <?
    session_start() ;

    require("db.php ");

    mysql_connect(M ACHINE, USER, '');
    mysql_select_db (DBNAME);

    $username = $_SESSION['username'];
    $pwd =$_SESSION['pwd'];

    if(isset($usern ame)){

    $customerid = $_POST['customerid'];
    $customername = $_POST['customername'];
    $customercontac t = $_POST['customercontac t'];
    $orderid = $_POST['orderid'];

    $sql = "SELECT * FROM customer";

    $result = mysql_query($sq l) or die("Unable to get order info");

    $row = mysql_fetch_ass oc($result);
    extract($row);

    }
    ?>

    <html>
    <head>
    <title>Update Customer Details</title>
    </head>
    <body>
    <form action="do_upda tecustomer.php? action=do_updat ecustomer&order id=<?php echo $orderid; ?>" enctype="multip art/form-data" method='post'>< br>
    <link rel="stylesheet " type="text/css" href="fyp.css" />
    <b></b><br><br>
    <table border="0">

    <tr><td>Custome r Name:</td>
    <td><input type="text" name ="customerna me" value ="<?php echo $customername; ?>"></td></tr>

    <tr><td>Custome r Contact:</td>
    <td><input type="text" name ="customerconta ct" value ="<?php echo $customercontac t; ?>"></td></tr>

    <tr><td>Order ID:</td>
    <td><input type="text" name ="orderid" value ="<?php echo $orderid; ?>"></td></tr>

    <tr><td><inpu t type="reset" value="Reset"></td>
    <td><input type = "Submit" name="submit" value="Update"> </td></tr>

    </table>
    </form>
    </body>
    </html>


    <?

    session_start() ;

    require("db.php ");

    mysql_connect(M ACHINE, USER, '');
    mysql_select_db (DBNAME);

    if (isset($_POST['submit']))
    {
    $customerid = $_GET['customerid'];
    $customername = $_POST['customername'];
    $customercontac t = $_POST['customercontac t'];
    $orderid = $_POST['orderid'];


    $sql = "UPDATE 'customer' SET 'customername' = '$customername' ,
    'customercontac t' = '$customerconta ct','orderid' = '$orderid' WHERE 'customerid' = '$customerid'";

    $result = mysql_query($sq l) or die ("Unable to Update Customer Information");
    }


    //echo "Customer Details has been updated from database.";


    //<br><br>
    //"<a href=cus_detail s.php>View Customer Details</a><br>";
    //"<a href=index.php> Go to Mainpage</a><br>";
    ?>
    [/PHP]

    I can't seem to update...Could someone be so kind to help me check my codes =)
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Can you explain "it cant seem to update"?

    Use this query to update
    Code:
    $sql = "UPDATE customer SET customername = '$customername',
            customercontact = '$customercontact', orderid = '$orderid' WHERE customerid = '$customerid'";
    You were using single quotes instead of back tick (`) around table name and column.

    Comment

    • mwasif
      Recognized Expert Contributor
      • Jul 2006
      • 802

      #3
      Also replace your update query line to this

      [PHP]$result = mysql_query($sq l) or die ("Unable to Update Customer Information. Error: ".mysql_error() );[/PHP]

      mysql_error() will return the sql error.

      Comment

      Working...