hmm... I understand what you mean... But still, there are lots of question in my mind... hmm, let's put it like this... I have a simple php scripts:
Code:
simple.php
<?php
include('dbconnect.php');
$name = $_POST[name];
$age = $_POST[age];
$data = "insert into simplerecord values(null,'$name','$age')";
mysql_query($data) or die(mysql_error());
?>
<html>
<head>
<title> simple form </title>
</head>
<body>
<form action="simple2.php" method="POST">
<p><strong>Name:</strong><br>
<input type="text" name="name"></p>
<p><strong>Age:</strong><br>
<input type="text" maxlength="2" name="age"></p>
<p><input type="submit" value="send"></p>
</form>
</body>
</html>
Code:
simple2.php
<?php
include('dbconnect.php');
$data = "select * from simplerecord";
$query = mysql_query($data);
$num = mysql_num_rows($query);
$x = 0;
while($x < $num)
{
$name = mysql_result($query,$x,"name");
$ID = mysql_result($query,$x,"ID");
$age = mysql_result($query,$x,"age");
printf("Name: %s<br>",$name);
printf("ID: %d<br>",$ID);
printf("Age: %d<br><br>",$age);
$x++;
}
?>
Code:
dbconnect.php
<?php
$con = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("db",$con);
?>
let's say, these 3 scripts create an application...These are the things that I found out.... First is the simple.php... In this script, when I didn't put a value on the action attribute, the process seems to be ok, I successfully added a record (simple2.php is not yet created)... so the form tag looks like this:
Code:
<form action="" method="POST">
When I created the simple2.php, the form tag in simple.php script looks like this:
Code:
<form action="simple2.php" method="POST">
But this time, when I test it through my browser(filling up the name and age) and checked my database, the record that I inserted become null in my database (the attributes name and age has no value in my database but the attribute ID has a value)... Why is that?
OUTPUT in browser when simple2.php was not yet created: // I put display code in the same page
Name: lourence john cabaluna
ID: 1
Age: 18
Attributes values in the database when simple2.php was not yet created:
ID = 1
name = lourence john cabaluna
age = 18
OUTPUT in browser when simple2.php was created:
Name: lourence john cabaluna
ID: 1
Age: 18
Name:
ID: 2
Age: 0
Attributes values in the database when simple2.php was created:
ID = 1
name = lourence john cabaluna
age = 18
ID = 2
name =
age = 0
Bookmarks