Trenger SQL Syntaks hjelp!

typisk

Utvikler
Nei, begrensingen er på mysql_query();

Dette er ikke lov (som du prøver på):
PHP:
mysql_query("{$sql1}; {$sql2}; ...");
Pga sikkerhet (folk kunne lagt til f.eks ;DROP TABLES xxx) er dette kun lov:
PHP:
mysql_query($sql1);
mysql_query($sql2);
 

adeneo

Medlem
Jeg er ikke spesielt god på SQL, men det ser ut som en særdeles dårlig ide å putte alt i en string og så kjøre hele dritten, du må nok begrense deg til en query om gangen.

Du har selvfølgelig koblet til en database (mysql_select_db($database)) osv...

Du trenger vel heller ikke backticks på tabellnavnet, prøv:

PHP:
$query = "CREATE TABLE Administrators (
  `AdminID`      INTEGER(11) UNSIGNED AUTO_INCREMENT,
  `FirstName`    VARCHAR(50) NOT NULL,  
  `LastName`     VARCHAR(50) NOT NULL,  
  `Username`     VARCHAR(50) NOT NULL,  
  `Password`     VARCHAR(50) NOT NULL,  

  PRIMARY KEY (`AdminID`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
 
Sist redigert:

Cisse

Medlem
Forsatt feil her.

Hele koden:

PHP:
<?php

	require_once "../Connect.php"; /*MySQL configuration and connect*/
	
	if(IsSet($_POST['install'])) {
	
		$query1 = "DROP TABLE IF EXISTS `Administrators`;
				  CREATE TABLE `Administrators` (
				  `AdminID` int(11) NOT NULL AUTO_INCREMENT ,
				  `FirstName` varchar (50) NOT NULL,
				  `LastName` varchar (50) NOT NULL,
				  `Username` varchar (50) NOT NULL,
				  `Password` varchar (50) NOT NULL,
				  PRIMARY KEY (`AdminID`)
				) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
				
				$result1 = mysql_query($query1) or die (mysql_error());
				
		$query2 =  "DROP TABLE IF EXISTS `Posts`;
					CREATE TABLE `Posts` (
					`PostID` int(11) NOT NULL AUTO_INCREMENT,
					`Title` varchar (100) NOT NULL,
					`Intro` text NOT NULL,
					`Body` text NOT NULL,
					`Date` varchar (100) NOT NULL,
					`Writer` int (11) NOT NULL,
					`PictureID` int (11) NOT NULL,
				   PRIMARY KEY (`PostID`)
				 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
				 
				 $result2 = mysql_query($query2) or die(mysql_error());
				 
		$query3 = "DROP TABLE IF EXISTS `Pictures`;
					CREATE TABLE `Pictures` (
					`PictureID` int(11) NOT NULL AUTO_INCREMENT,
					`Picture` varchar (100) NOT NULL,
					`Path` varchar (500) NOT NULL,
					`Height` varchar (100) NOT NULL,
					`Widht` varchar (100) NOT NULL,
				   PRIMARY KEY (`PictureID`)
				 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
				 
				 $result3 = mysql_query($query3) or die(mysql_error());
				 
		$query4 = "DROP TABLE IF EXISTS `Videos`;
					CREATE TABLE `Videos` (
					`VideoID` int(11) NOT NULL AUTO_INCREMENT,
					`Video` varchar (100) NOT NULL,
					`Path` varchar (500) NOT NULL,
					`Lenght` varchar (100) NOT NULL,
				   PRIMARY KEY (`VideoID`)
				 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
				 
				 $result4 = mysql_query($query4) or die(mysql_error());
				 
		$query5 = "DROP TABLE IF EXISTS `Guests`;
					CREATE TABLE `Guests` (
					`GuestID` int(11) NOT NULL AUTO_INCREMENT,
					`Name` varchar (100) NOT NULL,
					`Age` varchar (100) NOT NULL,
					`Bloglink` varchar (100) NOT NULL,
					`Password` varchar (100) NOT NULL,
				   PRIMARY KEY (`GuestID`)
				 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
				 
				 $result5 = mysql_query($query5) or die(mysql_error());
				 
		$query6 = "DROP TABLE IF EXISTS `Comments`;
					CREATE TABLE `Comments` (
					`CommentID` int(11) NOT NULL AUTO_INCREMENT,
					`GuestID` int(11) NOT NULL,
					`Title` varchar (100) NOT NULL,
					`Comment` text NOT NULL,
					`Date` varchar (100) NOT NULL,
					`Bloglink` varchar (100) NOT NULL,
				   PRIMARY KEY (`CommentID`)
				 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
				 
				 $result6 = mysql_query($query6) or die(mysql_error());

	}
	
	if ( empty($result1)) {
		
		echo "<b>An error ocurred with query 1! Please try again!<br>";
	
	}
	
	if ( empty($result2)) {
		
		echo "<b>An error ocurred with query 2! Please try again!<br>";
	
	} 
	
	if ( empty($result3)) {
		
		echo "<b>An error ocurred with query 3! Please try again!<br>";
	
	}
	
	if ( empty($result4)) {
		
		echo "<b>An error ocurred with query 4! Please try again!<br>";
	
	}
	
	if ( empty($result5)) {
		
		echo "<b>An error ocurred with query 5! Please try again!<br>";
	
	}
	
	if ( empty($result6)) {
		
		echo "<b>An error ocurred with query 6! Please try again!<br>";
	
	}  else {
	
		echo "<h1>PostON is installed on your webserver!!!</h1><br><a href='../admin/Index.php'>Go to the admin Login!</a>";
		
	}
	
?>

Feilen:

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 'CREATE TABLE `Administrators` ( `AdminID` int(11) NOT NULL AUTO_INCREMENT' at line 2
 
Topp