SQL in php
Posted by: wilfred_phang (---.60.in-addr.arpa.tm.net.my)
Date: February 10, 2009 02:03PM

Hi, i would like to ask why the database is not successfully created when i'm using AUTO_INCREMENT in for the primary key? Below is my code:

<?php
$con = mysql_connect("localhost","root",""winking smiley;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
/*
// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
*/
// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE People
(
P_ID varchar(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(P_ID),
P_Name varchar(20),
P_Pswd varchar(20),
)";

// Execute query
mysql_query($sql,$con);

mysql_close($connect);
?>

Please help me to solve this problem. Thanks!

Options: ReplyQuote
Re: SQL in php
Posted by: yfastud (Moderator)
Date: February 10, 2009 05:39PM

Quote

P_ID varchar(10) NOT NULL AUTO_INCREMENT,
auto increase when set w/ number, not varchar :-(

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote


Sorry, only registered users may post in this forum.