1 Replies - 112 Views - Last Post: 24 December 2017 - 10:36 AM Rate Topic: -----

#1 [email protected]  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 57
  • Joined: 24-February 15

SQL syntax error

Posted 24 December 2017 - 10:32 AM

I have an error in my php code but I don't really understand what I should look for, it is at line 5 but I can't see the problem.
Maybe someone can check my code?

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 ')' at line 5

<?php
	// Database info
	$host = 'localhost';
	$user = 'xxxxx';
	$pass = 'xxxxx';
	$database = 'db75076';
	
	// Database connection
	$conn = mysqli_connect($host, $user, $pass, $database);
	
	// Check connection
	if(!$conn){
		die('Connection failed: '  . mysqli_error());
	} else {
		echo 'Connection succesfully';
	}

	// Create query
	$result = "CREATE TABLE Students (
		ID INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
		Firstname VARCHAR(30) NOT NULL,
		Lastname VARCHAR(30) NOT NULL,
		 )";

	echo "<br>";

	// Check query
	if(mysqli_query($conn, $result)) {
		echo "Student table created succesfully";
	} else {
		echo "Couldn't create table: " . mysqli_error($conn);
	}

	// Quit connection
	mysqli_close($conn);

?>



Is This A Good Question/Topic? 0
  • +

Replies To: SQL syntax error

#2 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 652
  • View blog
  • Posts: 2,704
  • Joined: 13-June 14

Re: SQL syntax error

Posted 24 December 2017 - 10:36 AM

I would guess that the trailing comma on line 22 is the problem.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1