View Full Version : $_SERVER[PHP_SELF] debug needed please

03-09-2007, 11:07 PM

I'm following the PHP tutorials. I'm a bit stuck on Tutorial 10. Everything works until I hit submit, then I just get Error 404 Page not found! Everything up to this pointbworks fine. Bet it's easy to spot from "outside" but I'm failing!


// database connection //

$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
$data4 = $_POST['data4'];
$submit = $_POST['submit'];

if ($submit && $data2 && $data3 && $data4) {

$query = sprintf("INSERT into table1 (field2, field3, field4) VALUES ('$data2', '$data3', '$data4')");
mysql_query($query)or die (mysql_error());

}elseif($submit) {
echo "One of your fields is empty!";

$query = sprintf("SELECT * FROM table1");
$result = mysql_query($query);
$row = mysql_fetch_array($result);

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<form id="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?> ">

<table width="75%" border="1">
<td><input name="data1" type="text" id="data1"></td>
<td><input name="data2" type="text" id="data2"></td>
<td><input name="data3" type="text" id="data3"></td>
<td colspan="3"><div align="center">
<input type="submit" name="Submit" value="Submit">
<input name="submit" type="hidden" id="submit" value="1">
<table width="75%" border="1">

<?php do { ?>

<td><?php echo $row["field1_id"];?></td>
<td><?php echo $row["field2"];?></td>
<td><?php echo $row["field3"];?></td>
<td><?php echo $row["field4"];?></td>

<?php } while ($row = mysql_fetch_array($result)); ?>



All help appreciated.

If anyone has a set of finished code - I'd love to see it.


03-10-2007, 04:18 PM
you'll find a working example in this thread


give me a shout if you still have problems

03-10-2007, 05:05 PM
I have miss-labelled variables / form object ids.


then in the form I numbered data1, data2 and data3

There was also a closing chevron.

I'm really chuffed with my progress; a huge thanks to the forum, especially dj, marvellous stuff.