[英]How can I use isset method in php for two different posts?,
<?php
session_start();
include_once'config/connect.php'; //database connection
if(isset($_POST['add'])) {
$add = mysql_query("UPDATE venue SET location='".$_POST['add']."'
WHERE vid = (select vid from user_venue where id = (select user_id from iangadot_user
where username='".$_SESSION['username_profile']."' ))");
}
if(isset($_POST['webb'])) {
$webb = mysql_query("UPDATE venue SET web='".$_POST['webb']."'
WHERE vid = (select vid from user_venue where id = (select user_id from iangadot_user
where username='".$_SESSION['username_profile']."' ))");
}
?>
Html file: HTML文件:
<!DOCTYPE html>
<html>
<body>
<form method="POST">
<p>Address:</p> <input class = "field" name="add" placeholder= "<?php
if(isset($_SESSION['address'])) { echo $_SESSION['address']; } ?>" type="text" >
<input class = "button" type = "submit" Value = "Save"><br>
<p>Website:</p> <input class = "field" name= "webb" placeholder = "<?php
if(isset($_SESSION['website'])) { echo $_SESSION['website']; } ?>" type="text">
</form>
</body>
</html>
A text input will always report a value in $_POST
, possibly an empty string. 文本输入将始终报告
$_POST
的值,可能为空字符串。
Conceptually, you allow the user to add both values, so it's up to you to prioritize one over the other or report an error in case both are filled. 从概念上讲,您允许用户将两个值相加,因此由您决定优先级高于另一个值或在两个值均被填充的情况下报告错误。
Now to detect automatically which one was filled, you could simply test the value of the $_POST
data. 现在,要自动检测填充了哪一个,您只需测试
$_POST
数据的值即可。
if ($_POST['add'] != "" && $_POST['web'] != "") {
error ("make up your mind!");
}
if ($_POST['add'] != "") { ....
if ($_POST['web'] != "") { ....
add 加
or die(mysql_error())
to the end of your query statements. 到查询语句的末尾。 Chances are one of the queries has a syntax error.
查询之一可能是语法错误。
Also, you really should be passing POST variables through at least mysql_real_escape_string() Rather than inserting directly into your database. 另外,您实际上应该至少通过mysql_real_escape_string()传递POST变量,而不是直接插入数据库中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.