PDA

View Full Version : PHP, a beginners guide, part 9.


-fedexer-
11-18-2007, 09:40 PM
I have followed the tutorial completely through, but when i hit submit, instead of returning to itself the page seems to go to the main directory, whilst displaying a 404 error. Im sure i have done everything correctly, and i have checked it and i cant seem to find anything wrong, could someone take a look and see if i have overlooked something.

<?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) {
//checking that the table has been populated (data entered) when submit is pressed
////////////////////////////////////
$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);
////////////////////////////////////////////////
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dwc.php</title>
<style type="text/css">
<!--
.style1 {font-size: 24px}
#apDiv1 {
position:absolute;
left:357px;
top:217px;
width:355px;
height:107px;
z-index:1;
}
#apDiv2 {
position:absolute;
left:240px;
top:56px;
width:907px;
height:98px;
z-index:2;
}
#apDiv3 {
position:absolute;
left:388px;
top:60px;
width:497px;
height:118px;
z-index:2;
}
-->
</style>
</head>
<body>
<div id="apDiv1">
<table width="569" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>ID</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>
</div>
<form id="form1" name="form1" method="post" action=" <?php $_SERVER['PHP_SELF']; ?> ">
<table width="389" border="1" cellpadding="0" cellspacing="0" id="apDiv2">
<tr>
<td width="145">data2</td>
<td width="122">data3</td>
<td width="114">data4</td>
</tr>
<tr>
<td height="25"><label>
<input type="text" name="data2" id="data2" />
</label></td>
<td><label>
<input type="text" name="data3" id="data3" />
</label></td>
<td><label>
<input type="text" name="data4" id="data4" />
</label></td>
</tr>
<tr>
<td colspan="3"><label>
<div align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
</div>
</label></td>
</tr>
</table>
</form>
</body>
</html>


Thanks
-fedexer-

-fedexer-
11-18-2007, 10:11 PM
Note: this works in FF but not any other browsers. (dont know why)

davidj
11-19-2007, 08:42 AM
try replacing...

<?php $_SERVER['PHP_SELF']; ?>

with the page name


my_page.php

-fedexer-
11-19-2007, 03:45 PM
Intrequing, that fixed my problem david ;)

Only problem that still resides , is that if i try to view the page using Yahoo Browser (my default browser) it asks me if i want :

Warning: the web page which you are about to visit may attempt to request your personal information (such as passwords, credit card numbers and social security numbers) for unauthorized use or may otherwise attempt to harm your computer.
Malicious web sites can use this type of address in order to disguise themselves. The destination may appear to be:
%22http
but the actual destination is:
%22http

i click yes to continue, but then my browser just closes.... is this because im viewing it on my machine and it would work on the net?

or is it something else that is possibly causing this problem

(i want to make sure all browsers are compatable)

Thanks

-fedexer-

davidj
11-19-2007, 03:59 PM
try the site in IE or fire fox

-fedexer-
11-19-2007, 04:01 PM
works fine in IE and FF , just not yahoo Browser for some reason, it throws that warning message as it attempts to open it , then you click yes, it looks like its loading and then it just closes.

davidj
11-19-2007, 04:03 PM
sounds like a dodgy install

or the security settings are too strict

use a proper browser like FF

-fedexer-
11-19-2007, 04:04 PM
haha sure thing ;) ill just use FF / IE for testing, (i have IE set as default for testing anyway)

Thanks alot david ;)

Now i can get on with the other VTMs after i finish my homework 8-)

-fedexer-