Username: Posted September 21, 2010 Share Posted September 21, 2010 I've used this on like three other scripts I don't know why it won't insert now <?php date_default_timezone_set('America/Los_Angeles'); $timestamp = date('H:m:s m.d'); $admin = '24.68.214.97'; $visitor_ip = $_SERVER['REMOTE_ADDR']; $host="mysql"; // Host name $username="15557_test"; // Mysql username $password="**********"; // Mysql password $db_name="15557_test"; // Database name $tbl="announce"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $body = $_POST["body"]; if ($visitor_ip == $admin) { mysql_query("INSERT INTO $tbl (body, date) VALUES ('$body', '$timestamp')"); //right here, i can echo $body and see what I wrote, but I can't insert into $tbl } else { die("no"); } ?> <meta http-equiv="REFRESH" content="0;url=http://testchan.dcfilms.org/board-b.php"> Quote Link to comment https://forums.phpfreaks.com/topic/214013-script-wont-insert-to-db/ Share on other sites More sharing options...
Psycho Posted September 21, 2010 Share Posted September 21, 2010 Either: 1) The IP does not match (they can change you know) OR 2) The query is failing. Try the following: <?php date_default_timezone_set('America/Los_Angeles'); $timestamp = date('H:m:s m.d'); $admin = '24.68.214.97'; $visitor_ip = $_SERVER['REMOTE_ADDR']; $host = "mysql"; // Host name $username = "15557_test"; // Mysql username $password = "**********"; // Mysql password $db_name = "15557_test"; // Database name $tbl = "announce"; // Table name mysql_connect($host, $username, $password)or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $body = $_POST["body"]; if ($visitor_ip == $admin) { $query = "INSERT INTO {$tbl} (`body`, `date`) VALUES ('{$body}', '{$timestamp}')"; mysql_query($query) ordie("Query: {$query}<br />Error:".mysql_error()); } else { die("no"); } ?> <meta http-equiv="REFRESH" content="0;url=http://testchan.dcfilms.org/board-b.php"> Quote Link to comment https://forums.phpfreaks.com/topic/214013-script-wont-insert-to-db/#findComment-1113725 Share on other sites More sharing options...
Username: Posted September 21, 2010 Author Share Posted September 21, 2010 Either: 1) The IP does not match (they can change you know) OR 2) The query is failing. Try the following: It is 2, I'm sure. But it still doesn't make sense to me why it wouldn't work. Oh well.. Quote Link to comment https://forums.phpfreaks.com/topic/214013-script-wont-insert-to-db/#findComment-1113733 Share on other sites More sharing options...
PFMaBiSmAd Posted September 21, 2010 Share Posted September 21, 2010 The code that mjdamato posted has some error checking and error reporting logic in it that would tell you why the query is failing. Quote Link to comment https://forums.phpfreaks.com/topic/214013-script-wont-insert-to-db/#findComment-1113740 Share on other sites More sharing options...
Username: Posted September 21, 2010 Author Share Posted September 21, 2010 The code that mjdamato posted has some error checking and error reporting logic in it that would tell you why the query is failing. I tried it, it didn't return any error. Quote Link to comment https://forums.phpfreaks.com/topic/214013-script-wont-insert-to-db/#findComment-1113761 Share on other sites More sharing options...
mikosiko Posted September 21, 2010 Share Posted September 21, 2010 starting with mjdamato code do this: add this lines ini_set("display_errors", "1"); error_reporting(E_ALL); immediately after the <?php line and fix what seems to be a typo error in this line mysql_query($query) ordie("Query: {$query}<br />Error:".mysql_error()); should be mysql_query($query) or die("Query: {$query}<br />Error:".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/214013-script-wont-insert-to-db/#findComment-1113764 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.