Pregunta

I have two issets in one php file but it keeps on taking one of the posts only. So it is one or another! Here is the php part:

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

 <!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>
¿Fue útil?

Solución

A text input will always report a value in $_POST, possibly an empty string.

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.

if ($_POST['add'] != "" && $_POST['web'] != "") {
    error ("make up your mind!");
}
if ($_POST['add'] != "") { ....
if ($_POST['web'] != "") { ....

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top