darkenroyce Posted April 14, 2008 Share Posted April 14, 2008 Hi Guys I'm getting the syntax problem with the following code: $sql="INSERT INTO squad (players) VALUES ('$_POST[playerid]') WHERE p_id="$id""; mysql_query($sql, $con) or die(mysql_error()); p_id is the player ID within the SQL table, and $id - $id = $_GET ['n_id']; - is a integer php variable passed through a URL. Tried to googling this but found no simple syntax correction. Please advise.... Cheers Darkenroyce Link to comment https://forums.phpfreaks.com/topic/101104-insertwhereusing-variables/ Share on other sites More sharing options...
p2grace Posted April 14, 2008 Share Posted April 14, 2008 Try this: <?php $sql="INSERT INTO `squad` (`players`) VALUES ('".$_POST[playerid]."') WHERE `p_id` ='$id'"; mysql_query($sql, $con) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/101104-insertwhereusing-variables/#findComment-517085 Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 Why are you using the WHERE clause in an insert statement? It's usually reserved for SELECT, UPDATE and DELETE Link to comment https://forums.phpfreaks.com/topic/101104-insertwhereusing-variables/#findComment-517089 Share on other sites More sharing options...
p2grace Posted April 14, 2008 Share Posted April 14, 2008 lol woops yeah.... definitely don't need that Link to comment https://forums.phpfreaks.com/topic/101104-insertwhereusing-variables/#findComment-517094 Share on other sites More sharing options...
p2grace Posted April 14, 2008 Share Posted April 14, 2008 I was just looking at syntax, didn't even look at the logic. Link to comment https://forums.phpfreaks.com/topic/101104-insertwhereusing-variables/#findComment-517095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.