...

View Full Version : Problematic PHP / Mysql Insert



Jesuspwnt
12-23-2007, 11:43 PM
I've just coded a shoutbox, but it won't insert....

i can manually insert the data into the database and it echo's it
but this line is being problematic:


$insert = mysql_query("INSERT INTO `ccurityo_cms`.`shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`)VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')");

all variables are accounted for..
it just doesn't insert..

any ideas?

fl00d
12-23-2007, 11:46 PM
Maybe this?


$insert = mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')");


I removed the ` from the dot (`.` became .) and I spaced VALUES out from the bracket.

Jesuspwnt
12-23-2007, 11:49 PM
Maybe this?


$insert = mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')");


I removed the ` from the dot (`.` became .) and I spaced VALUES out from the bracket.

lol, thanx for trying, but i copied and pasted it straight from my db when inserting a set of values manually.
anyway i DID try it, no luck, still won't post.

fl00d
12-23-2007, 11:58 PM
Can you post the rest of the code?

Jesuspwnt
12-24-2007, 12:01 AM
$short_date = date("d/m/Y H:i");
$user = $_SESSION['username'];
$ip = $_SERVER['REMOTE_ADDR'];
echo "<form method=\"post\">\n<br />\n<textarea name=\"message\" class=\"shoutbox_ta\"></textarea>\n<br /><input type=\"submit\" value=\"Shout!\"></form>";
if($_POST){
$message = sanitize("sql", $_POST['message']);
$insert = mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')");
if(!$insert){
echo "Could Not Post Shout";
}
}
$shouts = mysql_query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 0,5");
echo "<table>";
while($shout = mysql_fetch_array($shouts)){
echo "<tr><td><b>".$shout['author']."</b><br />".$shout['time'];
echo "<br />".$shout['message'];
if($_SESSION['auth'] > 102){
echo "<br />".$shout['ip'];
}
echo "</td></tr>";
}
echo "</table>";

by the way, a little offtopic, i fixed the script on your thread ;)

CFMaBiSmAd
12-24-2007, 12:36 AM
Assuming your are getting the output from - echo "Could Not Post Shout";, add some error reporting to get php/mysql to tell you why it is failing -



if(!$insert){
echo "Could Not Post Shout";
echo mysql_error();
}



If you are not getting the "Count Not Post Shout", that would indicate that your code is not executing either due to a fatal parse or runtime error or the conditional logic is not being satisfied.

What symptoms are you getting?

Inigoesdr
12-24-2007, 01:45 AM
Maybe this?


$insert = mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')");


I removed the ` from the dot (`.` became .) and I spaced VALUES out from the bracket.

`database`.`table` should work fine. You can't remove the backticks in the middle unless you remove the ones on the end too, but proper syntax for MySQL uses backticks.

Jesuspwnt
12-24-2007, 02:07 AM
don't worry guys i fixed it, it was a problem in my sql db, i forgot to use auto_increment, sometimes, you forget the simplest of things



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum