MySQL Update Issue

Hey, I have a MySQL database with the table ‘users’, and I want to allow users to post a description.
I have a form on another webpage, and I am sure that it is working.

The problem is that, in the following code, I am using the variable $text to update the MySQL. And, when the user submits, the value will not update unless I actually create a specific value to set.

Please excuse the terrible coding. I just want to make it functional before I organize/secure it.
Any help is appreciated, thanks! :slight_smile:

[php]

<?PHP session_start(); function upload() { $text = $_POST['description']; $userid = $_SESSION['user_id']; $con = mysql_connect("localhost","**********","****"); //I starred these on purpose if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("**********", $con); //I starred this on purpose mysql_query("UPDATE users SET description=$text WHERE user_id=$userid"); } if (isset($_POST['submit'])) { upload();} ?>

[/php]

With
[php]

mysql_query(“UPDATE users SET description=’$text’ WHERE user_id=’$userid’”);
[/php]

Variable need to be inside single quotation.

Actually:

[php]
mysql_query(“UPDATE users SET description=’$text’ WHERE user_id=$userid;”);
[/php]

UPDATE queries need a semi-colon at the end, and I assume user_id is an integer so shouldn’t have single-quotes as wilson said.

well my work without the semi-colon maybe it’s because my php.ini config

php.ini config has nothing to do with mysql. It could be your mysql version but every update query i’v had to use required the semi-colon.

interesting.

when i started learning SQL in college they taught to end everything SQl query with ;

but I got used to not using it in my php Scripts since they work without the semi-colon and i mean all my php scripts and I upload them to my server 000webhost.com and also works and according to them they have the latest version of mySQL.

I think semi-colon in php query is optional since every php simple code need a ; too.

It’s not every query that needs it. I’ve just found certain queries (UPDATE and INSERT mostly) to completely hate me if I don’t end them with a semi-colon.

As far as I know, there’s nothing wrong with putting the semi-colon on the end of a query so getting into a habit of it is good if you work with mysql raw.

Sponsor our Newsletter | Privacy Policy | Terms of Service