Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

PERL
<?php
include('connect_db.php');

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
Posted
Comments
Er. Tushar Srivastava 25-Sep-12 9:32am    
You have included connect_db.php can I see the file....

1 solution

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.
 
Share this answer
 
Comments
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 www.something.com?somevar=somevalue 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.

See http://www.w3schools.com/php/php_post.asp
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900