Shadowing Posted December 12, 2011 Share Posted December 12, 2011 I must be using the wrong search terms in google cause I cant find out how to update a field to a blank spot. trying to make name blank. I thought it was just " " hope someone can please help me with this mysql_query("UPDATE users SET name = '".mysql_real_escape_string "."' WHERE id = '".mysql_real_escape_string($_SESSION['user_id']))."'"; Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/ Share on other sites More sharing options...
-Karl- Posted December 12, 2011 Share Posted December 12, 2011 ' ', is correct, it must be the ID that it's not locating. Have you tried echo'ing $_SESSION['user_id']? Or perhaps try printing the query. $query = "UPDATE users SET name = '".mysql_real_escape_string ."' WHERE id = '".mysql_real_escape_string($_SESSION['user_id']))."'"; $run = mysql_query($query); EDIT: Actually, I've just noticed there's a few errors in your line of code, try this: mysql_query("UPDATE users SET name = '' WHERE id = '".mysql_real_escape_string($_SESSION['user_id'])."'"); Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1296975 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 thanks alot Karl that works!!! I really appreciate the help now i need to figure out why it only echos "you need to check the box" when I hit toture but not surrender any ideas? if (isset($_POST['surrender']) || (isset($_POST['toture']))) { if(!isset($_POST['agree'])){ echo "You need to check the box"; } else { mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id'])); Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1296991 Share on other sites More sharing options...
-Karl- Posted December 12, 2011 Share Posted December 12, 2011 You'll have to show a bit more code than that tbh. Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1296992 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 this the entire code. really appreciate you taking time out to help me <?php if (isset($_POST['surrender']) || (isset($_POST['toture']))) { if(!isset($_POST['agree'])){ echo "You need to check the box"; } else { mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id'])); // logs you out and destroys the session and redirects you to signup page header("Location: signup.php"); session_start(); session_destroy(); exit(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1296996 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 I dont dont know why i have such huge problems understanding these "'" I really thought this below would work but it keeps giving me unexpected T_STRING error mysql_query("UPDATE users SET password='"$password"' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'") Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1296998 Share on other sites More sharing options...
-Karl- Posted December 12, 2011 Share Posted December 12, 2011 On your first post, where is $_POST['agree'] defined? Also, change: mysql_query("UPDATE users SET password='"$password"' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'") To: mysql_query("UPDATE users SET password='".$password."' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'") Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1296999 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 ahh I always wonder why some times my code boxes were huge and other time small didnt realize it was cause of the php tags. sorry about that. <?php if (isset($_POST['change'])) { // checks if password matches confirm password if ($_POST['new'] != $_POST['confirm']) { echo 'Your confirm password does not match your password'; } else { // updates the passowrd for password recovery mysql_query("UPDATE users SET forgotpd='".mysql_real_escape_string($_POST['confirm'])."' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'") $password = md5($_POST['new']); // Updates password with Md5 mysql_query("UPDATE users SET password='".$password."' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'") echo "Your password has been changed"; } } ?> im getting a error first on this line unexpected T_STRING <?php $password = md5($_POST['new']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1297002 Share on other sites More sharing options...
-Karl- Posted December 12, 2011 Share Posted December 12, 2011 Not sure, the md5 looks fine to me. Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1297003 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 Alright decided to get rid of some stuff to help problem solve I'm getting a } error for some reason with this. if I delete the mysq1_query there is no errors <?php if (isset($_POST['change'])) { // checks if password matches confirm password if ($_POST['new'] != $_POST['confirm']) { echo 'Your confirm password does not match your password'; } else { //updates the passowrd for password recovery mysql_query("UPDATE users SET forgotpd='".mysql_real_escape_string($_POST['confirm'])."' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"} } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1297004 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 lol i had a } on the end of the line i just changed that. but wierd its still giving me a } error Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1297005 Share on other sites More sharing options...
Zane Posted December 12, 2011 Share Posted December 12, 2011 I haven't exactly read every reply in here, but wouldn't it be easier to set name to NULL instead of a white-space? This way you could simply SET name = NULL You could also query for null values with WHERE name IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1297008 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 I found out what was wrong there has to be a ; at the end <?php mysql_query("UPDATE users SET forgotpd='".mysql_real_escape_string($_POST['confirm'])."' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"); ?> yah i was reading about null i never had any scripts when learning that messed with null so i guess fear leads me ha I"ll mess around with the NULL though thanks for that Quote Link to comment https://forums.phpfreaks.com/topic/252965-updating-a-field-to-a-blank/#findComment-1297009 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.