Problem with PHP 'PHP_SELF'

Posted by shinjuo on Stack Overflow See other posts from Stack Overflow or by shinjuo
Published on 2010-03-25T18:41:04Z Indexed on 2010/03/25 18:43 UTC
Read the original article Hit count: 359

Filed under:
|

I am having a bit of trouble. It does not seem to be a big deal, but I have created a page that the user can edit a MySQL database. Once they click submit it should process the php within the if statement and echo 1 record updated. The problem is that it does not wait to echo the statement. It just seems to ignore the way I wrote my if and display the whole page. Can anyone see where I went wrong.

<!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></title>
</head>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php require("serverInfo.php"); ?>
<?php
    $res = mysql_query("SELECT * FROM cardLists order by cardID") or die(mysql_error()); 
    echo "<select name = 'Cards'>"; 
    while($row=mysql_fetch_assoc($res)) { 
        echo "<option value=\"$row[cardID]\">$row[cardID]</option>"; 
    } 
    echo "</select>";
?>
Amount to Add: <input type="text" name="Add" />
<input type="submit" />
</form>

<?php
if(isset($_POST['submit']));
{
    require("serverInfo.php");
mysql_query("UPDATE `cardLists` SET `AmountLeft` = `AmountLeft` + ".mysql_real_escape_string($_POST['Add'])." WHERE `cardID` = '".mysql_real_escape_string($_POST['Cards'])."'");
 mysql_close($link);
 echo "1 record Updated";
}
?>
<br />
<a href="index.php"> <input type="submit" name="main" id="main" value="Return To Main" /></a>
</body>
</html>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql