0
INSERT INTO `C301554_myroom`.`visitor` (
`Name` ,
`Address` ,
`City` ,
`State` ,
`Country` ,
`PIN` ,
`no_of_males` ,
`no_of_females` ,
`no_of_childrens` ,
`mail` ,
`Phone_no` ,
`Senior_Citizens` ,
`ID` ,
`date_from` ,
`date_to` ,
`Visitor_ID` ,
`Vehicle_No` ,
`Purpose`
)
VALUES (
'Jaspreet', 'D-66', 'Rohtak', 'HR', (

SELECT Country_Name
FROM country_code
WHERE Country_Code = "IN"
), '124001', '1', '1', '1', '', '2324342', 'Y', 'passport', '3/7/2011', '6/7/2011', 'null', '22', 'For Admission'

Above query is running on mysql but when i am trying to execute the query through php it is giving mysql error. -----here the code is------

$sql="INSERT INTO `C301554_myroom`.`visitor` (
`Name` ,
`Address` ,
`City` ,
`State` ,
`Country` ,
`PIN` ,
`no_of_males` ,
`no_of_females` ,
`no_of_childrens` ,
`mail` ,
`Phone_no` ,
`Senior_Citizens` ,
`ID` ,
`date_from` ,
`date_to` ,
`Visitor_ID`,
`Vehicle_No`,
`Purpose`
)

VALUES('$jName','$jAddress','$jCity','$jState',(select Country_Name from country_code where Country_Code=".$jcountry."),'$jpin','$jmale','$jfemale','$jchildren','$jemail','$jphone','$jSenior_Citizen','$jid','$jfrom','$jto','$RID','$jvehicle','$jpurpose')";
7
  • Please go back and format your code legibly. Commented Jul 4, 2011 at 7:33
  • echo $sql, probably a quote or other un-santised char Commented Jul 4, 2011 at 7:34
  • 1
    I think that Country_Code is string, so you should add quotes to Country_Code='".$jcountry."' Commented Jul 4, 2011 at 7:35
  • Country_Code should be quoted as its a string Commented Jul 4, 2011 at 7:36
  • i know where is the error when the subquery executes (select Country_Name from country_code where Country_Code=".$jcountry.") it will return a variable (for eg india) now to execute the whole query the value teturned(INDIA) should be in double quotes("INDIA") and i am unable to do that.How to concatenate double quotes with it.I tried it many times using . operator but still getting error Commented Jul 4, 2011 at 7:37

1 Answer 1

2

You're missing single quotes around the $jcountry in the sub-query that select the country code.

(select Country_Name from country_code where Country_Code='".$jcountry."')
Sign up to request clarification or add additional context in comments.

1 Comment

@Jaspreet Singh - Use prepared statements and you will no longer need to care about single quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.