I’ve created a query to insert a few certain values into my database:
function upload_text($text, $categories) {
$idea = mysql_real_escape_string(htmlentities($text));
$categories = mysql_real_escape_string(htmlentities($categories));
mysql_query("INSERT INTO `textfiles` VALUES ('', '".$_SESSION['user_id']."', '$text', '$categories', UNIX_TIMESTAMP() )"); }
The informaton submitted through the query is gathered by a user input PHP/HTML site, which consists of the following code (shortened):
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<font size='2' face='arial'>Your text:
<textarea cols="150" rows="5" name="text" maxlenght='500'></textarea>
<font size='2' face='arial'>Categories:
<textarea cols="150" rows="1" name="categories" maxlenght='100'></textarea>
<input type='submit' name='sub' value='Submit'> </form>
if (isset($_POST['sub'])) {
$text = $_POST['text'];
$categories = $_POST['categories'];
$upload = upload_text($text, $categories);
exit();
}
When I test my site in through localhost, and submit text, as I would expect a user to do, no text is actually transfered to my database. It remains empty.
Would someone please help me understand what errors I have in my code, or what misstakes I’m doing, because I can’t seem to find them.
Thank you.
The function needs to be wrapped in curly braces:
You must also already have an active connection to your DB server for this to work.
It would also be very useful to see what your SQL looks like before the query is run so using my code above
echoout$SQLjust before it is fed tomysql_query().As a good first step for debugging I suggest you enable error logging at the top of your script: