Im getting the following error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘country FROM countries WHERE idcountry=4 VALUES (”,’Almelo’)’ at line 1
Thanks in advance for helping me with this problem because im trying to fix it for 3 days now.
Im getting 2 data pieces from my form through $POST. This is the form:
form action="inc/add/addcity.php" method="post">
Select country:
$query="SELECT idcountry,country FROM countries ORDER BY country ASC";
$result = mysql_query ($query);
echo "<select name='countrybox' id='countrybox' value=''>Country</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[idcountry]>$nt[country]</option>";}
echo "</select>";<br>
City to add: <input type="text" name="addcity" id="addcity"/>
<input type="submit" name="sumit" value"sumit"/>
</form>
The option value’s are coming from my database
Now the action php file
include 'addmysql.php';
$data = $_POST;
$citypost = $data['addcity'];
$cityselected = $data['countrybox'];
$cityselected1 = "SELECT country FROM countries WHERE idcountry=$cityselected";
$citytable = "cities";
$citytable .= "$cityselected1";
$sql= "INSERT INTO $citytable VALUES ('','$citypost')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "<script type='text/javascript'>window.location='../../add.php'; </script>"
I think this line:
is causing grief.
$citytableends up with the SELECT query sandwiched inside of the INSERT. That is the reason for the specific error you’re seeing.However, I’m not sure I fully understand what you want this code to do.