PDA

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


MarkDakers
03-09-2007, 11:07 PM
Hi

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!

Code:


<?PHP
require_once("Connections/connection.php");
// 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);




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

<body>
<p>&nbsp;</p>


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


<table width="75%" border="1">
<tr>
<td>data1</td>
<td>data2</td>
<td>data3</td>
</tr>
<tr>
<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>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="submit" name="Submit" value="Submit">
<input name="submit" type="hidden" id="submit" value="1">
</div></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="75%" border="1">
<tr>
<td>ID_1</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
</tr>

<?php do { ?>


<tr>
<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>
</tr>

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

</table>

</body>
</html>



All help appreciated.

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

Mark

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

http://www.dreamweaverclub.com/forum/showthread.php?t=25153

give me a shout if you still have problems

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

$data2,$data3,$data4

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.