imtaqi Posted January 21, 2008 Share Posted January 21, 2008 Following is my insert.php file to which my form post the data <?php $fname = $_POST["fname"]; $lname = $_POST["lname"]; $age = $_POST["age"]; $con = mysql_connect("localhost","giftme@1","mypass"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("giftme@1-airtime", $con); $sql = "SELECT * FROM PERSON WHERE(first_name='$fname' AND last_name='$lname' AND age='$age')"; $result = MySQL_query($sql, $con); $already_there = (MySQL_num_rows($result) > 0); if ($already_there) { $array = MySQL_fetch_array($result); $id = $array['id']; $entries = $array['entries'] + 1; $sql = "UPDATE person SET entries=$entries WHERE id=$id"; } else { $sql = "INSERT INTO person VALUES('', '$fname', '$lname', 1)"; } MySQL_query($sql, $con); MySQL_close($con); /*redirect - this must be the first output of the script *not even an empty line can come before the initial <?php tag */ header('location: http://yahoo.com/'); ?> I dont know what's gone wrong with the program not running giving following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /data/apache/users/kilu.de/giftme/www/form/insert.php on line 14 Warning: Cannot modify header information - headers already sent by (output started at /data/apache/users/kilu.de/giftme/www/form/insert.php:14) in /data/apache/users/kilu.de/giftme/www/form/insert.php on line 31 ?> Line 14: $already_there = (MySQL_num_rows($result) > 0); Line 31: header('location: http://yahoo.com/'); Could any1 help Quote Link to comment https://forums.phpfreaks.com/topic/87089-mysql-php-program-not-running/ Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 do yourself a few MASSIVE favours... 1) dont use static variables... 2) use errors!!! <?php $age = $_POST["age"]; $con = mysql_connect("localhost","giftme@1","mypass") or die('Could not connect: ' . mysql_error()); mysql_select_db("giftme@1-airtime", $con); $result = MySQL_query("SELECT * FROM `PERSON` WHERE(`first_name`='$fname' AND `last_name`='$lname' AND `age`='$age') LIMIT 1") or die(mysql_error()); if(mysql_num_rows($result) > 0){ $array = mysql_fetch_array($result); $entries = ; mysql_query("UPDATE `person` SET `entries`='{$array['entries']+ 1}' WHERE `id`='{$array[id]}'"); }else { mysql_query("INSERT INTO `person` VALUES('', '{$_POST[fname]}', '{$_POST["lname"]}', 1)"); } mysql_close($con); header('location: http://yahoo.com/'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87089-mysql-php-program-not-running/#findComment-445549 Share on other sites More sharing options...
cooldude832 Posted January 21, 2008 Share Posted January 21, 2008 also your queries should be structured like <?php $q = "Select this from `that` where this=that"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); ?> Best way to diagnostic errors. Quote Link to comment https://forums.phpfreaks.com/topic/87089-mysql-php-program-not-running/#findComment-445558 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.