470,862 Members | 1,769 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

Problem Loading Two db Tables with Script

The purpose of the script below is to load the same news item into two
different MySQL tables (thus displaying the same news item on two web
pages). The problem I am having is this: The script actually
works--but just once. The next time I run it (even days later), it
will not load the data. It just displays the error message from line
#37; in other words, there is no value in $result.

(BTW, I have stripped out all security temporarily. I understand that
in its present form this is an insecure script. It is not being left
on the server.)

Server PHP: 4.3.4
Server MySQL: 3.23.58

Can anyone figure out why this script would successfully load the two
tables, but only once? Thank you for your time and consideration.

dsl

------------------------------

<html>
<?php
$strTitle = 'Post Weekly News';
require ("header.php");
?>
<body>
<div id="center">
<FORM action="<?=$PHP_SELF?>" method="POST">
<p>Headline: <br>
<INPUT TYPE="text" NAME="headline" SIZE="50" /><br>
<p>Story text: <br>
<TEXTAREA NAME="story" ROWS="10" COLS="50" /></TEXTAREA><br>
<p>Start Date: <br>
<INPUT TYPE="text" NAME="initdate" SIZE="12" /><br>
<p>End Date: <br>
<INPUT TYPE="text" NAME="expdate" SIZE="12" /></p>
<INPUT TYPE=submit name="reg2" VALUE="Submit" />
<INPUT TYPE=reset VALUE="Clear Fields" />
</FORM>
<?php
// Connect to the database server
$dbcnx = @mysql_connect("localhost", <user>, <password>);
if (!$dbcnx) exit();
// Select the database
if (! @mysql_select_db("<db_name>")) exit();
if (!isset($reg2)) {
echo("No submission yet.");
}else{
// load row into news table
$sql = "insert into news set
headline='$headline',
story='$story',
initdate='$initdate',
expdate='$expdate'";
$result = (@mysql_query($sql));
if (!$result) {
echo("<p>ERROR: <b>News</b> table NOT loaded.</p>");
}else{
echo("<p><b>News</b> table loaded.</p>");
}
if ($result) {
$sql2 = "insert into hc_news set
headline='$headline',
story='$story',
initdate='$initdate',
expdate='$expdate'";
$result2 = (@mysql_query($sql2));
if (!$result2) {
echo("<p>ERROR: <b>HC_News</b> table NOT
loaded.</p>");
}else{
echo("<p><b>HC_News</b> table loaded.</p>");
echo("<p>Both tables loaded successfully.</p>");
}
}
}
?>
</div>
</body>
</html>

Jul 17 '05 #1
0 1403

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by nick.taylor | last post: by
13 posts views Thread by Jon Paal | last post: by
5 posts views Thread by toffee | last post: by
11 posts views Thread by Flexor | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.