Jump to content

[SOLVED] Mysql Error


joeysarsenal

Recommended Posts

I seem to be getting this error. When trying to create a table and cant seem to find were i went wrong.

Code im using is

<?php		/* create the Staff Table  */

$host = "localhost";
$user = "root";
$pass = "";

//    include( "../some/wierd/folder/details.inc" );

$Connect = @mysql_connect($host, $user, $pass);

if(!$Connect){
  echo('<p>Unable to connect to the' .
       ' database server at this time.</p>');
  exit();
}


mysql_select_db("plaincart");

$sql = "CREATE TABLE clients(" .
	  "member_id int(4) NOT NULL AUTO_INCREMENT PRIMARY KEY," .
	  "firsname varchar(100) NOT NULL," .
	  "lastname varchar(100) NOT NULL," .
	  "email varchar(100) NOT NULL ," .
	  "city varchar(100) NOT NULL,".
	  "address varchar(100) NOT NULL," .
	  "postcode varchar(4) ," .
	  "login varchar(100) NOT NULL default,".
	  "passwd varchar(32) NOT NULL );";
	  
echo "SQL is " . $sql . "<br />";

if(mysql_query($sql)){
  echo("<p>client table successfully created!</p>");	
}
else{
  print("<p>Error creating clients table: " . mysql_error() . "</p>");	
}
?>

Error creating client table: 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 'passwd varchar(32) NOT NULL )' at line 1

Link to comment
https://forums.phpfreaks.com/topic/73403-solved-mysql-error/
Share on other sites

You dont state any default value for login. Either remove the default keyword, or define a default.

 

"CREATE TABLE clients(" .
	  "member_id int(4) NOT NULL AUTO_INCREMENT PRIMARY KEY," .
	  "firsname varchar(100) NOT NULL," .
	  "lastname varchar(100) NOT NULL," .
	  "email varchar(100) NOT NULL ," .
	  "city varchar(100) NOT NULL,".
	  "address varchar(100) NOT NULL," .
	  "postcode varchar(4) ," .
	  "login varchar(100) NOT NULL default 'foo',".
	  "passwd varchar(32) NOT NULL );";

Link to comment
https://forums.phpfreaks.com/topic/73403-solved-mysql-error/#findComment-370328
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.