Monday, 19 August 2013

SQL database not inserting data?

SQL database not inserting data?

I am working on a program that takes HTML code made by a WYSIWYG editor
and inserting it into a database, then redirecting the user to the
completed page, which reads the code off the database. I can manually
enter code in phpmyadmin and it works but in PHP code it will not
overwrite the entry in the code column for the ID specified. I have
provided the PHP code to help you help me. The PHP is not giving me any
parse errors. What is incorrect with the following code?
<?php
//POST
VARIABLES------------------------------------------------------------------------
//$rawcode = $_POST[ 'editor1' ];
//$code = mysqli_real_escape_string($rawcode);
$code = 'GOOD';
$id = "1";
echo "$code";
//SQL
VARIABLES-------------------------------------------------------------------------
$database = mysqli_connect("localhost" , "root" , "password" ,
"database");
//INSERT QUERY DATA
HERE----------------------------------------------------------------
$queryw = "INSERT INTO users (code) VALUES('$code') WHERE ID = '" . $id
. "'";
mysqli_query($queryw, $database);
//REDIRECT TO LOGIN
PAGE----------------------------------------------------------------
echo "<script type='text/javascript'>\n";
echo "window.location = 'http://url.com/users/" . $id .
"/default.htm';\n";
echo "</script>";
?>

No comments:

Post a Comment