Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/137069-php-mysql-update-inserting-blank/
Share on other sites

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());

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>";

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?

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>";

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.

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.