Jump to content

[SOLVED] cant find my syntax error


rondog

Recommended Posts

I have a basic select statement and its throwing a syntax error. All I am doing is updating group name in my DB. I am checking if they submit the same one as well as checking if the one they are submitting is a duplicate which is why I have 2 queries.

 

It is saying:

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 'group WHERE name = 'ROTC'' at line 1

 

If I echo out my select statement I get this which looks fine to me:


SELECT name FROM group WHERE name = 'ROTC'

 

Here is my code managing this update:

<?php
	if(isset($_POST['savegroupchanges'])) {
		//$sql2 and $result2 determined if the user changed the title field or not.
		$groupname = $_POST['groupfield'];
		$sql = mysql_query("SELECT name FROM group WHERE name = '$groupname'") or die(mysql_error());
		$sql2 = mysql_query("SELECT name FROM group WHERE id = '$gid'") or die(mysql_error());
		$num = mysql_num_rows($sql);
		$result2 = mysql_fetch_array($sql2);
		if($result2['name'] != $groupname && $num > 0) {
			$statustext = "<p style=\"color:#ff0000;background-color:#fff;text-align:center;\">That name is already taken. Please choose another.</p>";
		} else {
			$sql = mysql_query("UPDATE group SET name = '$groupname' WHERE id = '$gid'") or die(mysql_error());
			$statustext = "<p style=\"color:#ffd530;background-color:#6F6161;text-align:center;\">Successfully updated.</p>";
		}			
	}
?>

 

$groupname is equal to a input text field in a form that is not shown in this code. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/99045-solved-cant-find-my-syntax-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.