MYSQL Syntax Check
Hello Again Everyone,
I am VERY new to mysql and I have been having a problem getting the synax right for a query I need to run.
I was hoping that someone from this forum could take a peek at my syntax for this query and tell me where I may be messing up:
When I run this in mysql I get an error message but I THINK I am close.
<?php
$sql = "SELECT field_name FROM default_listingsDBElements WHERE (paypaluser = 'yes')";
?>
Any help would you can offer would be great.
Thanks
NYColt
s0da posted this at 16:28 — 12th April 2004.
He has: 157 posts
Joined: Mar 2004
try backticks around the fieldnames; you might have "badwords" that are being used.
SELECT `field_name` FROM `default_listingsDBElemenets` WHERE `paypaluser`='yes'
NYColt posted this at 17:26 — 12th April 2004.
They have: 42 posts
Joined: Dec 2002
this is the error message I get:
Unknown column 'paypaluser' in 'where clause'
s0da posted this at 18:07 — 12th April 2004.
He has: 157 posts
Joined: Mar 2004
is that column in your table?
NYColt posted this at 18:15 — 12th April 2004.
They have: 42 posts
Joined: Dec 2002
The table name is:default_listingsDBElemenets
The Column is:field_name
The field is: paypaluser
The field value is: yes or no ( i am looking for all that say yes)
s0da posted this at 18:24 — 12th April 2004.
He has: 157 posts
Joined: Mar 2004
well either the field `paypaluser` is NOT in the column OR the SQL server is messed up somehow.
NYColt posted this at 13:29 — 13th April 2004.
They have: 42 posts
Joined: Dec 2002
ok this is the query I needed, which works:
if($sql = "SELECT field_name FROM " . $config[table_prefix] . "default_listingsDBElements WHERE
field_name='paypaluser' and field_value = 'yes' ")
What I want to do now is call a function called:
<?php
renderpaypal();
?>
if the result of the query equals yes.
Any suggestions how I can call that function within the if statement?
Thanks for any help.
NYColt
Suzanne posted this at 15:41 — 13th April 2004.
She has: 5,507 posts
Joined: Feb 2000
Okay, you're not actually querying the database, eh? You're just setting up the question, not asking it.
<?php
// longhand for clarity
$sql = \"SELECT ... \";
$qry = mysql_query($sql);
if (!$qry) { echo mysql_error(); }
// shorthand for brevity
if (!$qry = mysql_query(\"SELECT ...\")) echo mysql_error();
?>
Normally at this point you get the results of the query and then manipulate them (results with mysql_fetch_array or similar).
I would suggest you rethink your query to be to get the value of paypaluser, then set a condition then.
i.e.
<?php
// select the value for paypaluser (yes/no) from the table for this user
$sql = \"SELECT paypaluser FROM \" . $config[table_prefix] . \"default_listingsDBElements WHERE user_field_name = user_field_value\");
$qry = mysql_query($sql);
if (!$qry) echo mysql_error();
while ($row = mysql_fetch_array($qry)) {
$paypaluser = $row['paypaluser'];
if ($paypaluser == 'yes') {
renderpaypal();
}
else {
// do something else, choose another payment method?
}
}
?>
m3rajk posted this at 02:32 — 17th April 2004.
They have: 461 posts
Joined: Jul 2003
i'm not sure of the structure, could you give us something to have a common basis?
give us partial structure. we might be able to actually help you modify to a better structure:
ie: if you need a yes/no feild, a tiny int using 0/1 (true/false) may actually be better than a text feild that will use yes/no.
id est:
main table structure:
pid int # player id number
player char(15) # username
paypal tinyint(1) # uses paypal
stormpay tinyint(1) # uses stormpay
php snippet:
# this grabs everyone who uses paypal/stormpay
$sql="SELECT username FROM users WHERE";
switch($paytype){
case '0': $sql.=" paypal=1"; break; # this gets the paypal users
case '1': $sql.=" AND stormpay=1;" break; # this add stormpay
case '2': $sql.=" stormpay=1;"; break; # storm pay only
}
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.