FW: [PHP-DB] Username

2002-02-05 Thread Tony James

Hi Jennifer

The table defines the uid field as not null.
CREATE TABLE users (
  uid int(10) unsigned NOT NULL auto_increment,
  name varchar(20) NOT NULL default '',
  password varchar(20) NOT NULL default '',
..


However you are trying to insert null into uid field

$query = INSERT INTO users (uid, name) VALUES(NULL, $name);
$result = mysql_query($query);


Since a primary key has to be not null try inserting an empty string instead
of NULL.

HTH

TJ.
-Original Message-
From: Jennifer Downey [mailto:[EMAIL PROTECTED]]
Sent: 05 February 2002 14:50
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Username


Hi,

It's me bothering you great helpers again! Wondering if you can help me?
I know I am missing something stupid cause I am taking this pretty much
straight out
of  the PHP 4 Bible.

Here is my table dump:


CREATE TABLE users (
  uid int(10) unsigned NOT NULL auto_increment,
  name varchar(20) NOT NULL default '',
  password varchar(20) NOT NULL default '',
  class tinyint(3) unsigned NOT NULL default '0',
  realname varchar(40) default NULL,
  email varchar(50) NOT NULL default '',
  sex enum('Male','Female') default NULL,
  session varchar(15) NOT NULL default '',
  dateregistered datetime NOT NULL default '-00-00 00:00:00',
  dateactivated datetime NOT NULL default '-00-00 00:00:00',
  lastvisit datetime NOT NULL default '-00-00 00:00:00',
  logins int(10) unsigned NOT NULL default '0',
  points int(11) NOT NULL default '1000',
  PRIMARY KEY  (uid),
  UNIQUE KEY name (name,email)
) TYPE=MyISAM;


Here is the php code:

?
// include the database configuration
includeconfig.php;
// connect to database
mysql_connect($db[host],$db[user],$db[password]);
mysql_select_db($db[database])  or die (sorry I couldn't connect to the
database.);

// if no connect then exit
// exit;

// if connect successful

?
!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN

html
head
titleUntitled/title
/head
body
?
?
if(!IsSet($stage))
  {
?

Please fill out the form below to get an account.
FORM METHOD=POST ACTION=te.php
Username:BRINPUT TYPE=TEXT NAME=name SIZE=15BR
input type=hidden name=stage value=1
INPUT TYPE=SUBMIT
/form
?
$query = INSERT INTO users (uid, name) VALUES(NULL, $name);
$result = mysql_query($query);
if($result == 0)
print(There has been a problem.);
else
print(Your information has been recorded.);
}
 ?
/body
/html

All I want is to get the username into the database.
As soon as test.php shows in browser, the Username, submit button and box ar
e there but also
it prints the There has been a problem. right off the bat. Now I know
there are misprints in the book
and I hope I was smart enough to catch them but maybe not. can someone
please tell me what I have
done wrong?

Thanks for all your time.

Jennifer Downey



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




FW: [PHP-DB] Username

2002-02-05 Thread Tony James


Hi again

The insert statement is incorrectly positioned within the if statement.

?
if(!IsSet($stage))
 {
?
Please fill out the form below to get an account.
FORM METHOD=POST ACTION=te.php
Username:BRINPUT TYPE=TEXT NAME=name SIZE=15BR
input type=hidden name=stage value=1
INPUT TYPE=SUBMIT
/form
?
$query = INSERT INTO users (uid, name) VALUES(NULL, $name);
$result = mysql_query($query);
if($result == 0)
print(There has been a problem.);
else
print(Your information has been recorded.);
}
 ?

should be

?
if(!IsSet($stage))
{
?
Please fill out the form below to get an account.
FORM METHOD=POST ACTION=te.php
Username:BRINPUT TYPE=TEXT NAME=name SIZE=15BR
input type=hidden name=stage value=1
INPUT TYPE=SUBMIT
/form
?
}
else
{
$query = INSERT INTO users (uid, name) VALUES(NULL, $name);
$result = mysql_query($query);
if($result == 0)
print(There has been a problem.);
else
print(Your information has been recorded.);
}

Again HTH
TJ
 ?




-Original Message-
From: Jennifer Downey [mailto:[EMAIL PROTECTED]]
Sent: 05 February 2002 14:50
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Username


Hi,

It's me bothering you great helpers again! Wondering if you can help me?
I know I am missing something stupid cause I am taking this pretty much
straight out
of  the PHP 4 Bible.

Here is my table dump:


CREATE TABLE users (
  uid int(10) unsigned NOT NULL auto_increment,
  name varchar(20) NOT NULL default '',
  password varchar(20) NOT NULL default '',
  class tinyint(3) unsigned NOT NULL default '0',
  realname varchar(40) default NULL,
  email varchar(50) NOT NULL default '',
  sex enum('Male','Female') default NULL,
  session varchar(15) NOT NULL default '',
  dateregistered datetime NOT NULL default '-00-00 00:00:00',
  dateactivated datetime NOT NULL default '-00-00 00:00:00',
  lastvisit datetime NOT NULL default '-00-00 00:00:00',
  logins int(10) unsigned NOT NULL default '0',
  points int(11) NOT NULL default '1000',
  PRIMARY KEY  (uid),
  UNIQUE KEY name (name,email)
) TYPE=MyISAM;


Here is the php code:

?
// include the database configuration
includeconfig.php;
// connect to database
mysql_connect($db[host],$db[user],$db[password]);
mysql_select_db($db[database])  or die (sorry I couldn't connect to the
database.);

// if no connect then exit
// exit;

// if connect successful

?
!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN

html
head
titleUntitled/title
/head
body
?
?
if(!IsSet($stage))
  {
?

Please fill out the form below to get an account.
FORM METHOD=POST ACTION=te.php
Username:BRINPUT TYPE=TEXT NAME=name SIZE=15BR
input type=hidden name=stage value=1
INPUT TYPE=SUBMIT
/form
?
$query = INSERT INTO users (uid, name) VALUES(NULL, $name);
$result = mysql_query($query);
if($result == 0)
print(There has been a problem.);
else
print(Your information has been recorded.);
}
 ?
/body
/html

All I want is to get the username into the database.
As soon as test.php shows in browser, the Username, submit button and box ar
e there but also
it prints the There has been a problem. right off the bat. Now I know
there are misprints in the book
and I hope I was smart enough to catch them but maybe not. can someone
please tell me what I have
done wrong?

Thanks for all your time.

Jennifer Downey



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php