Forum Moderators: coopster

Message Too Old, No Replies

PHP will not Insert Data Into Database

PHP will not Insert Data Into Database

         

slademadefilms

9:43 pm on Feb 10, 2008 (gmt 0)

10+ Year Member



It's a simple form submission page. I know the connection with the database is good, because I am printing information from the same table to which I'm trying to insert new data.

=============================================

<?
if ($submit == 1) {
mysql_query("INSERT INTO `sermons` (`title`, `text`) VALUES ('$title', '$text')");
$records = mysql_query("SELECT `id` FROM `sermons` ORDER BY `id` DESC LIMIT 0, 1");
$row = mysql_fetch_array($records);
$pagenumber = $row[id];
$pageid = "sermon".$pagenumber.".php";
$file=fopen("$pageid","w");
$contents="<" . "? \$id = '$pagenumber'; include(\"display.php\");?" . ">";
fwrite($file,$contents);
fclose($file);
print "The value of submit is $submit<br>";
print "The value of title is $title<br>";
print "New sermon added <a href='http://example.com/support/add.php'>Click Here to Add Another Sermon, Johnny</a>.";
print "<br><br>";

};

print "<ul>";
$result = mysql_query('SELECT * FROM `sermons` WHERE `active` = 1 ORDER BY `rank` ASC');
while($row = mysql_fetch_array($result)) {
print "<li><a href='http://example.com/sermons/sermon$row[id].php'><font face='arial' color='#ffffff' size='3'><b>$row[title]</b></font></a><br>";
};
print "</ul>";
?>

==================================================

Everything is working, except that no data is being written to the database. It worked on the first try, but it has not worked since.

Any ideas?

[edited by: eelixduppy at 9:58 pm (utc) on Feb. 10, 2008]
[edit reason] example.com [/edit]

cameraman

11:12 pm on Feb 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried
echo mysql_error() [php.net];

right after the insert line?

slademadefilms

11:30 pm on Feb 10, 2008 (gmt 0)

10+ Year Member



Thanks, the error led me to the problem; I merely edited on the keys on the table and now it works.