0

I always get this error:
"Error updating joke: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1"

There's something about this part of my code that causes that error and I just can't figure out what that is. help please :(

$id = mysql_real_escape_string($_POST['id']);
	$text = mysql_real_escape_string($_POST['text']);
	$sql = mysql_query("UPDATE joke SET joketext='$text' WHERE id=$id");
5
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by faroukmuhammad
0

Make sure that the field names are correct. Anyway, post the codes above of these three lines. It may easy to find the problem quickly.

0

try:

$sql = mysql_query("UPDATE joke SET joketext='$text' WHERE id='$id'") or die( mysql_error() );

notice the apostrophes around the value of $id

0

I always get this error:
"Error updating joke: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1"

There's something about this part of my code that causes that error and I just can't figure out what that is. help please :(

$id = mysql_real_escape_string($_POST['id']);
	$text = mysql_real_escape_string($_POST['text']);
	$sql = mysql_query("UPDATE joke SET joketext='$text' WHERE id=$id");

comment the above codes and replace with this and post its output

$id = mysql_real_escape_string($_POST['id']);
$text = mysql_real_escape_string($_POST['text']);
$sql = mysql_query("UPDATE joke SET joketext='$text' WHERE id=$id");
print_r($_POST);
echo "<br />";
echo $sql;
die();

Edited by Stefano Mtangoo: n/a

0

I tre your code the only problem is the connection identifier that you didn't add in mysql_query. this is my code;

<?php
$con = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("joking", $con);


$id = mysql_real_escape_string($_POST['id']);	
$text = mysql_real_escape_string($_POST['text']);	

$pre_sql = "UPDATE joke SET joketext='$text' WHERE id=$id";
$sql = mysql_query($pre_sql, $con);	

?>

i called the database joking ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.