Status
Not open for further replies.

sachin_kothari

Ambassador of Buzz
$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.
 

sreenidhi88

Journeyman
$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');
 
OP
sachin_kothari

sachin_kothari

Ambassador of Buzz
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:

paragkalra

The Linux Man !
Try inserting data manually through GUI like PHPMyAdmin or SQLYOG. It will generate the sql query which you can compare with yours.
 
OP
sachin_kothari

sachin_kothari

Ambassador of Buzz
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:

kapsicum

spice it up
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

Technomancer
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.
 
Status
Not open for further replies.
Top Bottom