简体   繁体   English

如何在php中为两个不同的帖子使用isset方法?,

[英]How can I use isset method in php for two different posts?,

I have two issets in one php file but it keeps on taking one of the posts only. 我在一个php文件中有两个isset,但是它只保留其中一个帖子。 So it is one or another! 所以是一个或另一个! Here is the php part: 这是php部分:

<?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.

相关问题 除了empty()之外,我如何使用PHP的isset()? - How can I use PHP's isset() in addition to empty()? 如何存储从 isset($_GET['Something']) 获得的值以在 .php 页面中重复使用 - How can I store the value I get from the isset($_GET['Something']) for repeated use within the .php page 我可以在PHP中使用两个构造函数方法吗? - Can I use two constructor method in PHP? 我可以在PHP中缩短isset()和==吗? - Can I shorten isset() and == in PHP? 如何使用php isset一个函数? - How to use php isset with a function? PHP-如何正确使用“ if(isset()&amp;&amp;!= NULL)|| (isset()&amp;&amp;!= NULL)”语句? - PHP - How do I correctly use a “if(isset() && != NULL) || (isset() && != NULL)” statement? isset或!isset用于php或其他用法 - isset or !isset for php or different usuage PHP - 当我在isset()中使用$ this作为动态变量时,为什么不同版本的PHP会返回不同的结果? - PHP - Why do different versions of PHP return different results when I use $this as a dynamic variable in isset()? 如何获得插入查询以与两个if(isset语句一起使用? - How can I get insert query to work with two if(isset statements? PHP-如何在ifset条件中嵌套while循环? - PHP - How can I nest a while loop inside an if isset condition?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM