Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 6th, 2005, 01:27 PM
Registered User
Join Date: Feb 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP Database Connectivity Problem

I am using Beginning PHP4, chapter 11. I have created create_db.php and run it. I then get the following message:

Successfully created the sample_db database.
1067: Invalid default value for 'usernumber'

and the table "User" has not been created.

I have used the following code:

include "./common_db.inc";

$dbname = "sample_db";
$user_tablename = "user;
$user_table_def = "usernumber MEDIUMINT(10) DEFAULT '0' NOT NULL AUTO_INCREMENT,";
$user_table_def .= "userid VARCHAR(8) BINARY NOT NULL,";
$user_table_def .= "userpassword VARCHAR(20) BINARY NOT NULL,";
$user_table_def .= "username VARCHAR(30) NOT NULL,";
$user_table_def .= "usercountry VARCHAR(50) NOT NULL,";
$user_table_def .= "useremail VARCHAR(50) NOT NULL,";
$user_table_def .= "userprofile TEXT NOT NULL,";
$user_table_def .= "registerdate DATE DEFAULT '0000-00-00' NOT NULL,";
$user_table_def .= "lastaccesstime TIMESTAMP(14),";
$user_table_def .= "PRIMARY KEY (userid),";
$user_table_def .= "UNIQUE usernumber (usernumber)";

$access_log_tablename = "access_log";
$access_log_table_def = "page VARCHAR(250) NOT NULL,";
$access_log_table_def .= "userid VARCHAR(8) BINARY NOT NULL,";
$access_log_table_def .= "visitcount MEDIUMINT(5) DEFAULT '0' NOT NULL,";
$access_log_table_def .= "accessdate TIMESTAMP(14),KEY page (page),";
$access_log_table_def .= "PRIMARY KEY (userid, page)";

$link_id = db_connect();
if(!$link_id) die(sql_error());

if(!mysql_query("CREATE DATABASE $dbname")) die(sql_error());

echo "Successfully created the $dbname database.<BR>";

if(!mysql_select_db($dbname)) die(sql_error());

if(!mysql_query("CREATE TABLE $user_tablename ($user_table_def)"))

if(!mysql_query("CREATE TABLE $access_log_tablename ($access_log_table_def)")) die(sql_error());

echo "Successfully created the $user_tablename and $access_log_tablename tables.";


Any help would be appreciated.


Reply With Quote
  #2 (permalink)  
Old February 6th, 2005, 01:36 PM
Authorized User
Join Date: Jan 2005
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts

You can't have usernumber be unique and at the same time have a default value of 0.

Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
Reply With Quote
  #3 (permalink)  
Old July 6th, 2006, 09:47 AM
Registered User
Join Date: Jul 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

FYI: I believe this is an error in the manual. This line of code is included in the manual and downloaded code

$user_table_def = "usernumber MEDIUMINT(10) DEFAULT '0' NOT NULL AUTO_INCREMENT,";

and the usernumber is shown as unique: $user_table_def .= "UNIQUE usernumber (usernumber)";

Reply With Quote
  #4 (permalink)  
Old July 18th, 2006, 07:51 AM
Registered User
Join Date: Jul 2006
Location: Houston, TX, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mustafaali Send a message via Yahoo to mustafaali

If u are using auto_increment option so there is no need of specifying the Default, becuase auto_increment by defualt generates the series of Number like 1,2,3,4,5..... after new row is inserted


Best Regards
Mustafa Ali
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Connectivity cnkumar74 VB Databases Basics 13 May 23rd, 2007 10:26 AM
Database Connectivity asearle XSLT 4 October 16th, 2006 06:41 AM
Database Connectivity pageturner71 Access 1 September 8th, 2004 05:13 AM

All times are GMT -4. The time now is 10:24 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.