Re: php script filling mysql db.table with nulls
| From: | szii at sziisoft dot com | Date: | Wed, 08 May 2002 18:12:06 +0000 |
| Subject: | Re: php script filling mysql db.table with nulls | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-19051@lists.php.net to get a copy of this message | ||
Do this...
var_dump($_POST); and look at the source generated.
My guess is that you're using $_POST['$headlines1["newsdate"]']
and that it's not really a string variable '$headlines1["newsdate']']
but instead a numerical offset/index from $headlines1["newsdate"].
ie...
$_POST[$headlines1["newsdate"]]
or maybe...
$_POST['$headlines1']["newsdate"]
Post the var_dump() and we'll be better able to diagnose it.
'Luck.
-Szii
----- Original Message -----
From: "Kirk Babb" <kbcd@worldnet.att.net>
To: <php-db@lists.php.net>
Sent: Wednesday, May 08, 2002 9:21 AM
Subject: [PHP-DB] php script filling mysql db.table with nulls
> I have a php script that I have done something very, very wrong to as it has
> erased the data in this table:
>
> mysql> select * from newsitems;
> +----+------------+-----------+----------+
> | ID | newsdate | newstitle | newstext |
> +----+------------+-----------+----------+
> | 1 | 0000-00-00 | | |
> | 2 | 0000-00-00 | | |
> | 3 | 0000-00-00 | | |
> | 4 | 0000-00-00 | | |
> | 5 | 0000-00-00 | | |
> | 6 | 0000-00-00 | | |
> +----+------------+-----------+----------+
> 6 rows in set (0.00 sec)
>
> I can't figure out what it is, I have been trying to get sessions to work
> lately so that has been the only change to the script. Sessions are
> working, because I can access the db, but every time I update the newsitems
> table above is the result. If I manually enter data from mysql> it will
> remain there until I run the script below. The script echoes back a success
> message for each inserted row. I apologize for the length.
>
> <?php
> session_start();
> $username=$_SESSION[username];;
> $password=$_SESSION[password];
> $update = $_POST['update'];
> $date1 = $_POST['$headlines1["newsdate"]'];
> $date2 = $_POST['$headlines2["newsdate"]'];
> $date3 = $_POST['$headlines3["newsdate"]'];
> $date4 = $_POST['$headlines4["newsdate"]'];
> $date5 = $_POST['$headlines5["newsdate"]'];
> $date6 = $_POST['$headlines6["newsdate"]'];
> $title1 = $_POST['$headlines1["newstitle"]'];
> $title2 = $_POST['$headlines2["newstitle"]'];
> $title3 = $_POST['$headlines3["newstitle"]'];
> $title4 = $_POST['$headlines4["newstitle"]'];
> $title5 = $_POST['$headlines5["newstitle"]'];
> $title6 = $_POST['$headlines6["newstitle"]'];
> $text1 = $_POST['$headlines1["newstext"]'];
> $text2 = $_POST['$headlines2["newstext"]'];
> $text3 = $_POST['$headlines3["newstext"]'];
> $text4 = $_POST['$headlines4["newstext"]'];
> $text5 = $_POST['$headlines5["newstext"]'];
> $text6 = $_POST['$headlines6["newstext"]'];
> if ($update == "Submit Changes") {
> // If news updates have been submitted
> // Connect to the db server
> // Connect to the db server
> $dbcnx = mysql_connect("localhost", "$username",
> "$password");
> if (!$dbcnx) {
> print mysql_error() . "<P>Unable to connect to the database server
> at this time. Click <a href='newsadmin.htm'>here</a> to start again, or
> " .
> "click <a href='index.htm'>here</a> to leave this part of
> the
> site.</P><br>";
> exit();
> }
> // Select the FlashNews db
> if(! @mysql_select_db("flashnews") ) {
> print "<P>Unable to locate the news database at this time. Click <a
> href='newsadmin.htm'>here</a> to try again, or" .
> "click <a href='index.htm'>here</a> to leave this part of
> the
> site.</P><br>";
> exit();
> }
> $updated_news1 = "UPDATE newsitems SET newsdate='$date1',
> newstitle='$title1', newstext='$text1' WHERE ID='1'";
> if (mysql_query($updated_news1)) {
> print "<p><center><font color ='663333'>******
> News item 1 in
> the database has been updated. ******</font></center></p>";
> } else {
> print "<P>Error updating news item 1 " . mysql_error() .
> "</P>";
> }
> $updated_news2 = "UPDATE newsitems SET newsdate='$date2',
> newstitle='$title2', newstext='$text2' WHERE ID='2'";
> if (mysql_query($updated_news2)) {
> print "<p><center><font color ='663333'>****** News
> item 2 in the
> database has been updated. ******</font></center></p>";
> } else {
> print "<P>Error updating news item 2 " . mysql_error() .
> "</P>";
> }
> $updated_news3 = "UPDATE newsitems SET newsdate='$date3',
> newstitle='$title3', newstext='$text3' WHERE ID='3'";
> if (mysql_query($updated_news3)) {
> print "<p><center><font color ='663333'>******
> News item 3 in
> the database has been updated. ******</font></center></p>";
> } else {
> print "<P>Error updating news item 3 " . mysql_error() .
> "</P>";
> }
> $updated_news4 = "UPDATE newsitems SET newsdate='$date4',
> newstitle='$title4', newstext='$text4' WHERE ID='4'";
> if (mysql_query($updated_news4)) {
> print "<p><center><font color ='663333'>****** News
> item 4 in the
> database has been updated. ******</font></center></p>";
> } else {
> print "<P>Error updating news item 4 " . mysql_error() .
> "</P>";
> }
> $updated_news5 = "UPDATE newsitems SET newsdate='$date5',
> newstitle='$title5', newstext='$text5' WHERE ID='5'";
> if (mysql_query($updated_news5)) {
> print "<p><center><font color ='663333'>******
> News item 5 in
> the database has been updated. ******</font></center></p>";
> } else {
> print "<P>Error updating news item 5 " . mysql_error() .
> "</P>";
> }
> $updated_news6 = "UPDATE newsitems SET newsdate='$date6',
> newstitle='$title6', newstext='$text6' WHERE ID='6'";
> if (mysql_query($updated_news6)) {
> print "<p><center><font color ='663333'>****** News
> item 6 in the
> database has been updated. ******</font></center></p>";
> } else {
> print "<P>Error updating news item 6 " . mysql_error() .
> "</P>";
> }
> echo "<P>Click on the button below to log out.</P>";
> $_SESSION = array();
> session_destroy();
> unset($update);
> ?>
> <form name="logout" action="index.htm">
> <input type="submit" name="logout" value="Logout Now">
> </form>
> <?php
> } else {
> echo "<P><FONT COLOR=RED>You have not accessed this page correctly.
> Hit the back button on your browser window.</FONT></P>";
> exit();
> }
> ?>
>
> This may be a general question, but since it affected the db I thought it
> should be posted here. Thanks for any and all help!
>
> -Kirk
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php