mercredi 8 avril 2015

Using variable, outside if statement

I have a problem, with a variable that's declared inside an if statement, and i can't use that variable inside another if statement.


This is the first if statement.



if(isset($_POST['submit']))
{
$name = $_POST['name'];

sleep(1);
echo "some text";

?>


This is the second if statement. And this is the one, where i want to use the $name variable



<?php
exit();
}
if(isset($_POST['submit1']))
{

echo $name;
sleep(1);
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$email = $_POST['email'];


$userq = "INSERT INTO game_user (name, email, password) VALUES ('$name', '$email', '$pass1')";
$result = mysqli_query($mysqli,$userq);

}
?>


Any help is appreciated :)


EDIT: Here's the full code as requested :)



<?php
$name = '';
if(isset($_POST['submit']))
{
$name = $_POST['name'];

sleep(1);
echo "Vi mangler lige lidt mere information, før $name kommer på vingerne";

?>

<script>
$(document).ready(function(){

document.getElementById("newbox").style.height = "600px";
$("input").show();
$("sweg").show();


});
</script>
<form method="post">

<input name="pass1" type="password" class="feedback-tand" placeholder="Password" /><br/><br/>
<input name="pass2" type="password" class="feedback-tand" placeholder="Gentag password" /><br/><br/>
<input name="email" type="text" class="feedback-tand" placeholder="Email" /><br/><br/>

<input name="submit1" type="submit" value="OPRET!" id="submit1"/>


</form>
<?php

exit();
}
if(isset($_POST['submit1']))
{

echo $name;
sleep(1);
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$email = $_POST['email'];


$userq = "INSERT INTO game_user (firma, email, password) VALUES ('$name', '$email', '$pass1')";
$result = mysqli_query($mysqli,$userq);






}
?>




<form method="post">

<div class="newcomp">
<input name="name" type="text" class="feedback-tand" placeholder="Airline navn (Dette kan ikke skiftes senere!)" id="tidsrum" />
</div>

<input name="submit" type="submit" value="OPRET!" />


</form>


Also note this code is purely for experimenting.


Aucun commentaire:

Enregistrer un commentaire