struggling with php edit/update form
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
just can't work out where it is going wrong
Thank you in advance
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.
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
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:
Then when referencing the id in your query, just change the $_GET['id'] to $_POST['id']
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
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']."',
should be replaced by:
"UPDATE sgrjobs SET ref='$ref',role='$role',contract='$contract',
You can also try out with the below link:
Hope this helps.
Last edited by priyankagound; 11-23-2013 at 05:38 AM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)