Hi
I am new to MySQL/PHP. I wanted to see if I could set up a database table in an existing database and output the data into a web page. Everything works OK except that I cannot see the ID column. This is the primary key (auto_increment)
Here's the strange thing, I can see the ID 1,2,3,4,5 .. when I view the database table in phpMyAdmin. I just wanted to do it all in code and output it.
Can you explain why I cannot see the ID column ?? I have tried and tried. Below shows code bits for (1) creating the table (2) insering data (3) outputing data
Please note that the data is inserted from a form that uses a seperate php handler file.
Tthank you if you can help me please
// Create table in your database
mysql_select_db("pstwin-g", $con);
$sql = "CREATE TABLE person
(
personID int auto_increment primary key,
fname varchar(15),
sname varchar(15),
age int
)";
// Insert a row of information into the table "person"
mysql_query( "INSERT INTO person VALUES (' ' ,'$_POST[fname]','$_POST[sname]','$_POST[age]') " )
or die(mysql_error());
// store the record of the "PERSON" table into $row
echo "<table border='1 'bgcolor ='yellow' cellpadding = '5'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['personID'] . "</td>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['sname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
}
echo "</table>";
I am new to MySQL/PHP. I wanted to see if I could set up a database table in an existing database and output the data into a web page. Everything works OK except that I cannot see the ID column. This is the primary key (auto_increment)
Here's the strange thing, I can see the ID 1,2,3,4,5 .. when I view the database table in phpMyAdmin. I just wanted to do it all in code and output it.
Can you explain why I cannot see the ID column ?? I have tried and tried. Below shows code bits for (1) creating the table (2) insering data (3) outputing data
Please note that the data is inserted from a form that uses a seperate php handler file.
Tthank you if you can help me please
// Create table in your database
mysql_select_db("pstwin-g", $con);
$sql = "CREATE TABLE person
(
personID int auto_increment primary key,
fname varchar(15),
sname varchar(15),
age int
)";
// Insert a row of information into the table "person"
mysql_query( "INSERT INTO person VALUES (' ' ,'$_POST[fname]','$_POST[sname]','$_POST[age]') " )
or die(mysql_error());
// store the record of the "PERSON" table into $row
echo "<table border='1 'bgcolor ='yellow' cellpadding = '5'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['personID'] . "</td>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['sname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
}
echo "</table>";