Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2006, 03:51 AM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to PeterJB
Default Where are the answers (authers!!!!!!)

I've been wrestling with this problem for a few weeks and since i'm trying to learn using the book "Beginning php5", it would be nice if someone involved (Auther) could help me fix this problem.

One of the problems i'm having is with the creating of the database script in the book.

The script is this one:-

<?php
include "./common_db.inc";

$dbname = "testsample_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);"))
                                                      die(sql_error());

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.";


The problem is with the line:-

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

Why does it not work....?????

I get an error message saying:-

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

Please can one of the Authers explain what the problem is or direct me to where i can find the answer.

Thank you.

Dislexics have more fnu
 
Old August 29th, 2006, 11:58 PM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You quoted the default of 0 (zero) on an integer field. Remove the quotes and try again. The database is trying to assign the varchar '0' to an integer field.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Contradictory answers Fitz SQL Server 2000 1 June 22nd, 2006 08:14 PM
i need answers ???????? saudyonline ADO.NET 2 October 9th, 2004 11:47 AM
Answers dcoleman31p Forum and Wrox.com Feedback 5 November 12th, 2003 12:23 AM





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