Jump to content

You have an error in your SQL syntax; check the manual that corresponds to your


boiy

Recommended Posts

<?php

$connection = mysql_connect("localhost","root","blackbriar");

 

if(!$connection){

die("Database connection failed: " . mysql_error());

}

$db = mysql_select_db("nut",$connection);

if(!$db){

die("Database selection failed: " . mysql_error());

}

?>

<?php

//global $id;

/*if (intval($_GET['id']) == 0) {

redirect_to("contentarea.php");

}*/

 

include_once 'includes/form_functions.php';

if (isset($_POST['submit'])) {

$errors = array();

 

$required_fields = array('topic', 'body');

$errors = array_merge($errors, check_required_fields($required_fields));

 

$fields_with_lengths = array('topic' => 50);

$errors = array_merge($errors, check_required_fields($fields_with_lengths));

 

if (empty($errors)) {

// Perform Update

$id = mysql_prep($_GET['id']);

$topic = trim(mysql_prep($_POST['topic']));

$body = trim(mysql_prep($_POST['body']));

 

//$sql_news_query ="UPDATE `news` SET `id` = '$id',`news_title` = '\'$topic'\', `news_content` = '$body' WHERE `id` = '$id' LIMIT 1";

//$sql_news_query = "UPDATE news SET topic = '{$topic}' body= '{$body}' WHERE id = {$id}";

//$sql_news_query = ("UPDATE news SET news_title='" . $topic . "'news_content='" . $body . "' where id='" . $id . "'");

$sql_news_query = "UPDATE `news` SET

  `news`.`id` = '{$id}',

  `news`.`news_title` = '{$topic}',

          `news`.`new_content` = '{$body}',

          WHERE `news`.`id` = {$id}";

$add_result = mysql_query($sql_news_query) or die(mysql_error()) ;

if (mysql_affected_rows() == 1) {

// Success

$message = "The news was successfully updated.";

} else {

// Failed

$message = "The news update failed.";

$message .= "<br />". mysql_error();

}

}

 

} // end: if (isset($_POST['submit']))

?>

<?php

$query = "SELECT * FROM news";

 

$niis = mysql_query($query) or die(mysql_error());

 

while($row = mysql_fetch_array($niis)){

echo "<a href= \"page1.php?id=" . urlencode($row['id']) . "\">{$row["news_title"]}</a><br>";

//echo "<li class=\"selected\"><a href = \"test.php?id =".urlencode($menu["id"])."\">{$menu["news_title"]}</a></li>";

}

?>

<?php

if(isset($_GET['id'])){

echo "id is set<br>";

$id = $_GET['id'];

$set = "SELECT * FROM news WHERE id=" . $id ." ";

$result_set = mysql_query($set) or die(mysql_error());

$sub = mysql_fetch_array($result_set);

echo $sub['news_content'];

}else{

echo "id not set";

}

?>

 

<h1>News & Events Update</h1>

  <?php if (!empty($message)) {echo "<p class=\"msg\">" . $message . "</p>";} ?>

<?php if (!empty($errors)) { display_errors($errors); } ?>

  <form id="form1" name="form1" method="post" action="page1.php?id=<?php urlencode($sub['id']);?>">

    <fieldset>

      <legend>Edit Subject:</legend>

      <p>

        <label for="topic2">Topic:</label>

        <input name="topic" type="text" class="text" id="topic2" tabindex="10" value=<?php echo $sub['news_title'];?> />

        </p>

      <p>

        <label for="body">Body:</label><br />

          <textarea name="body" id="body" cols="50" rows="10" tabindex="20" ><?php echo $sub['news_content'];?></textarea>

        </p>

      <p>

        <input type="submit" name="submit" id="addEntry" value="Update Entry!" tabindex="30" />

      </p>

 

 

 

above is me codes, i will like someone to pleas help out cos i av limited time i am workin with

when i run it i get the followin

 

You have an error in your SQL syntax; check the manual that corresponds to your

 

thanks

 

Link to comment
Share on other sites

[code=php:0]<?php 
$connection = mysql_connect("localhost","root","blackbriar");

	if(!$connection){
		die("Database connection failed: " . mysql_error());
	}
	$db = mysql_select_db("nut",$connection);
	if(!$db){
		die("Database selection failed: " . mysql_error());
	}
