Jump to content

Script won't insert to DB


Username:

Recommended Posts

I've used this on like three other scripts I don't know why it won't insert now  :shrug:

 

<?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">

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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