Page 1 of 1

nothing's showing up!

Posted: Thu Jul 04, 2002 11:20 pm
by cheatboy00
i'm having a problem here i cant seem to get a variable to show up... heres what the code look like

Code: Select all

// these vars (email and login), i got from a different submit form
$qry = mysql_query("SELECT * FROM users WHERE login = '$login' & email = '$email'");

while ($row = mysql_fetch_array($qry)) { 
   $question = $rowї'question'];
   $answer = $rowї'answer']; 
};

echo ("<Form action=f3.php method=post>");
echo ("<FONT COLOR=#FFFFFF>Please answer your question.</FONT>");

// this is teh place where i cant get the var to work
echo ("<P><FONT COLOR=#FFFFFF>&nbsp;&nbsp;&nbsp; $question</FONT>");


echo ("<BR>");
echo ("<BR><FONT COLOR=#FFFFFF>&nbsp;&nbsp;&nbsp; answer: </FONT>");
echo ("<BR><INPUT TYPE=text size=28 NAME=ans>");
echo ("<input type="hidden" name="question" value="$question" />");
echo ("<input type="hidden" name="login" value="$login" />");
echo ("<input type="hidden" name="email" value="$email" />");
echo ("<CENTER><INPUT TYPE=submit VALUE=Submit> <input type=reset NAME=Clear VALUE=Clear></CENTER>");
echo ("</form>");
erg.. i dont know whats wrong

Posted: Fri Jul 05, 2002 1:36 am
by protokol
instead of mysql_fetch_array($qry) use mysql_fetch_assoc($qry)

Posted: Fri Jul 05, 2002 2:15 am
by twigletmac
Using mysql_fetch_assoc() instead of mysql_fetch_array() shouldn't make too much of a difference except you'll only be getting an associative array and not a numerically indiced one as well.

You're probably not getting a result from your query, try something like

Code: Select all

<?php
$sql = "SELECT question, answer FROM users WHERE login = '$login' & email = '$email'";
echo $sql;  // Debugging to check the SQL statement
$qry = mysql_query($sql) or die(mysql_error()); 

echo 'There are '.mysql_num_rows($qry).' rows returned';  // Bit more debugging

if (mysql_num_rows($qry) == 1) &#123;
	$row = mysql_fetch_assoc($qry);
	$question = $row&#1111;'question']; 
	$answer = $row&#1111;'answer']; 
	echo <<<END
<form action="f3.php" method="post">
	<font color="#ffffff">Please answer your question.</font>
	<p><font color="#ffffff">&nbsp;&nbsp;&nbsp; $question</font></p>
	<p><font color="#ffffff">&nbsp;&nbsp;&nbsp; answer: </font><br />
		<input type="text" size="28" name="ans" />
		<input type="hidden" name="question" value="$question" />
		<input type="hidden" name="login" value="$login" />
		<input type="hidden" name="email" value="$email" /></p>
	<center>
		<input type="submit" value="Submit" /> <input type="reset" name="clear" value="Clear">
	</center>
</form> 
END;
&#125; else &#123;
	echo 'That login name or email address is incorrect';
&#125;
?>

Posted: Fri Jul 05, 2002 2:33 am
by martin
Are you sure these variables have been passed.
// these vars (email and login), i got from a different submit form
Try echoing them out to make sure.

Posted: Fri Jul 05, 2002 7:59 am
by llimllib
$qry = mysql_query("SELECT * FROM users WHERE login = '$login' & email = '$email'");
Just a note: with a query like this, be *very* careful that $login and $email have been cleaned - they should contain no spaces, no special characters, and not be longer than their respective fields in the database.

Posted: Fri Jul 05, 2002 3:29 pm
by cheatboy00
damn i think thats the problem, when you put in your email address into the form and submit it has a mysql error becasue of the @, is there anyway i can bypass that, case i was going throught my table (users, in myphpadmin) and i tryed to select teh samethign i was oing outside and it came up with this error......

