Jump to content


Photo

MySQL version - syntax error?


  • Please log in to reply
2 replies to this topic

#1 wizzkid

wizzkid
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 22 July 2006 - 08:48 AM

Hi I create this script to edit an article on my news section.. But I encounter this error

Could update the entry because: 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 '' at line 1. The query was UPDATE news SET date='2006-06-27', title='', article='' WHERE int_id=.


This is my edit_news.php code
<?php 

ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

	require_once ('../include/LeePH/mysql_connect.php');
	
if (isset ($_POST['submit'])) { 

	// Define the query.
	$query = "UPDATE news SET date='{$_POST['date']}', title='{$_POST['vc_title']}', article='{$_POST['vc_article']}' WHERE int_id={$_POST['id']}";
	$r = mysql_query ($query);
	
	// Report on the result.
	if (mysql_affected_rows() == 1) {
		print '<p>The blog entry has been updated.</p>';
	} else {
		print "<p>Could update the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
	}

} else { // Display the entry in a form.

	// Check for a valid entry ID in the URL.
	if (is_numeric ($_GET['id']) ) {
	
		// Define the query.
		$query = "SELECT * FROM news WHERE int_id={$_GET['id']}";
		if ($r = mysql_query ($query)) { // Run the query.
		
			$row = mysql_fetch_array ($r); // Retrieve the information.
			
			// Make the form.
			print '<form action="edit_news.php" method="post">
		<p>Entry Date: <input type="text" name="date" size="40" maxsize="100" value="' . $row['date'] . '" /></p>
		<p>Entry Title: <input type="text" name="title" size="40" maxsize="100" value="' . $row['vc_title'] . '" /></p>
		<p>Entry Text: <textarea name="article" columns="40" rows="5">' . $row['vc_article'] . '</textarea></p>
		<input type="hidden" name="int_id" value="' . $_GET['id'] . '" />
		<input type="submit" name="submit" value="Update this Entry!" />
		</form>';
	
		} else { // Couldn't get the information.
			print "<p>Could retrieve the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
		}

	} else { // No ID set.
		print '<p><b>You must have made a mistake in using this page.</b></p>';
	}

} // End of main IF.

mysql_close(); // Close the database connection.

?>

I am using these version of software:
OS: Kubuntu 6.06 Dapper
mySQL: MySQL 5.0.22-Debian_0ubuntu6.06-log
PHP: PHP 5.1.2
Apache:Apache/2.0.55

My Database Structure
int_id  - int
date - date
vc_title - string
vc_article - string


Thanks hope you can help!

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 22 July 2006 - 08:57 AM

try using

int_id='{$_POST['id']}'";

see if that works
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 wizzkid

wizzkid
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 22 July 2006 - 10:43 AM

Yeah! sorry it was bad.. :) I failed to put the ' '

its working now,

Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users