Click here to Skip to main content
14,644,142 members
Rate this:
Please Sign up or sign in to vote.
See more:
i have this code and it doesn't show any errors but it did not update the record.

why is that? a little help please.


if (isset($_POST['submit']))
mysql_query("UPDATE indigo21IT SET LastName='$_POST[lastname]', GivenName='$_POST[givenname]', MiddleName='$_POST[middlename]' WHERE ID='$id'")
or die(mysql_error());

header("Location: main.php");

$id = $_GET['id'];

$result = mysql_query("SELECT * FROM indigo21IT where ID=$id");

kind regards
Er. Tushar Srivastava 25-Sep-12 9:32am
You have included connect_db.php can I see the file....

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Unless you have other php on the page that isn't included in the question, at the point where you're running the query the variable $id does not have a value. The record won't update because the query likely will not find a record with a blank id number.

I also notice that you are retrieving data from both the $_GET and $_POST, normally you'd only be retrieving stuff from one or the other but not usually both.
Mohibur Rashid 19-Sep-12 20:53pm
Good catch with id value empty thing and also bad comment about either GET or POST

you can easily send post data to and php will accept somevar as get method and also post value.
SquidSK 21-Sep-12 10:32am
You're probably thinking about $_RESPONSE not $_POST. No post value is ever visible to a user on the url. You can retrieve a value from both $_GET and $_RESPONSE or you can retrieve a value from $_POST and $_RESPONSE, but not from $_GET and $_POST since they are filled by HTTP GET method and HTTP POST method respectively, which are not equivalent.

Mohibur Rashid 21-Sep-12 21:37pm
nope, $_RESPONSE is out of my thinking. ...
bye the way I already showed an example in my comment. if you don't understand that. ask me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100