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

Recommended Answers

All 4 Replies

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.

try:

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

notice the apostrophes around the value of $id

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.