我正在php中开发登录系统。当我在注册表格中输入详细信息并单击注册按钮时,我有一个名为signup1.php
的注册文件它以空白屏幕显示相同的文件CCD_ 2。
我想在注册用户时重定向myprofile.php
。我放了这个代码。
$user->redirect('myprofile.php');
注释中的代码:
<?php
require_once 'dbconfig.php';
if($user->is_loggedin()!="") {
$user->redirect('myprofile.php');
}
if(isset($_POST['btn-signup'])) {
else{
try {
$stmt = $DB_con->prepare("SELECT name,email FROM customer WHERE email=:umail");
$stmt->execute(array(':umail'=>$umail));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($row['email']==$umail) {
$error[] = "sorry email id already taken !";
} else {
if($user->register($fname,$lname,$uname,$umail,$uphone,$upass)) {
$user->redirect('myprofile.php');
}
}
} catch(PDOException $e) {
echo $e->getMessage();
}
}
}
?>
重定向功能:
class User {
public function redirect($url) {
header("Location: $url");
}
}
从您提供的少量信息中,我可以看到一个问题。此:
if(isset($_POST['btn-signup'])) {
else{
}
}
不起作用,它会抛出这个错误:
PHP分析错误:语法错误,意外的'else'(T_else(
if子句的工作原理如下:
if( $condition ) {
// do something if $condition is TRUE
}
else{
// do something else if $condition is FALSE
}
如果我正确理解了你的代码,你应该删除else {
行及其相应的右括号。
常见注意事项:如果您在PHP中遇到死亡的白色屏幕,并且没有任何错误消息,则通常会禁用错误报告(在生产环境中这是正常的(。你可以用以下线路激活它:
ini_set('display_errors',true);
error_reporting(E_ALL);
或者,您可以查看web服务器的错误日志(如果您的宿主提供了一个,则不是所有宿主都提供(。