Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 18-11-2008, 01:42 PM   #1 (permalink)
Alpha Geek
 
sachin_kothari's Avatar
 
Join Date: Dec 2004
Location: Pune
Posts: 569
Question SQL Query Error


$sql=mysql_query("INSERT INTO `survey_result` (`Name`, `Email`, `AgeGroup`, `NetAccess`, `DayOnline`, `WeekOnline`, `Activities`, `NewsRead`, `NewsSection`, `ClickAds`, `AdInfo`, `LikeIdea`, `Suggestion`) VALUES
($name, $email, $age_group, $net_access1, $day_online, $week_online, $activities1, $news_read, $news_section1, $click_ads, $ad_info1, $like_idea, $suggest)") or die(mysql_error());

What's wrong with this query? Its giving me an error saying that "error in SQL Synatax". Please help me.
sachin_kothari is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 18-11-2008, 04:29 PM   #2 (permalink)
Broken In
 
Join Date: Sep 2006
Posts: 147
Default Re: SQL Query Error

Quote:
Originally Posted by sachin_kothari View Post
$sql=mysql_query("INSERT INTO `survey_result` (`Name`, `Email`, `AgeGroup`, `NetAccess`, `DayOnline`, `WeekOnline`, `Activities`, `NewsRead`, `NewsSection`, `ClickAds`, `AdInfo`, `LikeIdea`, `Suggestion`) VALUES
($name, $email, $age_group, $net_access1, $day_online, $week_online, $activities1, $news_read, $news_section1, $click_ads, $ad_info1, $like_idea, $suggest)") or die(mysql_error());

What's wrong with this query? Its giving me an error saying that "error in SQL Synatax". Please help me.
try this
insert into survey_result values('&name','&email','&agegroup','&netaccess',' &dayonline','&weekonline','&activities','&newsread ','&newssection','&clickads','&adinfo','&likeidea'
,'&suggest');
__________________
techtricks.co.in

portforwarding
xp-vista crossover connection
installing xp on vista notebooks
sreenidhi88 is offline  
Old 18-11-2008, 05:10 PM   #3 (permalink)
Alpha Geek
 
sachin_kothari's Avatar
 
Join Date: Dec 2004
Location: Pune
Posts: 569
Default Re: SQL Query Error

Thanks for your reply dude. But this does not seems to be working. It insert &name, &email and so in my database, not their actual values. My mysql version is 5.0.67

Last edited by sachin_kothari; 18-11-2008 at 05:20 PM.
sachin_kothari is offline  
Old 18-11-2008, 05:25 PM   #4 (permalink)
The Linux Man !
 
paragkalra's Avatar
 
Join Date: Jan 2006
Location: Nagpur, Maharashtra, India
Posts: 217
Default Re: SQL Query Error

Try inserting data manually through GUI like PHPMyAdmin or SQLYOG. It will generate the sql query which you can compare with yours.
__________________
Parag.A.Kalra, The Linux Man
http://www.paragkalra.com/
In this world without WALLS and GATES who need WINDOWS! USE LINUX! STOP PIRACY! GO OPEN SOURCE!
paragkalra is offline  
Old 18-11-2008, 06:07 PM   #5 (permalink)
Alpha Geek
 
sachin_kothari's Avatar
 
Join Date: Dec 2004
Location: Pune
Posts: 569
Default Re: SQL Query Error

Recosrds are getting inserted by doing it manually. But it isnt working through the code. I tried getting the values from my form to the database page. I am getting all the values alright. Its just that the query is not executing.

Edit: I tried generating the PHP code as you said and i got this

$sql = 'INSERT INTO `survey_result`(`Name`, `Email`, `AgeGroup`, `NetAccess`, `DaysOnline`, `WeeksOnline`, `Activities`, `NewsRead`, `NewsSection`, `ClickAds`, `AdInfo`, `LikeIdea`, `Suggestion`) VALUES ('
. ' \'Sachin Kothari\', \'sachin@sachin.com\', \'22-35 years\', \'/Home/Office/NetCafe/Othe\', \'More than 6 hours\', \'Daily\', \'/E-Mail/Search/Entertainment/Chat/Online Shopping/Social Networking/News/Work/Test\', \'Yes\', \'/Frontpage/Business/Sports\', \'Only if it is related to my needs\', \'/NewsPapers/Friends/Test\', \'Excellent Idea\', \'Test\')';

What are the slashes doing here? How do i modify it to make it work with the query?

Its working. I used this query.

$query = "INSERT INTO `survey_result` (`Name`, `Email`, `AgeGroup`, `NetAccess`, `DaysOnline`, `WeeksOnline`, `Activities`, `NewsRead`, `NewsSection`, `ClickAds`, `AdInfo`, `LikeIdea`, `Suggestion`) VALUES
('$name', '$email', '$age_group', '$net_access1', '$day_online', '$week_online', '$activities1', '$news_read', '$news_section1', '$click_ads', '$ad_info1', '$like_idea', '$suggest')";

Last edited by sachin_kothari; 18-11-2008 at 06:24 PM. Reason: Automerged Doublepost
sachin_kothari is offline  
Old 18-11-2008, 07:10 PM   #6 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: SQL Query Error

Escaping (The slashes do that)
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 18-11-2008, 07:24 PM   #7 (permalink)
spice it up
 
kapsicum's Avatar
 
Join Date: Apr 2004
Location: mumbai
Posts: 106
Default Re: SQL Query Error

do this ...

PHP Code:
$sqlmysql_query("INSERT INTO `survey_result` (`Name`, `Email`, `AgeGroup`, `NetAccess`, `DayOnline`, `WeekOnline`, `Activities`, `NewsRead`, `NewsSection`, `ClickAds`, `AdInfo`, `LikeIdea`, `Suggestion`) VALUES (".$name.", ".$email.", ".$age_group.", ".$net_access1.", ".$day_online.", ".$week_online.", ".$activities1.", ".$news_read.", ".$news_section1.", ".$click_ads.", ".$ad_info1.", ".$like_idea.", ".$suggest.")") or die(mysql_error()); 
let me know if ur problem is solved
kapsicum is offline  
Old 18-11-2008, 09:46 PM   #8 (permalink)
Human Spambot
 
toofan's Avatar
 
Join Date: May 2008
Location: Haldwani(Nainital)
Posts: 2,124
Default Re: SQL Query Error

you just break the code in two segments then everything would be ok. do as follows.
Copy this code and past it.

Code:
$query = "Insert into survery_result (Name, Email, AgeGroup, NetAccess, DayOnline, WeekOnline, Activities, NewsRead, NewsSection, ClickAds, AdInfo, LikeIdea, Suggestion) VALUES
('$name', '$email', '$age_group', '$net_access1', '$day_online', '$week_online', '$activities1', '$news_read', '$news_section1', '$click_ads', '$ad_info1', '$like_idea', '$suggest')";
$result = mysql_query($query);
Don't use ' ' sings in the table name and the fild names.
__________________
Check my work at:

http://www.flickr.com/photos/vimaljoshi
toofan is offline  
Old 18-11-2008, 09:55 PM   #9 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: SQL Query Error

Er guys, he already has solved it an hour earlier than kapsicum's post
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 19-11-2008, 09:27 AM   #10 (permalink)
Alpha Geek
 
sachin_kothari's Avatar
 
Join Date: Dec 2004
Location: Pune
Posts: 569
Default Re: SQL Query Error

yup guys, its solved.
anyway thanks for all your responses.
sachin_kothari is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Splinter Cell:Double Agent Visual C++ runtime error and ***MUST CHECK*** error zerohourkill Gamerz 17 04-08-2007 02:47 PM
Post Vista installation query!!! "CPU OVERVOLTAGE ERROR"!!! sude CPU / Motherboards 1 18-02-2007 08:53 PM
Windows XP Booting and Installation Error (LILO Error) arijitraja Software Q&A 3 26-02-2006 03:32 PM
Microtek Monitor Query and PHPBB Attachment Mod Query vwad Software Q&A 1 20-03-2005 09:32 AM
Error error error....gives me hell of a terror abhilash QnA (read only) 4 06-11-2004 12:41 AM

 
Latest Threads
- by gforz
- by soumya
- by Sujeet
- by icebags
- by Charan

Advertisement




All times are GMT +5.5. The time now is 02:59 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2