简体   繁体   English

PHP'PHP_SELF'的问题

[英]Problem with PHP 'PHP_SELF'

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. 似乎没什么大不了的,但是我创建了一个页面,用户可以编辑MySQL数据库。 Once they click submit it should process the php within the if statement and echo 1 record updated. 一旦他们单击提交,它将在if语句中处理php并回显更新的1条记录。 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. 似乎只是忽略了我编写if并显示整个页面的方式。 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>
if(isset($_POST['submit']));

1) Should not have a semicolon after it. 1)后面不能有分号。

2) $_POST['submit'] is not set. 2)未设置$_POST['submit'] You have to set a name on your submit button and give it a value. 您必须在“提交”按钮上设置一个名称,并为其提供一个值。 Just setting the type to 'submit' does not return a value for $_POST['submit'] in PHP. 仅将类型设置为'submit'不会在PHP中返回$_POST['submit']的值。

You've got a ; 你有一个; after your if statement. if语句之后。

I noticed that you have two submit buttons and I assume that you are using the first one. 我注意到您有两个提交按钮,并且我假设您正在使用第一个按钮。

Try giving it a name="submit" and a value too. 尝试给它一个name="submit"和一个值。

Of course it doesnt. 当然不是。 PHP runs in the server side, not in browser! PHP在服务器端运行,而不是在浏览器中运行! Open your page source. 打开页面源。 There is no PHP. 没有PHP。 Nothing to wait. 没什么可等的。 You need another page to send your form to. 您需要另一个页面将表单发送到。

And it is a big deal. 重要。 It's a cornestone of understanding how the web does work. 这是了解网络工作方式的基础。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM