Page 1 of 1
Varchar Query Issues
Posted: Wed Jun 11, 2003 10:02 am
by Bipper
I am running a query based on user input that will fill out a field called username or id. I throw togeter the query and it works fine for id# but when ever i use the quewry on anything that is varchar type it poops out and gives me this :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bipperv/public_html/MyBeam/php-bin/editUser.php on line 29
Any help would be cool
Later
Bipper
Posted: Wed Jun 11, 2003 10:07 am
by twigletmac
Sounds like there's something wrong with the SQL - could we see your code please.
Mac
Posted: Wed Jun 11, 2003 10:31 am
by cactus
Did you have a connection to the database ? Did you lose the connection ??
Regards,
Posted: Wed Jun 11, 2003 10:50 am
by Wayne
could be a couple of things, are your values in the queries enclosed in quotes?
post the SQL so we can see it.
Posted: Wed Jun 11, 2003 1:28 pm
by PastAustin
Wayne wrote:could be a couple of things, are your values in the queries enclosed in quotes?
post the SQL so we can see it.
That is exactly what it sounds like to me. You other options are a lost connection, or even a blank database entry or querying the wrong table.
Update
Posted: Wed Jun 11, 2003 9:22 pm
by Bipper
Well i know the sql is good and the connection and everything is good. I will put code up although due to a non disclosure agreement i can't post much.
Var names have all been changed the structure remains intact -
if ($submit) {
if ($id || $username)
{
if ($username)
{
$sql = "SELECT * FROM user WHERE beamRank=$username";
}
if ($id)
{
$sql = "SELECT * FROM user WHERE id=$id";
}
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<!--Make FORM to print out values for editing-->
<form method="post" action="<?php echo $PHP_SELF ?>">
<table>
<tr>
<td bgcolor="#FFFFCC">
ID#:
</td>
<td bgcolor="#CCFFFF">
<input type="Text" name="idE" value="<?php echo $myrow[id] ?>">
</td>
</tr>
<tr>
<td bgcolor="#CCFFFF">
Username:
</td>
<td bgcolor="#CCFFFF">
<input type="Text" name="usernameE" value="<?php echo $myrow[Uname] ?>">
</td>
</tr>
<tr>
<table>
What i am doing is pulling data based on either a id or username information put in on one form. The data is then filled in on a from that appears and allows for the user to edit it. Then it will eventually be able to update the database.
That is a brief dumbed down version. My table IS populated with correct data and the script works perfect if the integer id field is filled out. However the second you enter the username field it tirds out on me. I know the uname field is there and filled in correctly.
No solutions offered so far have helped - but thanks for the help thus far all
Bipper
Posted: Wed Jun 11, 2003 9:39 pm
by Bipper
LOVE THE AVATAR WAYNE LOL

Posted: Thu Jun 12, 2003 3:30 am
by Wayne
try :
Code: Select all
$sql = "SELECT * FROM user WHERE beamRank="$username"";
Im assuming that this is the varchar field that you are referring to not working! you can evaluate ints in an sql without the quotes but varchar, char etc require them.
Posted: Thu Jun 12, 2003 4:20 am
by twigletmac
It is most likely the lack of quotes that is causing the problem, to debug problems like this in the future though you should add some error handling to those database functions:
Code: Select all
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
You can also negate the need for escaping double quotes in your SQL by using single quotes around values (it's better SQL as well):
Code: Select all
$sql = "SELECT * FROM user WHERE beamRank='$username'";
Mac
Posted: Thu Jun 12, 2003 4:35 am
by cactus
(my 2 pence/cents worth)
On the subject of quotes I preffer to concatinate strings/queries:
Code: Select all
$sql = "SELECT * FROM user WHERE beamRank='".$username."'";
Helps with syntax highlighing too.

Posted: Thu Jun 12, 2003 4:37 am
by cactus
If I used the right BB tags!! :
Code: Select all
$sql = "SELECT * FROM user WHERE beamRank='".$username."'";

Doh!
Posted: Fri Jun 13, 2003 10:25 am
by Bipper
Yesh you guys were right just the simple lack of quotes arround the $username variable... How sad lol. Thank you all very much for the help, and I am sorry iI only gave you that little bit to work with

I have been in a frantic rush trying to get this project wrapped up
Thanks again
Bipper