nothing's showing up!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

nothing's showing up!

Post 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
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

instead of mysql_fetch_array($qry) use mysql_fetch_assoc($qry)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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;
?>
User avatar
martin
Forum Commoner
Posts: 33
Joined: Fri Jun 28, 2002 12:59 pm
Location: Cambridgeshire

Post 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.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post 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.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post 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
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post 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.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post 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.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post 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
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post 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'";
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Aaaarrrrgggghhh.

Wood from the trees stuff
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

I saw that, but I didn't want to sound stupid if it was a valid synonym for AND. :(
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

i think && might be..
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply