GreenUser Posted June 23, 2008 Share Posted June 23, 2008 Hi all! This here will not insert into my database with the form. The form works. I do not receive any error messages. I have had problems with the insert and value stuff before but can't remember. Thank you <?php session_start(); require("config.php"); require("db.php"); if($_POST['submit']) { $sql = "INSERT INTO stories(cat_id, dateposted, location, datename, body, fun, soh, con, int, sex, hyg, mes) VALUES(" . $_POST['cat'] . ",NOW(), '" . $_POST['location'] . "', '" . $_POST['datename'] . "', '" . $_POST['body'] . "' , '" . $_POST['fun'] . "', '" . $_POST['soh'] . "', '" . $_POST['con'] . "' , '" . $_POST['int'] . "', '" . $_POST['sex'] . "', '" . $_POST['hyg'] . "' , '" . $_POST['mes'] . "');"; mysql_query($sql); header("Location: " . $config_basedir . "/index.php"); } else { require("header.php"); ?> Link to comment https://forums.phpfreaks.com/topic/111448-solved-php-not-working-the-insert/ Share on other sites More sharing options...
Nexy Posted June 23, 2008 Share Posted June 23, 2008 Try this: <?php $sql = "INSERT INTO stories(cat_id, dateposted, location, datename, body, fun, soh, con, int, sex, hyg, mes) VALUES('".$_POST['cat']."', NOW(), '".$_POST['location']."', '".$_POST['datename']."', '".$_POST['body']."', '".$_POST['fun']."', '".$_POST['soh']."', '".$_POST['con']."', '".$_POST['int']."', '".$_POST['sex']."', '".$_POST['hyg']."', '".$_POST['mes']."')"; $res = mysql_query($sql) OR die(mysql_error()); ?> If anything is wrong, it should print out an error. Link to comment https://forums.phpfreaks.com/topic/111448-solved-php-not-working-the-insert/#findComment-572060 Share on other sites More sharing options...
GreenUser Posted June 23, 2008 Author Share Posted June 23, 2008 Thank you Nexy, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int, sex, hyg, mes) VALUES('', NOW(), '', '', '', '', '', '', '', '', '', ' at line 1 After narrowing it down a little more, this is the error message I received. Could you give any help here? Link to comment https://forums.phpfreaks.com/topic/111448-solved-php-not-working-the-insert/#findComment-572062 Share on other sites More sharing options...
dilum Posted June 23, 2008 Share Posted June 23, 2008 You can do like this rather than you'r way. if($_POST['submit']) { $temp1 = $_POST['cat']; $temp2 = $_POST['location']; .. .. .. $sql = "INSERT INTO stories(cat_id, dateposted, location, datename, body, fun, soh, con, int, sex, hyg, mes) VALUES('$temp1','now()','$temp2',....)"; mysql_query($sql); header("Location: " . $config_basedir . "/index.php"); } Link to comment https://forums.phpfreaks.com/topic/111448-solved-php-not-working-the-insert/#findComment-572083 Share on other sites More sharing options...
GreenUser Posted June 23, 2008 Author Share Posted June 23, 2008 Thank you Dilum your method works just as well, the problem I suppose is with the SQL. I'll move it over to the SQL forum. Sorry moderators. Link to comment https://forums.phpfreaks.com/topic/111448-solved-php-not-working-the-insert/#findComment-572092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.