taqi786
01-21-2008, 01:40 PM
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 :D
<?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 :D