By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

sql query

chelvan
P: 90
Expand|Select|Wrap|Line Numbers
  1.  $sql_addgroup=mysql_query("insert into group (refno,name,description,type,access) VALUES ('$userref','$gn','$gd','$gt','$ga')");
  2.     if(!mysql_query($sql_addgroup,$con)){
  3.     die('error:'.mysql_error());
  4.     }
  5.  
hi
all
when i run the above query its display ur query is empty. but i able to print those values b4 the query & after the query (the 2nd printing works only on after removing the query).
y i got such message?



thanks in advance
chel-1
Sep 9 '08 #1
Share this Question
Share on Google+
10 Replies


Atli
Expert 5K+
P: 5,058
Hi.

Read the code a little more carefully mate.

First you execute a query and assign the result to $sql_addgroup variable.
Then you execute another query using the $sql_addgroup variable, which a this point is a boolean value, which is not a valid SQL query.
Sep 9 '08 #2

chelvan
P: 90
thanks
its me again

my problem is "i want to check b4 insert the value is there or not?" how i solve it. that y i used the previous post way?


chel-1.
Sep 9 '08 #3

chelvan
P: 90
thanks
its me again

my problem is "i want to check b4 insert the value is there or not?" how i solve it. that y i used the previous post way?


chel-1.

my code is below
Expand|Select|Wrap|Line Numbers
  1.  
  2. $sql_selectUser=mysql_query("SELECT * FROM user WHERE username='$us'");
  3. while($row=mysql_fetch_array($sql_selectUser)){
  4.     $myref=$row['refno'];
  5.     }
  6.  
  7. $sql_checkUser=mysql_query("SELECT refno FROM group WHERE refno='$myref'");
  8. while($row=mysql_fetch_array($sql_checkUser)){
  9.     $userref=$row['refno'];
  10.     }
  11.  
  12. if((strlen($userref))>0){
  13.  echo "Do Something";
  14.  }
  15.  else if((strlen($userref))==0){
  16.  $userref=$myref;
  17.  
  18.  $sql_addgroup=mysql_query("insert into group (refno,name,description,type,access) VALUES ('$userref','$gn','$gd','$gt','$ga')");
  19.     if(!mysql_query($sql_addgroup,$con)){
  20.     die('error:'.mysql_error());
  21.     }
  22.     }
  23.  


plz correct above code 4 me.






thanks
chel-1
Sep 9 '08 #4

Atli
Expert 5K+
P: 5,058
Check what value before you insert what?
Your going to have to explain that a lot better.

The only thing I can see *wrong* with that code is what I posted earlier.
Once that is fixed the error you were talking about should be fixed.

P.S.
Please use clear English when posting.
By that I mean; don't use things like "b4", "4 me", etc...
Makes everything much much harder to read, especially in technical forums like these.

And the code tags are [code] ... [/code], not <code>...</code>.
Sep 9 '08 #5

chelvan
P: 90
Check what value before you insert what?
Your going to have to explain that a lot better.

The only thing I can see *wrong* with that code is what I posted earlier.
Once that is fixed the error you were talking about should be fixed.

P.S.
Please use clear English when posting.
By that I mean; don't use things like "b4", "4 me", etc...
Makes everything much much harder to read, especially in technical forums like these.

And the code tags are
Expand|Select|Wrap|Line Numbers
  1.  ... 
, not <code>...</code>.


sorry for my mistakes. i'm still having problem. sorry
from my first query i got the user_ref_no form the table 'user'
on the second query check the above user_ref_no is available or not on the table 'group'. if not i insert the fields else update.

how can i solve it?

thanks
chel-1
Sep 9 '08 #6

chelvan
P: 90
sorry for my mistakes. i'm still having problem. sorry
from my first query i got the user_ref_no form the table 'user'
on the second query check the above user_ref_no is available or not on the table 'group'. if not i insert the fields else update.

how can i solve it?

thanks
chel-1
its me again
i solved checking id. now i've the error on the inserting statements.its return "QUERY WAS EMPTY"

$sql_addgroup=mysql_query("insert into group(refno,name,description,type,access)VALUES('$ user_ref','$gn','$gd','$gt','$ga')");
if(!mysql_query($sql_addgroup,$con)){
die('error:'.mysql_error());
}

how i do it? any errors on the code?


chel-1
Sep 9 '08 #7

Atli
Expert 5K+
P: 5,058
Expand|Select|Wrap|Line Numbers
  1. $sql_addgroup = mysql_query("...");
  2. if(!mysql_query($sql_addgroup,$con)){
  3.   die('error:'.mysql_error());
  4. }
  5.  
You are calling the mysql_query function twice, using the result of the first one as the SQL for the second. So, the second query is being passed a boolean value, which, as far as MySQL is concerned, is empty.

It could all be replaced by the standard:
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("...") or die(mysql_error());
  2.  
Sep 9 '08 #8

chelvan
P: 90
Expand|Select|Wrap|Line Numbers
  1. $sql_addgroup = mysql_query("...");
  2. if(!mysql_query($sql_addgroup,$con)){
  3.   die('error:'.mysql_error());
  4. }
  5.  
You are calling the mysql_query function twice, using the result of the first one as the SQL for the second. So, the second query is being passed a boolean value, which, as far as MySQL is concerned, is empty.

It could all be replaced by the standard:
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("...") or die(mysql_error());
  2.  
thanks
well, i changed the code that follows.

Expand|Select|Wrap|Line Numbers
  1. $sql_addgroup=mysql_query("insert into group(refno,name,description,type,access)VALUES('$user_ref','$gn','$gd','$gt','$ga')") or die(mysql_error());
but still having errors its return
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group(refno,name,description,type,access)VALUES(' 00000000030','123','1233','Frie' at line 1

what is error?
chel-1
Sep 9 '08 #9

Atli
Expert 5K+
P: 5,058
group is a reserved keyword.

If you want to use it as a database / table / column name you have to enclose it in back-ticks (`group`)
Sep 9 '08 #10

chelvan
P: 90
group is a reserved keyword.

If you want to use it as a database / table / column name you have to enclose it in back-ticks (`group`)

thanks
all corrects

thanks forum

chel-1
Sep 9 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.