Skip to content

Instantly share code, notes, and snippets.

@yunchih
Last active August 29, 2015 14:05
Show Gist options
  • Save yunchih/8608fd6d34a780ff20f1 to your computer and use it in GitHub Desktop.
Save yunchih/8608fd6d34a780ff20f1 to your computer and use it in GitHub Desktop.
<?php
$ok = false; //sign up 尚未成功
if(isset($_POST['email'])):
$email = $_POST['email']; // 從 post 中取出 email
$password = $_POST['password']; // 從 post 中取出 password
$confirmPassword = $_POST['confirmPassword']; // 從 post 中取出 confirmPassword
/*
* 任務:
* 確認 password 和 confirmPassword 是否相同
* 如果兩者不相同,echo 警訊
*/
if($password == $confirmPassword){ //如果相同
$ok = true; // sign up 成功
}
else{ //如果不相同
$ok = false; // sign up 失敗
echo "<span style='color:red'>密碼與確認密碼不符</span>"; //警訊:密碼與確認密碼不相符
/*
* 可寫成 echo "<span style='color:red'>在這裡插入你要的訊息</span>";
* 這樣這個訊息就變紅色滴
*
*/
}
endif;
if(!$ok): //如果 sign up 尚未成功
// if(!$ok) 亦可寫成 if($ok == false)
?>
<h1>Sign up</h1>
<form action="exercise.php" method="post">
<label>Email: </label>
<input type="email" name="email" required/> <!-- required 意思是:必填欄位 -->
<label>Password: </label>
<input type="password" name="password" required/>
<label>Type your password again:</label> <!-- 確認密碼 -->
<input type="password" name="confirmPassword" required/>
<input type="submit" value="Register!" />
</form>
<?php else: ?>
<h1>Sign up successfully!! Ya~~</h1>
<h3>Your email is: <?php echo $email; ?></h3> <!-- 把前面的 email 變數填進來喲 -->
<?php endif; ?>
<?php
$ok = false; //sign up 尚未成功
if(isset($_POST['email'])):
$email = ???; // 從 post 中取出 email
$password = ???; // 從 post 中取出 password
$confirmPassword = ???; // 從 post 中取出 confirmPassword
/*
* 任務:
* 確認 password 和 confirmPassword 是否相同
* 如果兩者不相同,echo 警訊
*/
if(???){ //如果相同
$ok = ???; // sign up 成功
}
else{ //如果不相同
$ok = ???; // sign up 失敗
echo "???"; //警訊:密碼與確認密碼不相符
/*
* 可寫成 echo "<span style='color:red'>在這裡插入你要的訊息</span>";
* 這樣這個訊息就變紅色滴
*
*/
}
endif;
if(!$ok): //如果 sign up 尚未成功
// if(!$ok) 亦可寫成 if($ok == false)
?>
<h1>Sign up</h1>
<form action="exercise.php" method="post">
<label>Email: </label>
<input type="email" name="email" required/> <!-- required 意思是:必填欄位 -->
<label>Password: </label>
<input type="password" name="password" required/>
<label>Type your password again:</label> <!-- 確認密碼 -->
<input type="password" name="confirmPassword" required/>
<input type="submit" value="Register!" />
</form>
<?php else: ?>
<h1>Sign up successfully!! Ya~~</h1>
<h3>Your email is: <?php echo ???; ?></h3> <!-- 把前面的 email 變數填進來喲 -->
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment