/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Calling an email [NOT RESLOVED]

Sorry for the double post, but I didnt let me undo the resloved. Anyways I have this:

[code=php]$dbquery = “SELECT email FROM `users` WHERE Random_key='” . $confirmid . “‘”;
$result2 = mysql_query($dbquery);
echo “mysql_result($result2,4)”; [/code]

with this error:
mysql_result(Resource id #4,4)

Once again sorry for the double post. ๐Ÿ˜ฎ

to post a comment
PHP

10 Comments(s) โ†ด

Copy linkTweet thisAlerts:
@NogDogJul 16.2009 โ€”ย No quotes:
[code=php]
echo mysql_result($result2, 4);
[/code]
Copy linkTweet thisAlerts:
@UAL225authorJul 16.2009 โ€”ย when I do no quotes I get this:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 4 on MySQL result index 4 in /home2/*****/public_html/confirm.php on line 28
Copy linkTweet thisAlerts:
@NogDogJul 16.2009 โ€”ย If you want the first row from the result, row numbering starts at 0 (as does column numbering):
[code=php]
echo mysql_result($result2, 0);
[/code]
Copy linkTweet thisAlerts:
@UAL225authorJul 16.2009 โ€”ย I want the 5th one, because that is where the e-mail address is located

i.e., ID, Fullname, gid, uname, email, birth, pass, Random_key, Active

That is the 5th one from the left is email 4th if you don't count ID.
Copy linkTweet thisAlerts:
@NogDogJul 16.2009 โ€”ย 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.)
Copy linkTweet thisAlerts:
@UAL225authorJul 16.2009 โ€”ย well if you mean row by horizontal, then yes. I want the first one to be returned with the value of the email address.
Copy linkTweet thisAlerts:
@NogDogJul 16.2009 โ€”ย 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:
<i>
</i>mysql&gt; SELECT email FROM <span><code>users</code></span> WHERE Random_key='gobbledygook'

email
==================
[email protected]

(1 row returned)
mysql&gt; _

So the [i][b]query result[/b][/i] would be one row with one column. Therefore the email address you are looking for would be in [b][i]query result[/i][/b] 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:
<i>
</i>mysql&gt; SELECT name, email FROM <span><code>users</code></span> ORDER BY email ASC

name email
========= ==================
Joe Blow [email protected]
John Doe [email protected]

(2 rows returned)
mysql&gt; _

In such a case you'd probably end up using mysql_fetch_assoc() in a while() loop in order to retrieve and process each [b][i]result row[/i][/b] in sequence.
Copy linkTweet thisAlerts:
@UAL225authorJul 16.2009 โ€”ย Yes, that explains what you mean by the rows. In that case I only want that one row, so how come when I put in a 0 it gives me an error?
Copy linkTweet thisAlerts:
@NogDogJul 16.2009 โ€”ย What error do you get?
Copy linkTweet thisAlerts:
@UAL225authorJul 16.2009 โ€”ย 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:
[code=php]<?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);
?>[/code]


In this line:
[code=php]$query = "SELECT Active FROM users WHERE Random_key='$confirmId'";[/code]

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!
ร—

Success!

Help @UAL225 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 โ€” BETA 5.3,
whats_new: community page,
up_next: more Davinciโ€ข003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciโ€ข003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...