Running a SQL query from the following code:

<php
if(sizeof($_POST['addcandidate'])){
		foreach($_POST['addcandidate'] as $id){
		$name= mysql_query("SELECT LastName FROM candidate WHERE Candidate_ID= '$id'");
		while($rowz= mysql_fetch_assoc($name)){
		$candidatename= $rowz['LastName'];
		$alter= "ALTER TABLE '$votertable' ADD '$candidatename' int";
		mysql_query($alter) or die(mysql_error());
		}
		}	
	}
?>

I return Im getting:
#1064 - 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 ''SuperHeros_Votes' ADD 'Butters' int' at line 1

I thought originally it might have been an issue unknown to me since its coming from an array, however, I copied and paste:

ALTER TABLE 'SuperHeros_Votes' ADD 'Butters' int

into phpMyAdmin and got the same result.

seems alter doesn't like quotes around variables

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.