unknow reason for not working

ok, i haven’t touch php in 2 years, and i have started using it again. i am having really trouble with inserting data in a mysql database, now the database conection is fine, and no error messages pop up. it just doesn’t enter the data. my code is below any help would be gd thank you.

[php]

<?php if (isset($do) && $do == 'add') { $my_t = getdate(date("U")); $date = $my_t[weekday] . $my_t[month] . $my_t[mday] . $my_t[year]; $sql="INSERT INTO News (date, title, news) VALUES ('$date', '$title', '$news')"; if (!mysql_query($sql,$conn)) { die('Error: ' . mysql_error()); } echo "1 record added"; $data = mysql_query( "SELECT * FROM News", $conn ) or die(mysql_error()); $image1 = $row['image1']; while ( $row = mysql_fetch_array( $data ) ) { print "

" . $row['date'] . "


" . $row['title']; print "

" . $row['news'] . "

.

";} // end while } mysql_close($conn) ?>

[/php]
ADMIN EDIT: Added [PHP] Code tags and adjusted format for readability

No errors at all?

Do you have display_errors on in the PHP ini file?

i hope so, im using hostmonster, so i guess so. also that dam $end error is popping up with a different page.

Have a look at the following line:

if (!mysql_query($sql,$conn))

This statement will NOT produce an error if there is an error in your SQL statement. The mysql_query is a PHP function and will only generate an error if you supply the proper information (A link to the db, a query, etc…) So as long as all of that is correct, regardless whether your SQL query (The insert statement itself) is correct, you will never see the error from the database as to why it didn’t insert.

I suggest that you view the mysql_error (while debugging) regardless of the result.

Your “Error Checking” would also be better served as something more like.

[php]

if (mysql_errno != 0) {
die('Error: ’ . mysql_error());
}
echo “1 record added”;
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service