"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
If you want the first row from the result, row numbering starts at 0 (as does column numbering):
PHP Code:
echo mysql_result($result2, 0);
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
No, you want the 1st (and only) row returned by the query, don't you? (This is totally distinct from how and where that row is stored in the DB table.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
No, what I mean is that your query is going to return one result row with one field (column). In other words it will match on one row in the specified table where the value for column `Random_key` matches the supplied search value. If you ran the query from the MySQL command line, the output would be something like:
Code:
mysql> SELECT email FROM `users` WHERE Random_key='gobbledygook'
email
==================
joe@example.com
(1 row returned)
mysql> _
So the query result would be one row with one column. Therefore the email address you are looking for would be in query result row 0 (the only row) and column 0 (the only column).
For another query, you might request multiple columns and match on several or all rows in the database. It would return something like:
Code:
mysql> SELECT name, email FROM `users` ORDER BY email ASC
name email
========= ==================
Joe Blow joe@example.com
John Doe john@example.net
(2 rows returned)
mysql> _
In such a case you'd probably end up using mysql_fetch_assoc() in a while() loop in order to retrieve and process each result row in sequence.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
I figured it out, once you said the whole row thing, I started tweaking it. I will show you what I changed because that will explain better than I will
This is what I had:
PHP Code:
<?php //opens a connection to the MYSQUL require ("dbconnect.php"); $confirmId = mysql_real_escape_string($_GET['c']);
$errorMessage = ""; $validCount = 0;
$query = "SELECT Active FROM `users` WHERE Random_key='$confirmId'"; $result = mysql_query($query); $validCount = mysql_num_rows($result);
if($result['Active'] == 1) $errorMessage .= "You have already confirmed this account.<br/>"; if($validCount == 0) $errorMessage .= "You are trying to confirm an invalid account.<br/>";
if(empty($errorMessage)) { $query = "UPDATE `users` SET Active = 1 WHERE Random_key='$confirmId'"; mysql_query($query) OR die(mysql_error()); echo 'Your account has been confirmed! <br/>'; } else { echo $errorMessage; } //fetch and show their e-mail address from mysql echo mysql_result($result,0); ?>
In this line:
PHP Code:
$query = "SELECT Active FROM `users` WHERE Random_key='$confirmId'";
I changed from SELECT Active to SELECT email and now it selects their e-mail and still confirms their account when they press the link. Once again thanks!
Bookmarks