Please help a newbie

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am new to the world of PHP and MySQL. My objective is to create a
table, insert values in it and read it back.

Here's the partial code to create a table from a PHP file:

if (!$table_exists) {
        $query="CREATE TABLE contacts (id int(20) NOT NULL, name
varchar(15) NOT NULL, address varchar(15),PRIMARY KEY(id)
        if (mysql_query($query, $con)) echo "Table contacts created";
        else die('Unable to create table : '.mysql_error());
}


I input the values from a HTML form. Here is the partial code.
        $phone = $_POST['phone'];
        $name  = $_POST['name'];
        $address = $_POST['address'];
        $query = "INSERT INTO contacts VALUES ('$phone', '$name', '$address')";
        if (mysql_query($query, $con)) echo "Values inserted";
        else die('Unable to create table : '.mysql_error());


Now the problem that I am facing is that when I make my first insert,
the id field shows a garbage value and not the number that I entered.
Subsequent entries into the table show up just fine. It's only the
first one.

What am I doing wrong?

Thanks, Rij

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux