PHP script not updating mysql..what am I doing wrong?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sturmdogg
    Junior Member
    • Apr 2004
    • 12

    #1

    PHP script not updating mysql..what am I doing wrong?

    Hi guys,

    I have this script that's supposed to update existing records in mysql, but for some reason it doesnt. It's weird because I can add and delete records, but not modify. Can anyone look at the script and tell me what I'm doing wrong? Thanks!

    PHP script
    --------------------------------------------------------------------------------------

    <?
    // START PHP CODES. THIS PART MUST ON THE TOP OF THIS PAGE.

    // Connect database.
    include 'config.php';
    include 'opendb.php';

    // ***** This part will process when you Click on "Submit" button *****
    // Check, if you clicked "Submit" button
    if($Submit){

    // Get parameters from form.
    $id=$_POST['id'];
    $establishment=$_POST['establishment'];
    $code=$_POST['code'];
    $zipcode=$_POST['zipcode'];
    $expiry_date=$_POST['expiry_date'];



    // Do update statement.
    mysql_query("UPDATE upload2 SET establishment='$establishment', code='$code', zipcode='$zipcode' , expiry_date='$expiry_date' where id='$id'");

    // Close database connection.
    mysql_close();

    // Re-direct this page to select.php.
    header("location:coupons_admin.php");
    }
    // ************* End update part *************
    ?><?
    // *** Select data to show on text fields in form. ***

    // Get id parameter (GET method) from select.php
    $id=$_GET['id'];

    // Get records in all columns from table where column id equal in $id and put it in $result.
    $result=mysql_query("select * from upload2 where id='$id'");

    // Split records in $result by table rows and put them in $row.
    $row=mysql_fetch_assoc($result);

    // Close database connection.
    mysql_close();
    ?>



    HTML form
    --------------------------------------------------------------------------------------

    <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
    <table width="396" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr>
    <td width="142" class="style119">Establishment:</td>
    <td width="247"><input name="establishment" type="text" id="establishment" value="<? echo $row['establishment']; ?>"></td>
    </tr>
    <tr>
    <td class="style119">Coupon Code: </td>
    <td><input name="code" type="text" id="code" value="<? echo $row['code']; ?>"></td>
    </tr>

    <tr>
    <td class="style119">Zip Code: </td>
    <td><input name="zipcode" type="text" id="zipcode" value="<? echo $row['zipcode']; ?>"></td>
    </tr>
    <tr>
    <td class="style119">Expiry Date: </td>
    <td><input name="expiry_date" type="text" id="expiry_date" value="<? echo $row['expiry_date']; ?>"></td>
    </tr>

    <tr>
    <td colspan="2"><div align="center">
    <input name="Submit" type="submit" class="box" id="submit" value="Submit">
    </div></td>
    </tr>
    </table>
    </form>
  • Elite
    Senior Member
    • Apr 2004
    • 168

    #2
    Originally posted by sturmdogg
    // Do update statement.
    mysql_query("UPDATE upload2 SET establishment='$establishment', code='$code', zipcode='$zipcode' , expiry_date='$expiry_date' where id='$id'");
    IIRC Numeric field values should not be enclosed in quotes (only text fields such as varchar etc) - I don't know your database setup but I would guess that at least the field id is an integer.

    Also I can't see how you are passing the $id from the form - shouldn't you have a hidden form field with the id? So something like:

    Code:
    <input name="id" type="hidden" id="id" value="<? echo $row['id']; ?>">
    HTH

    Comment

    • sturmdogg
      Junior Member
      • Apr 2004
      • 12

      #3
      *sigh*

      I knew it was something simple I overlooked.

      /me beats head against the wall

      Thanks!

      Comment

      Working...