Hi,
I'm trying to connect to a database using MySQL. Very new at this.
I already have an existing table consisting of 2 rows created using phpMyAdmin.
The problem (not exactly) I'm facing is when i insert a new row, it seems to insert after the 2nd row, not at the bottom.
By right, i should have:
1
2
3
4
5
but i get:
1
2 < -- seems to insert after this.
5
4
3
Although I can sort the table, i just want to know why this is happening.
Here's the code:
$link = mysql_connect('localhost', '', '');
$db_list = mysql_list_dbs($link);
mysql_select_db('test');
$result = mysql_query('SELECT * FROM myTable);
if(isset($_POST['submit']) && $_POST["submit"] == "Insert"){
$rowCount = mysql_num_rows($result)+1;
$sql = "Insert into myTable (id, Name, Gender, Age, Year)
values ($rowCount, 'John', 'Male', 12, 1999)";
mysql_query($sql);
header("location:data.php");
}
echo printResult($result);
mysql_free_result($result);
mysql_close($link);
Thanks.