DIGIT-ARC read-only archive · snapshot: July 23, 2026

SQL Query Error

10 posts · originally from https://geek.digit.in/community/threads/sql-query-error.102376/

sachin_kothari
sachin_kothari Original post #1
Nov 18, 2008 at 1:42 PM
$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.
S
Nov 18, 2008 at 4:29 PM
$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');
sachin_kothari
Nov 18, 2008 at 5:10 PM
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
paragkalra
Nov 18, 2008 at 5:25 PM
Try inserting data manually through GUI like PHPMyAdmin or SQLYOG. It will generate the sql query which you can compare with yours.
sachin_kothari
Nov 18, 2008 at 6:07 PM
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')";
QwertyManiac
Nov 18, 2008 at 7:10 PM
Escaping (The slashes do that) :)
kapsicum
Nov 18, 2008 at 7:24 PM
do this ...

PHP:
$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
toofan
toofan #8
Nov 18, 2008 at 9:46 PM
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.
QwertyManiac
Nov 18, 2008 at 9:55 PM
Er guys, he already has solved it an hour earlier than kapsicum's post :)
sachin_kothari
Nov 19, 2008 at 9:27 AM
yup guys, its solved.
anyway thanks for all your responses.