boiy Posted January 29, 2011 Share Posted January 29, 2011 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/226024-you-have-an-error-in-your-sql-syntax-check-the-manual-that-corresponds-to-your/ Share on other sites More sharing options...
Pikachu2000 Posted January 29, 2011 Share Posted January 29, 2011 When posting code, please enclose it in the forum's . . . BBCode tags. It is also helpful to post the error messages exactly as they appear. Quote Link to comment https://forums.phpfreaks.com/topic/226024-you-have-an-error-in-your-sql-syntax-check-the-manual-that-corresponds-to-your/#findComment-1166850 Share on other sites More sharing options...
boiy Posted January 29, 2011 Author Share Posted January 29, 2011 [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 Quote Link to comment https://forums.phpfreaks.com/topic/226024-you-have-an-error-in-your-sql-syntax-check-the-manual-that-corresponds-to-your/#findComment-1166854 Share on other sites More sharing options...
Pikachu2000 Posted January 29, 2011 Share Posted January 29, 2011 Can you paste the error here, and do you know which query is generating the error? There are several queries in that code. Quote Link to comment https://forums.phpfreaks.com/topic/226024-you-have-an-error-in-your-sql-syntax-check-the-manual-that-corresponds-to-your/#findComment-1166860 Share on other sites More sharing options...
boiy Posted January 29, 2011 Author Share Posted January 29, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/226024-you-have-an-error-in-your-sql-syntax-check-the-manual-that-corresponds-to-your/#findComment-1166903 Share on other sites More sharing options...
Pikachu2000 Posted January 29, 2011 Share Posted January 29, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226024-you-have-an-error-in-your-sql-syntax-check-the-manual-that-corresponds-to-your/#findComment-1167007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.