lucas20 Posted December 15, 2008 Share Posted December 15, 2008 I have a basic MYSQL statement that is turning my field into a blank field as opposed to inserting the variable into the database. Everything works fine and the variable is not null, but the TEXT1 field is left blank after execution. The field is set-up in MYSQL as a 'text' input type. $query = "UPDATE INDEX_TEXT SET TEXT1=\"$INDEX\" WHERE ID=1"; Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/ Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 Can we see more of your code? How do you get $INDEX? Have you tried echoing $INDEX to see what's in it? echo $INDEX; $query = "UPDATE INDEX_TEXT SET TEXT1=\"$INDEX\" WHERE ID=1"; echo $query; mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-715869 Share on other sites More sharing options...
lucas20 Posted December 15, 2008 Author Share Posted December 15, 2008 Here is the entire function, the echo of the variable works correctly. $INDEX=$_POST["INDEX_TEXT"]; $query = "UPDATE INDEX_TEXT SET TEXT1=\"$INDEX\" WHERE ID=1"; //die($query); mysql_query($query) or die('Index text update failed:<br><br>' . mysql_error()); ; echo "<center><h2>Updated index text to</h2>"; echo "<BR>"; echo $INDEX; echo "<BR></center>"; Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-715871 Share on other sites More sharing options...
lucas20 Posted December 15, 2008 Author Share Posted December 15, 2008 of course when I run the query in mysql with the text of the variable it works fine. Same if I replace the text for the variable in the php and run it. This would make sense that it is a variable issue - why is it null though for the SQL but not below when I 'echo' it? Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-715975 Share on other sites More sharing options...
ngreenwood6 Posted December 15, 2008 Share Posted December 15, 2008 Try this instead: $INDEX=$_POST['INDEX_TEXT']; $query = "UPDATE INDEX_TEXT SET TEXT1='$INDEX' WHERE ID=1"; //die($query); mysql_query($query) or die('Index text update failed:<br><br>' . mysql_error()); ; echo "<center><h2>Updated index text to</h2>"; echo "<BR>"; echo $INDEX; echo "<BR></center>"; Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-715977 Share on other sites More sharing options...
lucas20 Posted December 15, 2008 Author Share Posted December 15, 2008 Ya, same result. I've tried every quote non-quote double quote way I can image. I thought it was that too. Does the input format have anything to do with it in SQL? I have it set as TEXT but no other specifications at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-715990 Share on other sites More sharing options...
ngreenwood6 Posted December 15, 2008 Share Posted December 15, 2008 what errors are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-715995 Share on other sites More sharing options...
lucas20 Posted December 15, 2008 Author Share Posted December 15, 2008 errors - i wish - there are no errors, everything works smoothly except the field becomes blank after updating Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-716008 Share on other sites More sharing options...
ngreenwood6 Posted December 15, 2008 Share Posted December 15, 2008 Have you tried it like this: $INDEX= mysql_real_escape_string($_POST['INDEX_TEXT']); $query = "UPDATE INDEX_TEXT SET TEXT1='$INDEX' WHERE ID='1'"; //die($query); mysql_query($query) or die('Index text update failed:<br><br>' . mysql_error()); ; echo "<center><h2>Updated index text to</h2>"; echo "<BR>"; echo $INDEX; echo "<BR></center>"; also I assume you are selecting a database somewhere else in the code where the connection is. Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-716011 Share on other sites More sharing options...
lucas20 Posted December 15, 2008 Author Share Posted December 15, 2008 nope, but now I have --- same result. here's a new twist- if I also update the ID then the text DOES update. So this worked, but now I'm stuck with a crazy ID number. $query = "UPDATE INDEX_TEXT SET TEXT1='$INDEX', ID='88' WHERE ID=1"; I tried just changing the WHERE ID=88 but it went back to giving me a blank TEXT1 Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-716037 Share on other sites More sharing options...
ngreenwood6 Posted December 15, 2008 Share Posted December 15, 2008 sorry maybe someone else can help because that makes no sense to me and you can login to your mysql database and change the id back to 1 if you need to. Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-716041 Share on other sites More sharing options...
lucas20 Posted December 15, 2008 Author Share Posted December 15, 2008 Ya I'm in the database now, hopefully someone can assist because this is kinda silly. Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-716043 Share on other sites More sharing options...
fenway Posted December 15, 2008 Share Posted December 15, 2008 of course when I run the query in mysql with the text of the variable it works fine. Same if I replace the text for the variable in the php and run it. This would make sense that it is a variable issue - why is it null though for the SQL but not below when I 'echo' it? Let's see the actual echo here, please. Quote Link to comment https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/#findComment-716156 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.