 |
18-11-2008, 01:42 PM
|
#1 (permalink)
|
|
Alpha Geek
Join Date: Dec 2004
Location: Pune
Posts: 569
|
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.
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
18-11-2008, 04:29 PM
|
#2 (permalink)
|
|
Broken In
Join Date: Sep 2006
Posts: 147
|
Re: SQL Query Error
Quote:
Originally Posted by sachin_kothari
$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
|
|
|
18-11-2008, 05:10 PM
|
#3 (permalink)
|
|
Alpha Geek
Join Date: Dec 2004
Location: Pune
Posts: 569
|
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.
|
|
|
18-11-2008, 05:25 PM
|
#4 (permalink)
|
|
The Linux Man !
Join Date: Jan 2006
Location: Nagpur, Maharashtra, India
Posts: 217
|
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!
|
|
|
18-11-2008, 06:07 PM
|
#5 (permalink)
|
|
Alpha Geek
Join Date: Dec 2004
Location: Pune
Posts: 569
|
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
|
|
|
18-11-2008, 07:10 PM
|
#6 (permalink)
|
|
Commander in Chief
Join Date: Jul 2005
Posts: 6,658
|
Re: SQL Query Error
Escaping (The slashes do that)
__________________
Harsh J
www.harshj.com
|
|
|
18-11-2008, 07:24 PM
|
#7 (permalink)
|
|
spice it up
Join Date: Apr 2004
Location: mumbai
Posts: 106
|
Re: SQL Query Error
do this ...
PHP Code:
$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());
let me know if ur problem is solved
|
|
|
18-11-2008, 09:46 PM
|
#8 (permalink)
|
|
Human Spambot
Join Date: May 2008
Location: Haldwani(Nainital)
Posts: 2,124
|
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.
|
|
|
18-11-2008, 09:55 PM
|
#9 (permalink)
|
|
Commander in Chief
Join Date: Jul 2005
Posts: 6,658
|
Re: SQL Query Error
Er guys, he already has solved it an hour earlier than kapsicum's post
__________________
Harsh J
www.harshj.com
|
|
|
19-11-2008, 09:27 AM
|
#10 (permalink)
|
|
Alpha Geek
Join Date: Dec 2004
Location: Pune
Posts: 569
|
Re: SQL Query Error
yup guys, its solved.
anyway thanks for all your responses.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|