SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
Thread: mysql result source??
-
Dec 28, 2000, 23:16 #1
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
mysql result resource ???
hi, i might just be in over my head, but after a few hours of busting my brains, i hit a wall at line 109.
this is the section:
Code:100- if ($upass != $upass2) { 101- $upassError2 = "<LI>Your Two Passwords Did Not Match</LI>\n"; 102- $send = "no"; 103- } 104- if ($upass == $upass2) { 105- $db = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); 106- $sql = "SELECT * FROM $table WHERE uname='$uname'"; 107- $result = mysql_query($sql,$db); 108- } 109- $num = mysql_numrows($result); 110- if ($num != "0") { 111- $upassError3 = "<LI>The User Name you selected is already taken</LI>\n"; 112- $send = "no"; 113- } 114- }
Code:Warning: Supplied argument is not a valid MySQL result resource in /register1.php on line 109
i've only been writing in PHP for about a month and a half, so i'm really lost right. any help would be much appreciated. thanks in advance.
. . . chris
-
Dec 28, 2000, 23:45 #2
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Upon first glance that would appear to be the query being wrong that your query stored in the variable $sql is failing.
try printing $sql before the query
like
print $sql;
then take the query that appears on the screen and copy it and paste onto the command line mysql prompt to see why the query is failing maybe a bad tablename or fieldnamePlease don't PM me with questions.
Use the forums, that is what they are here for.
-
Dec 29, 2000, 00:08 #3
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i'm getting the following when i print $sql:
Code:SELECT * FROM users WHERE uname=''
Code:Empty set (0.00 sec)
Code:SELECT * FROM users WHERE uname='ace'
we're getting somewhere, but i don't know where
. . . chris
-
Dec 29, 2000, 00:16 #4
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This probably isn't it but I am pretty sure its mysql_num_rows($result)
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Dec 29, 2000, 00:22 #5
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why don't you try this:
$result = mysql_query("SELECT * FROM $table WHERE uname='$uname'");
}
$num = mysql_num_rows($result);
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Dec 29, 2000, 00:33 #6
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
no luck.
. . . chris
-
Dec 29, 2000, 00:36 #7
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
it's not making any sense. it should work.....but it's not.
. . . chris
-
Dec 29, 2000, 00:37 #8
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Boy that is pretty weird, let me ask you this does your query run even if no $uname has been specified? Like do you check for whether the form has been submitted before you run the query? The query is returning as a failed query that is why you get a bad result resource when you try to call mysql_num_rows($result) I think maybe the code gets run even before the form gets submitted could you show a little bit more code like all the php minus your username and password for your db of course.
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Dec 29, 2000, 01:04 #9
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
here ya go..........
to answer your questions:
-- the query runs even if no $uname has been entered, but it returns as an empty set (bec. it's empty). the mysql error msg is present at this point.
-- the query runs even if $uname has been entered, but the mysql error msg is still present at -- $num = mysql_numrows($result); --
-- for some stupid reason i'm getting the feeling that this is going to give me header errors too --
--- i'll tell you what. if you help me figure this out, i will owe you a huge one, you name it ---
Code:<?php $DBhost = "localhost"; $DBuser = "xxxxxxxx"; $DBpass = "xxxxxxxxxx"; $DBName = "xxxxxxxxxxx"; $table = "xxxxxxx"; $db = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //Start Error Message $errorMsg = "<TABLE ALIGN=center BORDER=0><TR><TD>\n"; $errorMsg .= "<FONT COLOR=red size=\"2\">Error!</FONT>\n"; $errorMsg .= "<FONT COLOR=red>Unable to send your message because of the following empty field(s):\n<UL>"; $errorMsgEnd = "</UL>\nPlease enter the required information and resend.</FONT>\n"; $errorMsgEnd .= "</TD></TR></TABLE>\n"; //End Error Message //Start Form Block $formblock = " <FORM METHOD=POST ACTION=\"/php-bin/register1.php\"> <TABLE width=\"250\" height=\"250\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"> <TR> <TD> <div align=\"center\"><FONT FACE=\"ARIAL\" SIZE=\"-1\">User Name</FONT></div> </TD> <TD> <INPUT TYPE=\"text\" NAME=\"uname\" size=\"20\" VALUE=\"$uname\"maxlength=\"20\"> </TD> </TR> <TR> <TD> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">Password</font></div> </TD> <TD> <INPUT TYPE=\"password\" NAME=\"upass\" size=\"20\" VALUE=\"$upass\"maxlength=\"20\"> </TD> </TR> <TR> <TD> <div align=\"center\"><font size=\"-1\" face=\"Arial, Helvetica, sans-serif\">Confirm<br> Password</font> </div> </TD> <TD> <input type=\"password\" name=\"upass2\" size=\"20\" VALUE=\"$upass2\"maxlength=\"20\"> </TD> </TR> <TR> <TD> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">E-mail</font></div> </TD> <TD> <input type=\"text\" name=\"Email\" size=\"20\" VALUE=\"$Email\"maxlength=\"40\"> </TD> </TR> <TR> <TD COLSPAN=2> <div align=\"center\"> <input type=\"hidden\" name=\"op\" value=\"ds\"> <input type=\"image\" src=\"/01/images/btn5b.gif\" width=\"44\" height=\"17\" alt=\"Send\" border=\"0\" align=\"absmiddle\" name=\"submit\"> </div> </TD> </TR> <TR> <TD COLSPAN=2></TD> </TR> </TABLE> </FORM> "; //End Form Block //Start ErrorCheck <!-- Note: the op variable will not equal anything until the form is submitted, none of the variables will --> // they need to see the form if ($op != "ds") { echo "$formBlock"; } else if ($op == "ds") { $send = "yes"; // check each required field and create an error message. // if any of the required fields are blank, set $send to "no". if ($upass == $upass2) { $db = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); $sql = "SELECT * FROM $table WHERE uname='$uname'"; print $sql; $result = mysql_query("SELECT * FROM $table WHERE uname='$uname'"); } $num = mysql_num_rows($result); //$result = mysql_query($sql,$db); //} //$num = mysql_num_rows($result); if ($num != "0") { $upassError3 = "<LI>The User Name you selected is already taken</LI>\n"; $send = "no"; } } if ($uname == "") { $unameError = "<LI>User Name</LI>\n"; $send = "no"; } if ($upass == "") { $upassError = "<LI>Password</LI>\n"; $send = "no"; } if ($Email == "") { $EmailError = "<LI>E-mail</LI>\n"; $send = "no"; } if ($upass != $upass2) { $upassError2 = "<LI>Your Two Passwords Did Not Match</LI>\n"; $send = "no"; } //End ErrorCheck // now do something depending value of $send if ($send == "yes") { //select the DB @mysql_select_db("$DBName") or die("Unable to select database $DBName"); //insert the values into the Db $sqlquery = mysql_query("INSERT INTO $table VALUES('$uname','$upass','$Email')"); Header("Location: /01/html/resrc.html"); } else if ($send == "no") { echo "$errorMsg"; echo "$upassError3"; echo "$unameError"; echo "$upassError"; echo "$EmailError"; echo "$upassError2"; echo "$errorMsgEnd"; echo "$formblock"; } ?>
. . . chris
-
Dec 29, 2000, 01:16 #10
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A couple of quickies I am not sure if they are causing the problem but you seem to connect to the database twice once on about the 5th line and one about 6 lines up from your error.
Another have you tried printing $result
print $result to see what it is returningPlease don't PM me with questions.
Use the forums, that is what they are here for.
-
Dec 29, 2000, 01:33 #11
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
print $result doesn't return anything.
what's interesting is that when i fill-in any other field in addition to $uname, print $sql doesn't return anything.
so, i remove the second db connection -- no problems.
print $sql now gives me a header error.
i remove print $sql --- i'm still getting the original "mysql result resource" error except that now the data is added in to the db because i'm unable to check for any duplicates of $uname.. . . chris
-
Dec 29, 2000, 11:21 #12
- Join Date
- Dec 2000
- Location
- Poland
- Posts
- 17
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Exchange lines 108 and 109. The order is wrong now.
It will prevent the error situations when an user inputs two different passwords.
Maybe it will help with all your errors
Chris
-
Dec 29, 2000, 11:44 #13
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by asdn
Exchange lines 108 and 109. The order is wrong now.
It will prevent the error situations when an user inputs two different passwords.
Maybe it will help with all your errors
ChrisCode:$me = chris (aka atomicmunky) while ($num = mysql_num_rows($result); ) = (Warning: Supplied argument is not a valid MySQL result resource ){ $me = frustrated ; }
-- let's assume for a second that i'm missing something really obvious that's causing this error -- is there any other way of going about this?
<Edited by atomicmunky on 12-29-2000 at 11:50 AM>. . . chris
-
Dec 29, 2000, 12:12 #14
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I changed a few things around and I think it may work now but give it a shot and BTW what header error was it giving?
<?php
$DBhost = "localhost";
$DBuser = "xxxxxxxx";
$DBpass = "xxxxxxxxxx";
$DBName = "xxxxxxxxxxx";
$table = "xxxxxxx";
$db = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
mysql_select_db($DBName) or die("Unable to select database $DBName");
//Start Error Message
$errorMsg = "<TABLE ALIGN=center BORDER=0><TR><TD>\n";
$errorMsg .= "<FONT COLOR=red size=\"2\">Error!</FONT>\n";
$errorMsg .= "<FONT COLOR=red>Unable to send your message because of the following empty field(s):\n<UL>";
$errorMsgEnd = "</UL>\nPlease enter the required information and resend.</FONT>\n";
$errorMsgEnd .= "</TD></TR></TABLE>\n";
//End Error Message
//Start Form Block
$formblock = "
<FORM METHOD=POST ACTION=\"/php-bin/register1.php\">
<TABLE width=\"250\" height=\"250\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
<TR>
<TD>
<div align=\"center\"><FONT FACE=\"ARIAL\" SIZE=\"-1\">User Name</FONT></div>
</TD>
<TD>
<INPUT TYPE=\"text\" NAME=\"uname\" size=\"20\" VALUE=\"$uname\"maxlength=\"20\">
</TD>
</TR>
<TR>
<TD>
<div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">Password</font></div>
</TD>
<TD>
<INPUT TYPE=\"password\" NAME=\"upass\" size=\"20\" VALUE=\"$upass\"maxlength=\"20\">
</TD>
</TR>
<TR>
<TD>
<div align=\"center\"><font size=\"-1\" face=\"Arial, Helvetica, sans-serif\">Confirm<br>
Password</font> </div>
</TD>
<TD>
<input type=\"password\" name=\"upass2\" size=\"20\" VALUE=\"$upass2\"maxlength=\"20\">
</TD>
</TR>
<TR>
<TD>
<div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">E-mail</font></div>
</TD>
<TD>
<input type=\"text\" name=\"Email\" size=\"20\" VALUE=\"$Email\"maxlength=\"40\">
</TD>
</TR>
<TR>
<TD COLSPAN=2>
<div align=\"center\">
<input type=\"hidden\" name=\"op\" value=\"ds\">
<input type=\"image\" src=\"/01/images/btn5b.gif\" width=\"44\" height=\"17\" alt=\"Send\" border=\"0\" align=\"absmiddle\" name=\"submit\">
</div>
</TD>
</TR>
<TR>
<TD COLSPAN=2></TD>
</TR>
</TABLE>
</FORM>
";
//End Form Block
//Start ErrorCheck
<!-- Note: the op variable will not equal anything until the form is submitted, none of the variables will -->
// they need to see the form
//Check to make sure the form was submitted by making sure clicked on the image input "submit" and the x coordinate of where they clicked is greater than 0
if ($submit_x > 0) {
if ($op == "ds") {
$send = "yes";
if ($upass == $upass2) {
//Make sure $uname is filled in
if ($uname != "") {
$result = mysql_query("SELECT * FROM $table WHERE uname='$uname'");
if (mysql_num_rows($result) > 0) {
$upassError3 = "<LI>The User Name you selected is already taken</LI>\n";
$send = "no";
}
}
}
}
//op does not = ds so show form again
else {
$send = "no";
echo "$formBlock";
}
// check each required field and create an error message.
// if any of the required fields are blank, set $send to "no".
if ($uname == "") {
$unameError = "<LI>User Name</LI>\n";
$send = "no";
}
if ($upass == "") {
$upassError = "<LI>Password</LI>\n";
$send = "no";
}
if ($Email == "") {
$EmailError = "<LI>E-mail</LI>\n";
$send = "no";
}
if ($upass != $upass2) {
$upassError2 = "<LI>Your Two Passwords Did Not Match</LI>\n";
$send = "no";
}
//End ErrorCheck
// now do something depending value of $send
if ($send == "yes") {
//select the DB
//insert the values into the Db
$sqlquery = mysql_query("INSERT INTO $table VALUES('$uname','$upass','$Email')");
Header("Location: /01/html/resrc.html");
}
if ($send == "no") {
echo "$errorMsg";
echo "$upassError3";
echo "$unameError";
echo "$upassError";
echo "$EmailError";
echo "$upassError2";
echo "$errorMsgEnd";
echo "$formblock";
}
}
?>
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Dec 29, 2000, 14:01 #15
- Join Date
- Dec 2000
- Location
- BOSTON MA
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hello my good man. i'm feeling a litle bit happier today.
tried out your version and it works like a charm. i couldn't believe it was working, so i filled out the form like 5 times. and it worked all five times !!!!!
-- thanks so much for your help -- it preserves my sanity for one more day.
the header error i was receiving was something along the line of "unable to send header. header already sent by bla-bla at line bla"
the first few times it was bec of "print $sql" that the error was occuring. i removed that, only to get the resource error and header error at line -- $num = mysql_num_rows($result); --
but it looks like it's working great now.
just so i'm sure what you changed with the code....(correct me if i'm wrong) but you're checking if "submit" is clicked first? i don't get the "x" part. if i understand correctly, "x" is not a variable but a function of PHP?
and also you're checking if the username is filled as you're checking if the passwords match?
i think i understand. i definitely need some more experience. so i'm on to the second part of the script. this should be interesting.
in case anyone is interested this bit of code (supplied by another kind soul) did the trick too.
Code:if ($upass == $upass2) { $sql = "SELECT COUNT(*) AS count FROM $table WHERE uname='$uname'"; $result = mysql_query($sql,$db); $count = mysql_fetch_array($result); if ($count["count"] != 0) { $upassError3 = "<LI>The User Name you selected is already taken</LI>\n"; $send = "no"; } }}}
so, as promised i owe you a gigantic assist of your choice.
once again, thanks so much.. . . chris
-
Dec 29, 2000, 14:10 #16
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No prob the _x part let me explain:
When you submit a form using http an input type of image which you use does not send the name of the input in your case "submit" what is does send is the x and y coordinates of where the user clicked on the image as input name_x and _y so in your case submit_x and submit_y so by checking for $submit_x being greater than 0 you are testing to see whther in fact the user clicked on the submit imagePlease don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks