Jump to content

[SOLVED] PHP not working the INSERT


GreenUser

Recommended Posts

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

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.

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?

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");

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.