www.webdeveloper.com
Results 1 to 4 of 4

Thread: struggling with php edit/update form

  1. #1
    Join Date
    Apr 2012
    Posts
    35

    struggling with php edit/update form

    Hi

    I got two issues I think

    I got a edit.php page and it has a form that should update a mysql record but it is not doing so

    If I don't select any active or inactive radio button, I get the following error

    Notice: Undefined index: status in /home/sites/irhwebsites.com/public_html/sites/sgr/admin/edit.php on line 18

    If I do select a active or inactive radio button, the form just resets itself and does nothing

    I have pasted the coding from the edit.php into pastebin and included the link below

    http://pastebin.com/zwqpGMw9

    just can't work out where it is going wrong

    Thank you in advance

    Ian

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    519
    The message means that you have a bad index reference in an array variable. You are using an array such as $my_ar wherein the indice is not valid, i.e., $my_ar[$x] where $x hasn't been given a value, or the value is not present in the array. Perhaps you have 2 items in your array and $x is > 1.

  3. #3
    Join Date
    Aug 2012
    Posts
    155
    The reason for your error is that you are checking to see if posted values are empty but with your radio buttons they already have values (which is correct) so the value will never by empty but if neither of the radio buttons is selected then that post variable won't be set and that is why you get the Undefined Index.

    Therefore change your
    Code:
    && $_POST['status']!=""
    to
    Code:
    && isset($_POST['status'])
    With regard to the 2nd problem (submitting your form) it is because you are trying to mix post and get - a form's data can only be sent using one or the other and post is generally better, which you are using in the method of your form.

    To send the id you just create a hidden field and remove the get parameter from your form action:
    HTML Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
    Then when referencing the id in your query, just change the $_GET['id'] to $_POST['id']

  4. #4
    Join Date
    Sep 2013
    Posts
    221
    First place the below code in your start:

    $ref = mysql_real_escape_string($_POST['ref']);
    $role = mysql_real_escape_string($_POST['role']);
    $contract = mysql_real_escape_string($_POST['contract']);

    Well..., according to my observation in your code:

    "UPDATE sgrjobs SET ref='".$_POST['ref']."',
    role='".$_POST['role']."',
    contract='".$_POST['contract']."',

    should be replaced by:
    "UPDATE sgrjobs SET ref='$ref',role='$role',contract='$contract',

    You can also try out with the below link:
    https://netbeans.org/kb/docs/php/wish-list-lesson7.html

    Hope this helps.
    Last edited by priyankagound; 11-23-2013 at 04:38 AM.
    strad solutionswww.stradsolutions.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles