Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetch Array problem

Status
Not open for further replies.

M2E

IS-IT--Management
Aug 1, 2005
28
GB
Could someone tell me what is wrong with the below please!!!!
Should I be using fetch row, fetch array or num_rows????

#add entry if NO matching record was found, else deny sign-up */
if(mysql_fetch_row($rs)) {
echo "The email address, $email has already been signed up for this event!";
}
else {
#create the 2nd query
$date="RDR_030605";
$sql="INSERT INTO events_bookings(date, fullname, email, mobile) VALUES ( \"$date\", \"$fullname\", \"$email\", \"$mobile\")";
Everytime I run it, I get the below message:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home2/rgevans/public_html/Regulars/events/rdr_signup/booking.php on line 147
- Basically I have a sign-up form where users sign up to an event. The code checks to see that they have not already
signed up. If they have already signed up they are told they are unable to. If they haven't then their signup is added to the db.
The full php is below.... Thanking in advance!!!

<?php

#ensure all fields have entries
if ($fullname and $email and $mobile)
{
#connect to mysql
$conn=@mysql_connect("localhost", "rgevans_adminuse", "excellent") or die ("Err:Conn");

#select the specified database
$rs = @mysql_select_db("rgevans_m2e", $conn) or die ("Err:Conn");

#create the 1st query
$date="RDR_030605";
$sql="SELECT * FROM events_bookings WHERE email = \"".$email."\" AND date = \"".$date."\"";

#add entry if NO matching record was found, else deny sign-up */
if(mysql_fetch_row($rs)) {
echo "The email address, $email has already been signed up for this event!";
}
else {
#create the 2nd query
$date="RDR_030605";
$sql="INSERT INTO events_bookings(date, fullname, email, mobile) VALUES ( \"$date\", \"$fullname\", \"$email\", \"$mobile\")";

#execute the query
$rs=mysql_query($sql,$conn);
}

#confirm the added record details
if($rs) {echo ("."); }
}

?>

----Ment2Excel (M2E)----
--LEARN BY EXAMPLE--
 
Before retrieving data from a MySQL query you need to execute the query.
1. Connect
2. excute query $result= mysql_query($sql,$conn);
3. fetch rows
Please read faq434-3850
 
AS DRJ478 you need to execute the query that checkws the database, before cheking for rows.

Even so, your are checking the wro variable for the prescence of rows.

$rs, only returns a connection to the database, after that you have tu run the query using mysql_query.
Code:
$results=mysql_query($sql,$rs);
notice i'm passing the connection $rs to the mysql_query funtion so it knows where to execute it.
the you can check the $results variable to see if any rows came back. from your query.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top