?>
<?php 
//global $id;
	/*if (intval($_GET['id']) == 0) {
		redirect_to("contentarea.php");
	}*/

	include_once 'includes/form_functions.php';
	if (isset($_POST['submit'])) {
		$errors = array();

		$required_fields = array('topic', 'body');
		$errors = array_merge($errors, check_required_fields($required_fields));

		$fields_with_lengths = array('topic' => 50);
		$errors = array_merge($errors, check_required_fields($fields_with_lengths));

		if (empty($errors)) {
			// Perform Update
			$id = mysql_prep($_GET['id']);
			$topic = trim(mysql_prep($_POST['topic']));
			$body = trim(mysql_prep($_POST['body']));

//$sql_news_query ="UPDATE `news` SET `id` = '$id',`news_title` = '\'$topic'\', `news_content` = '$body' WHERE `id` = '$id' LIMIT 1";
		//$sql_news_query = "UPDATE news SET topic = '{$topic}' body= '{$body}' WHERE id = {$id}";
//$sql_news_query = ("UPDATE news SET news_title='" . $topic . "'news_content='" . $body . "' where id='" . $id . "'"); 
				$sql_news_query = "UPDATE `news` SET
								   `news`.`id` = '{$id}',	 
								   `news`.`news_title` = '{$topic}', 
						           `news`.`new_content` = '{$body}', 
						           WHERE `news`.`id` = {$id}";
			$add_result = mysql_query($sql_news_query) or die(mysql_error()) ;
		if (mysql_affected_rows() == 1) {
				// Success
				$message = "The news was successfully updated.";
			} else {
				// Failed
				$message = "The news update failed.";
				$message .= "<br />". mysql_error();
			}
		}	

	} // end: if (isset($_POST['submit']))
?>
<?php 
$query = "SELECT * FROM news";

$niis = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($niis)){
echo "<a href= \"page1.php?id=" . urlencode($row['id']) . "\">{$row["news_title"]}</a><br>";
//echo "<li class=\"selected\"><a href = \"test.php?id =".urlencode($menu["id"])."\">{$menu["news_title"]}</a></li>";
}
?>
<?php
if(isset($_GET['id'])){
echo "id is set<br>";
$id = $_GET['id'];
$set = "SELECT * FROM news WHERE id=" . $id ." ";
$result_set = mysql_query($set) or die(mysql_error());
$sub = mysql_fetch_array($result_set);
echo $sub['news_content'];
}else{
echo "id not set";
}	
?>

<h1>News & Events Update</h1>
  <?php if (!empty($message)) {echo "<p class=\"msg\">" . $message . "</p>";} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>
  <form id="form1" name="form1" method="post" action="page1.php?id=<?php urlencode($sub['id']);?>">
    <fieldset>
      <legend>Edit Subject:</legend>
      <p>
        <label for="topic2">Topic:</label>
        <input name="topic" type="text" class="text" id="topic2" tabindex="10" value=<?php echo $sub['news_title'];?> />
        </p>
      <p>
        <label for="body">Body:</label><br />
          	<textarea name="body" id="body" cols="50" rows="10" tabindex="20" ><?php echo $sub['news_content'];?></textarea>
        </p>
      <p>
        <input type="submit" name="submit" id="addEntry" value="Update Entry!" tabindex="30" />
      </p>

[/code]

 

kk>> i corrected that

Link to comment
Share on other sites

thats the problem.... am not sure which one is generating the error

 

 

but i know that before i started workin on the UPDATE syntax, the error wasnt there

 

so lets start with the UPDATE

 

 $sql_news_query = "UPDATE `news` SET
                              `news`.`id` = '{$id}',    
                              `news`.`news_title` = '{$topic}', 
                                `news`.`new_content` = '{$body}', 
                                WHERE `news`.`id` = {$id}";

 

and as u can see... i have tried several update...

 

i commented out....pls take it step by step

 

i need a solution

mysql version is 5.1.38

Link to comment
Share on other sites

Then you need to insert some echos to tell you which query is failing. Wherever you use die(mysql_error()), also echo the query string, not only so you can tell which query is failing, but so you can examine the query to make sure it contains what you would expect it to contain.

Link to comment
Share on other sites

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.