So Im still beginning to learn php and Im trying to make this code upload two items,name and age. to my database "NK" to table "players" and then display all entries in players. But whenever I hit submit, Page reloads to show the Php code and doesn't execute.
<html>
<body>
<form action="db.php" method="post">
Name: <input type="text" name="name">
Age:<input type="text" name="age">
<input type="submit">
</form>
</body>
</html>
and this is my db.php file
<?php
mysql_connect("localhost","noha","noha");
@mysql_select_db(NK) or die( "Unable to select database");
$name=$_POST['name'];
$age=$_POST['age'];
$result=mysql_query("SELECT * FROM Players");
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
$age=mysql_result($result,$i,"age");
echo "<b>$name $age</b><br>";
$i++;
}
mysql_close();
?>
I'm not sure what are you meaning and I'm guessing. The page reloads and show the Php code , then your php client is not set up yet. Have you checked that your mysql and apache server is running?
A good way is to
echo 'something';
mysql_connect("localhost","noha","noha");
and see whether the code execute
by the way $num=mysql_numrows($result); is $num=mysql_num_rows($result);
so you have server online, maybe you should check your mysql_select_db syntax
and try to use mysqli since mysql is deprecated