Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.