Problem Loading Two db Tables with Script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • coding@dlampel.com

    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_d b("<db_name>" )) exit();
    if (!isset($reg2)) {
    echo("No submission yet.");
    }else{
    // load row into news table
    $sql = "insert into news set
    headline='$head line',
    story='$story',
    initdate='$init date',
    expdate='$expda te'";
    $result = (@mysql_query($ sql));
    if (!$result) {
    echo("<p>ERROR: <b>News</b> table NOT loaded.</p>");
    }else{
    echo("<p><b>New s</b> table loaded.</p>");
    }
    if ($result) {
    $sql2 = "insert into hc_news set
    headline='$head line',
    story='$story',
    initdate='$init date',
    expdate='$expda te'";
    $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>

Working...