Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP MySQL
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.
 
<?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 17-Sep-12 1:07am
Comments
Tushar Sriv at 25-Sep-12 9:32am
   
You have included connect_db.php can I see the file....

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
Mohibur Rashid at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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