Be gentle with me. I have a total of about 3 days experience trying to very quickly learn just enough php to fulfill a task.
The sample code I see almost always returns a recordset, and the recordset is then dumped into an array, and a "while" loop is used to traverse the recordset.
But, if I deliberately return only one record, I do not need to traverse a recordset - I just want to read returned field data for that one record. So, I found a way to do this, using
(As you see in the code below.)
The questions I have at this point:
1.) to test if the record was returned, should I use "empty":
or is there a better way?
2.) I see that I cannot address the $onerow array by field names, so is the only (or the best) way to use
or is there another way to reference the array?
3.) When do I close the connection? (right after the line starting with $results =
4.) Once my processing.php file has completed, possibly with a database error, but hopefully with success, how do I gracefully redirect the user to the page I want them to go to? (a custom error page, or a custom success page)
$querystringactivationcode = $_SERVER['QUERY_STRING'];
$query7 = "SELECT userid, activationcode FROM mytable WHERE ((xyzvalid=0) AND (activationcode = '" . $querystringactivationcode . "')) LIMIT 1";
$results = mysql_query($query7) or die(mysql_error());
$onerow = mysql_fetch_row($results);
## $onerow; // the 0 element in the array is userid
## $onerow; // the 0 element in the array is the activation code
## $onerow['userid']; // I see that the array cannot be accessed this way - elements of the array are referenced by integers (zero based array)
## so, I can do some processing:
if ($querystringactivationcode == $onerow)
Thank you from a php beginner