Clinton Posted June 7, 2008 Share Posted June 7, 2008 <?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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/ Share on other sites More sharing options...
.josh Posted June 7, 2008 Share Posted June 7, 2008 Any errors? echo out vars and/or query string to see if vars contain expected info? echo something inside your condition to see if it's even passing? Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559597 Share on other sites More sharing options...
Clinton Posted June 7, 2008 Author Share Posted June 7, 2008 The vars echo correctly, how do I echo the string? Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559601 Share on other sites More sharing options...
.josh Posted June 7, 2008 Share Posted June 7, 2008 instead of doing $result = mysql_query("blahblahblah"); do $sql = "blahblahblah"; echo $sql; $result = mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559603 Share on other sites More sharing options...
.josh Posted June 7, 2008 Share Posted June 7, 2008 $_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? Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559605 Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 try putting the table name between backticks `` and add a or die(mysql_error()) to your insert query in order to see what's the error you're getting Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559607 Share on other sites More sharing options...
Clinton Posted June 7, 2008 Author Share Posted June 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559608 Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 there's a space in your table's name, you need to use backticks Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559610 Share on other sites More sharing options...
Clinton Posted June 7, 2008 Author Share Posted June 7, 2008 Did that, didn't update: ??? INSERT INTO `23MA04MS NONEL` (datecode, producttype, transactiondate, joblocation, jobnumber, signout, signin, outinby) VALUES (23MA04, MS NONEL, 2008-06-06, Montenay, 8321-A44, , 90, CA) Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559612 Share on other sites More sharing options...
Clinton Posted June 7, 2008 Author Share Posted June 7, 2008 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 'NONEL, 2008-06-06, Montenay, 8321-A44, , 90, c)' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559613 Share on other sites More sharing options...
Clinton Posted June 7, 2008 Author Share Posted June 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559617 Share on other sites More sharing options...
Clinton Posted June 7, 2008 Author Share Posted June 7, 2008 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')"; Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559622 Share on other sites More sharing options...
AndyB Posted June 7, 2008 Share Posted June 7, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/109082-solved-not-sure-why-info-is-not-insert-into-the-db/#findComment-559625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.