xcoderx Posted July 29, 2010 Share Posted July 29, 2010 why is it not updating? <?php $_POST['email']; $_POST['submit']; if (isset($_POST['submit'])) { /*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/ $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."', WHERE mem_id='".$_POST['mem_id']."'") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/ Share on other sites More sharing options...
Wolphie Posted July 29, 2010 Share Posted July 29, 2010 It's not updating because of the second line. You just have $_POST; sitting there doing nothing. You also are missing the quotes around the array key. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092608 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 fixed that already but still not updating Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092610 Share on other sites More sharing options...
Maq Posted July 29, 2010 Share Posted July 29, 2010 Turn on error reporting and output your query. Like Wolphie said, I'm not sure those POSTs at the top of your script are valid, take them out. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092617 Share on other sites More sharing options...
Pikachu2000 Posted July 29, 2010 Share Posted July 29, 2010 Get your query string out of the query execution and echo it. You can't possibly know if it contains the values it should contain without doing that. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092619 Share on other sites More sharing options...
Alex Posted July 29, 2010 Share Posted July 29, 2010 You have a comma after setting the value of email but you're only updating 1 column, remove it. $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092622 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 still it wont :-( ok here is the whole page <?php //Start session session_start(); //Check the session MEMBER_ID is present or not if(!isset($_SESSION['S_UID']) || (trim($_SESSION['S_UID']) == '')) { header("location: access-denied.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>My Profile</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $_POST['email']; $_POST['submit']; if (isset($_POST['submit'])) { /*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/ $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'") or die(mysql_error()); } ?> <h1>My Profile <?php echo $_SESSION['S_UID'];?></h1> <a href="member-index.php">Home</a> | <a href="logout.php">Logout</a> <p>This is another secure page. </p> <form action="member-profile.php" method="post"> <input type="text" name="email" /> <input type="submit" value="update" /> </form> </body> </html> what could possibly be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092627 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2010 Share Posted July 29, 2010 Your <input type='submit' field does not have a name='...' attribute so $_POST['submit'] will never be set. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092630 Share on other sites More sharing options...
Maq Posted July 29, 2010 Share Posted July 29, 2010 Are you sure you're even getting into the if statement? Because what AlexWD pointed out should have triggered the or die and it didn't. What PFM said. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092631 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 Your <input type='submit' field does not have a name='...' attribute so $_POST['submit'] will never be set. yes bro i seen that i added name="submit' but still it will not update Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092634 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 noone can help me with it? im still stuck :-( Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092675 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2010 Share Posted July 29, 2010 No one can really help you without seeing the current code. You either added the name="..." attribute incorrectly or you did not bother to refresh your browser to incorporate the change into the html the browser is operating on. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092678 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 the current code is this looks all ok but does not update anything in db. browser had been refreshed too <?php require_once('config.php'); //Start session session_start(); //Check the session MEMBER_ID is present or not if(!isset($_SESSION['S_UID']) || (trim($_SESSION['S_UID']) == '')) { header("location: access-denied.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>My Profile</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $_POST['email']; $_POST['submit']; if (isset($_POST['submit'])) { /*$sql =" UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."' ";*/ $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'") or die(mysql_error()); } ?> <h1>My Profile <?php echo $_SESSION['S_UID'];?></h1> <a href="member-index.php">Home</a> | <a href="logout.php">Logout</a> <p>This is another secure page. </p> <form action="member-profile.php" method="post"> <input type="text" name="email" /> <input type="submit" name="submit" value="update" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092687 Share on other sites More sharing options...
Jessica Posted July 29, 2010 Share Posted July 29, 2010 You keep ignoring several very good suggestions to get help. Here's another: add print_r($_POST); before your query. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092693 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 i do not understand quick thats a problem with me. ok i did the print_r post and i got this Array ( => [submit] => update ) Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092697 Share on other sites More sharing options...
Jessica Posted July 29, 2010 Share Posted July 29, 2010 i do not understand quick thats a problem with me. ok i did the print_r post and i got this Array ( => [submit] => update ) Where did you put it? Show your code every time. So go back and read what Wolphie and Mac said. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092698 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2010 Share Posted July 29, 2010 Your form is not setting a field named - 'mem_id' so it will be a little hard for the where clause in your query to match anything - ... WHERE mem_id='".$_POST['mem_id']."'" Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092700 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 @jesirose now it should be right? $email = $_POST['email']; if (isset($_POST['submit'])) { print_r($_POST); /*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/ $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_POST['mem_id']."'") or die(mysql_error()); } @PFM bro man now am i goin set the field name mem_id tell me please im now starting to give up. i guess there should be a hidden field to assign the mem_id? i do not know how to get it done at all :-( Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092712 Share on other sites More sharing options...
KevinM1 Posted July 29, 2010 Share Posted July 29, 2010 Where should mem_id be coming from? Even if you have a hidden field for it, the value must come from somewhere, right? It just seems like you're skipping steps. Remember, you need to explicitly tell PHP to do everything you want to do. In your head it's automatic to think that "oh, yeah, I'll match my query on the member's id." PHP has no notion of that unless you tell it to do that. Nothing is automatic. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092717 Share on other sites More sharing options...
Maq Posted July 29, 2010 Share Posted July 29, 2010 I see a couple of issues: 1) You're not passing a mem_id via POST. Maybe you store it in $_SESSION['S_UID']; ? 2) The email field is blank... 3) You don't sanitize your input to the DB. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092718 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 yes thats true im storing the mem_id in session but how come email field is blank? therefore how am i goin to get it to work please show me examples for im not too cinfident with all these yet im only trying all i could. Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092720 Share on other sites More sharing options...
xcoderx Posted July 29, 2010 Author Share Posted July 29, 2010 i tried this now $email = $_POST['email']; $mem_id = $_SESSION['S_UID']; if (isset($_POST['submit'])) { print_r($_POST); /*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/ $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$_SESSION['mem_id']."'") or die(mysql_error()); still now luck Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092725 Share on other sites More sharing options...
xcoderx Posted July 30, 2010 Author Share Posted July 30, 2010 anyone help solve it? Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1092996 Share on other sites More sharing options...
xcoderx Posted July 30, 2010 Author Share Posted July 30, 2010 damn i did it :-) and it is updatng the field but is this the right way i did? $email = $_POST['email']; $mem_id['mem_id'] = $_SESSION['S_UID']; if (isset($_POST['submit'])) { print_r($_POST); /*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/ $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."' WHERE mem_id='".$mem_id['mem_id']."'") or die(mysql_error()); } i retrived the mem_id from the session where i stored it so i did it the right way? Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1093006 Share on other sites More sharing options...
Jessica Posted July 30, 2010 Share Posted July 30, 2010 so i did it the right way? Is it working? Quote Link to comment https://forums.phpfreaks.com/topic/209235-not-updating-query/#findComment-1093232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.