lundi 20 juin 2016

if else inside of $_post isset

I have a form that is filled out by a sports coach. A coach can have multiple sports they coach and a player can play multiple sports. So if a coach wants to add a player to a team roster I need to check if the player exists and if so then just add the player id to the roster table and not add the player again to the players table. Below is the best representation of what I am trying to accomplish.

if (isset($_POST['submit'])) {

$email = mysqli_real_escape_string($con2, $_POST['email']);

$sql1 = "SELECT id, email FROM users WHERE email='$email'";
$result = $con2->query($sql1);


if ($result->num_rows > 0) {

//here is where I want to just add specific information


} //I have tried if $result == 0 and else if $result == 0


//here is where I would add the user if the email doesn't exist.

}  <-- //I feel like the issue is the if (isset($_POST['submit'])) which end just before this line. 

So I get mixed results based on where I place the end of the (isset($_POST['submit'])). I am trying to figure out how to retain the $_POST being set but not execute everything within in. I am pretty knew to this so please forgive me if I my question seems basic. Thanks for taking the time to review my question.

Aucun commentaire:

Enregistrer un commentaire