Page 1 of 1
What does it mean?
Posted: Sat Aug 06, 2005 4:12 am
by Bekzod

.
//for checking email in database
$check="select id from subscribe where email='$email');
$check_result=mysql_query($check, $conn);
*/when i asked my friend for help how to delete entries he gave the next:
$Id= mysql_result($check_result, 0, "id");
/*
what does the above script mean exactly?
then i logically put the next it works but the meaning of the mentioned line.
$sql="delete from subscribe where id='$id');
$result=mysql_query($sql, $conn);
Bekzod
Re: What does it mean?
Posted: Sat Aug 06, 2005 5:38 am
by s.dot
Code: Select all
// This is your SQL line, you're telling the database what you're going to do
// It had a syntax error, I fixed it.
$check="select id from subscribe where email='$email'";
// This line is performing the query, and stores the result of it in $check_result
$check_result=mysql_query($check, $conn);
// Attempting to extract the ID from the returned result row, although you should use mysql_fetch_assoc.. or leave the "id" part out
$Id= mysql_result($check_result, 0, "id");
// This line is telling the database to delete the record $Id
// Again, a syntax error, I replaced ')' with a double quote -- "
$sql="delete from subscribe where id='$id'";
// This line is performing the delete query
$result=mysql_query($sql, $conn);
I added comments above to help you out a little bit
Posted: Sat Aug 06, 2005 5:43 am
by Chris Corbyn
Code: Select all
$check="select id from subscribe where email='$email'";
That's just assigning a written MySQL SELECT query to a PHP variable called
check. $email puts the email address into the query.
Code: Select all
$check_result=mysql_query($check, $conn);
That line simply runs the query on the database using the PHP function
mysql_query() and assigns the result to the PHP variable
check_result.
Now to retreive any data from the output of mysql_query() you need to use one of a handful of special PHP functions (
mysql_result() or
mysql_fetch_array() or
mysql_fetch_assoc()). Here you've used mysql_result.
Code: Select all
$Id= mysql_result($check_result, 0, "id");
That tells mysql_result to get some data stored in the database that you retreived using mysql_query(). It gets
id from row 0 of the results returned by the query and assigns it to the PHP variable
Id.
Now your final line just uses that data to run a DELETE query on the MySQL database just like you ran the SELECT query at the start
Code: Select all
$sql="delete from subscribe where id='$id'";
$result=mysql_query($sql, $conn);
EDIT | Damn I'm too slow

Posted: Sat Aug 06, 2005 5:53 am
by s.dot
d11wtq wrote:EDIT | Damn I'm too slow

Slower, but definately more detailed