You have an error in your SQL syntax near '@yahoo.com LIMIT 0, 30' at line 1

Posted: Fri Jul 05, 2002 3:39 pm
by cheatboy00
llimllib wrote:Just a note: with a query like this, be *very* careful that $login and $email have been cleaned - they should contain no spaces, no special characters, and not be longer than their respective fields in the database.
but the problem here is teh the variable $email has a special character and if i take it out it wont find any e-mail that would match it in the database.... but if i do ahve ti in it wont match it anyway how do i get around this.

Posted: Fri Jul 05, 2002 4:01 pm
by llimllib
well, @ really isn't a special character; that is, you don't have to escape (\) it before putting it into a database. Sorry I wasn't more specific.
You don't need to escape them, i'm sure, because I just wrote a script to insert emails into a database (well, that's part of what it did). MySQL often gives dodgy errors that don't really stem from where the error is, so I would take errors from it with a grain of salt.

Posted: Fri Jul 05, 2002 4:13 pm
by cheatboy00
o.k. that helps a bit then... but i think this muight be the problem

Code: Select all

$sql = mysql_query("SELECT question, answer FROM users WHERE login = '$login' & email = '$email'");
i know you had (or someone), $sql without the mysql_query ... and had a $qry = mysql_query(sql) ... but i dont see the need to have an extra var for the hell of it...

but anyway when i output this into an echo (the $sql var) it comes up as a Resource id #2 ??? adn this problem looked similar too th one i had on my poll so i edited teh code but its still thinking the $login and $email are invalid... heres the code now...

Code: Select all

$sql = mysql_query("SELECT question, answer FROM users WHERE login = '$login' & email = '$email'"); 

$result = mysql_fetch_row($sql); 
$rl = $result&#1111;0];

if ($rl == 1) &#123; 
   $row = mysql_fetch_assoc($result); 
   $question = $row&#1111;'question']; 
   $answer = $row&#1111;'answer']; 
  
  // all the code for output is right, except for the fact it wont output the question

&#125; else &#123; 
   echo "<font color="ff0000">That login name or email address is incorrect</font>";
   echo "<BR><font color="ff0000">$sql</font>";
   echo "<BR><font color="ff0000">$result</font>";
   echo "<BR><font color="ff0000">$rl</font>";
&#125;
erg this is giving me a headace

Posted: Fri Jul 05, 2002 4:40 pm
by cheatboy00
omg damn this is soo stupid....

i got it everyone see who wants to know the problem here......

well i'll give you hint

Code: Select all

$sql = "SELECT question, answer FROM users WHERE login = '$login' & email = '$email'";
hmm... lets think

.
.
.
.
.
.
.
.
.
.
.
.
.
.

and the correct answer is

Code: Select all

$sql = "SELECT question, answer FROM users WHERE login = '$login' AND email = '$email'";

// opposed to this

$sql = "SELECT question, answer FROM users WHERE login = '$login' & email = '$email'";

Posted: Fri Jul 05, 2002 7:15 pm
by mikeq
Aaaarrrrgggghhh.

Wood from the trees stuff

Posted: Fri Jul 05, 2002 9:30 pm
by RandomEngy
I saw that, but I didn't want to sound stupid if it was a valid synonym for AND. :(

Posted: Fri Jul 05, 2002 9:53 pm
by hob_goblin
i think && might be..

Posted: Sat Jul 06, 2002 5:12 am
by twigletmac
I can't believe how easy that was and how blind I was.
know you had (or someone), $sql without the mysql_query ... and had a $qry = mysql_query(sql) ... but i dont see the need to have an extra var for the hell of it...
That was me and it wasn't for the hell of it, it was so you could print it out to the screen to check that it looked - with the php variables added - like it should. So if there was something wrong with $email and $login, like they weren't being passed or something, you'd know. Keeping the statement as a separate variable is especially useful when the SQL gets more complicated and you're adding loads of PHP vars to it. If you just whack it straight into mysql_query() you have no idea what it looks like and you're running blind.

Mac