Jump to content

boiy

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

boiy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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
  2. [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
  3. <?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
×
×
  • 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.