473,511 Members | 15,364 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sql query

chelvan
90 New Member
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
10 1415
Atli
5,058 Recognized Expert Expert
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
90 New Member
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
90 New Member
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
5,058 Recognized Expert Expert
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
90 New Member
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
90 New Member
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
5,058 Recognized Expert Expert
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
90 New Member
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
5,058 Recognized Expert Expert
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
90 New Member
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

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

Similar topics

2
3413
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
29
2477
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
9
3109
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
5372
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
4
2133
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets...
14
3853
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
3485
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
6
4816
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
3113
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
6
4373
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.