Jump to content

[SOLVED] Not sure why info is not INSERT into the db?


Clinton

Recommended Posts


<?php
session_start();

$tablename = $_POST['tablename'];
$datecode = $_POST['datecode'];
$producttype = $_POST['producttype'];
$transactiondate = $_POST['transactiondate'];
$joblocation = $_POST['joblocation'];
$jobnumber = $_POST['jobnumber'];
$signout = $_POST['signout'];
$signin = $_POST['signin'];
$outinby = $_POST['outinby'];
$page = $_POST['page'];

if ( @$_SESSION['login'] == "yes" AND @$_SESSION['released'] == "0" )
{

$_SESSION['location'] == $location;

$username = "";
$password = "";
$hostname = "";

$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db("clintona_".$location."Inventory",$dbhandle)
or die("Can not open the Inventory Database. Please consult your local dialing directory or try your call later.");

$result = mysql_query("INSERT INTO '$tablename' (datecode, producttype, transactiondate, joblocation, jobnumber, signout, signin, outinby) VALUES ('$datecode', '$producttype', '$transactiondate', '$joblocation', '$jobnumber', '$signout', '$signin', '$outinby')");

?>

<html>
<head>
<meta http-equiv="refresh" content="1; url=<? echo $page ?>.php">
<title></title>
</head>


<body bgcolor="#FFFFFF">

</body>


</html>


<? }

else if ( @$_SESSION['login'] == "yes" AND @$_SESSION['released'] == "1" )
{
echo "Your previous access has been revoked. <meta http-equiv='refresh' content='3;url=http:' />
";
}
else
{
echo "You have tried to enter a Employee Area only. Please login. <meta http-equiv='refresh' content='3;url=http:/' />
";
}


mysql_close($dbhandle); ?> 

$_SESSION['location'] == $location;

 

think you meant

 

$location = $_SESSION['location'];

 

that probably is preventing you from selecting your db (and therefore query failure) ... but I'm not really sure why you wouldn't have gotten your die message...got error reporting turned off?

The sessions working fine. Ummm... here's what I got for echoing the string. It looks like everything is correct.

 

INSERT INTO 23MA04MS NONEL (datecode, producttype, transactiondate, joblocation, jobnumber, signout, signin, outinby) VALUES (23MA04, 'MS NONEL', '2008-06-06', 'Montenay', '8321-A44', '', '90', 'CA')

 

Let me try the backticks but I'm pretty sure I did try those.

Ok, there was a space in MS NONEL so I put backticks in that value as well and it's gone but there are no spaces now and I'm still getting the following error:

 

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 ' 90, CA)' at line 1

 

What a pain.

Here's the answer:

 


$sql = "INSERT INTO `$tablename` (datecode, producttype, transactiondate, joblocation, jobnumber, signout, signin, outinby) VALUES ('$datecode', '$producttype', '$transactiondate', '$joblocation', '$jobnumber', '$signout', '$signin', '$outinby')";

For future reference, use rational error message displays:

 

Replace:

$result = mysql_query("INSERT INTO '$tablename' (datecode, producttype, transactiondate, joblocation, jobnumber, signout, signin, outinby) VALUES ('$datecode', '$producttype', '$transactiondate', '$joblocation', '$jobnumber', '$signout', '$signin', '$outinby')");

 

with:

$query = "INSERT INTO `$tablename` (datecode, producttype, transactiondate, joblocation, jobnumber, signout, signin, outinby) VALUES ('$datecode', '$producttype', '$transactiondate', '$joblocation', '$jobnumber', '$signout', '$signin', '$outinby')";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // show useful error

 

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.