Page 1 of 1

Help

Posted: Thu Oct 06, 2011 10:39 am
by jauson
Hi Please help!

can someone please why this code not working.
<?php
$host="Localhost";
$username="root";
$password="root";
$db_name="bbs";
$tbl_name="t_board";

mysql_connect('Localhost', 'root', 'root') or die("Unable to Connect");
mysql_select_db("bbs") or die("Unable to select DB!");

$index=$_POST['index'];
$writer=$_POST['writer'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$filename=$_POST['filename'];

$sql = "UPDATE INTO t_board
SET writer='$writer', 'subject='$subject', message='$message', 'filename='$filename'
WHERE index='$index'";
$result = mysql_query($sql);

if(!$result){
echo "Query NOT WORKING"; <---- QUERY NOT WORKING
exit;
}

if ($result){
header("Location: view.php");
}
else{
echo "Please Try Again!";
echo "<BR />";
echo "<a href='view.php'> BACK </a>";
}
mysql_close();

?>

Re: Help

Posted: Thu Oct 06, 2011 10:41 am
by Celauran
Please use syntax tags and meaningful titles. UPDATE INTO is not valid SQL syntax. Remove the INTO and try it again.

Re: Help

Posted: Thu Oct 06, 2011 3:31 pm
by flying_circus
In addition to what Celauran said, you have incorrect quoting in your query string. Also, the line with <---- QUERY NOT WORKING is a syntax error, you can put a double slash in front of the text to comment it (//<--- QUERY NOT WORKING).

Code: Select all

<?php
  # Database Credentials
    $host = "Localhost";
    $username = "root";
    $password = "root";
    $db_name = "bbs";
    $tbl_name = "t_board";
    
  # Connect to the Database
    mysql_connect($host, $username, $password) or die("Unable to Connect");
    mysql_select_db($db_name) or die("Unable to select DB!");
    
  # Fetch POST Vars
    $index = isset($_POST['index']) ? $_POST['index'] : '';
    $writer = isset($_POST['writer']) ? $_POST['writer'] : '';
    $subject = isset($_POST['subject']) ? $_POST['subject'] : '';
    $message = isset($_POST['message']) ? $_POST['message'] : '';
    $filename = isset($_POST['filename']) ? $_POST['filename'] : '';
    
  # Build SQL Query
    $sql = sprintf("UPDATE `%s` SET `writer`='%s', `subject`='%s', `message`='%s', `filename`='%s' WHERE `index`='%s';",
                   mysql_real_escape_string($tbl_name),
                   mysql_real_escape_string($writer),
                   mysql_real_escape_string($subject),
                   mysql_real_escape_string($message),
                   mysql_real_escape_string($filename),
                   mysql_real_escape_string($index));
                   
  # Execute SQL Query
    $result = mysql_query($sql);
    
  # Close Query
    mysql_close();
    
  # Check Results
    if($result === FALSE) {
      exit("Query NOT WORKING"); //<---- QUERY NOT WORKING
    } else {
      header("Location: view.php");
      exit;
    }
?>

Re: Help

Posted: Fri Oct 07, 2011 1:53 am
by jauson
thanks man! you really amazing! "flying_circus"

what special function or script did you use?