2016-08-15 13 views
0

私はtest1.phpに入力フォームを持っており、ユーザー入力がデータベースに存在しない場合、 test2.phpに進み、test2.phpにユーザ入力をエコーし​​ます。それ以外の場合は、test1.phpに戻ってリダイレクトし、使用できません。どのように私はdbとクローズ接続のユーザー入力を確認して、次のページの入力をエコーすることができます

入力がsqlに存在する場合は前のページにリダイレクトできますが、接続を閉じた後にtest2.phpでユーザー入力をエコーすることができません。ここで

はここtest1.php

<!doctype HTML> 
<html> 
<head> 
</head> 
<?php 
if(isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0) { 
    echo '<ul class="err">'; 
    foreach($_SESSION['ERRMSG_ARR'] as $msg) { 
     echo '<li>',$msg,'</li>'; 
    } 
    echo '</ul>'; 
    unset($_SESSION['ERRMSG_ARR']); 
} 
?> 
<form id="loginForm" name="loginForm" method="post" action="test-exec.php"> 
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> 
<tr> 
<th>Email </th> 
<td><input name="box" type="text" class="textfield" id="box" /></td> 
</tr> 
<td><input type="submit" name="Submit" value="Check" /></td> 
</tr> 
</table> 
</form> 

でテストexec.php

<?php 
session_start(); 

require_once('db/config.php'); 

$errmsg_arr = array(); 

$errflag = false; 

    $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE); 
if(!$con) { 
    die('Failed to connect to server: ' . mysqli_connect_error()); 
} 

$db = mysqli_select_db($con, DB_DATABASE); 
if(!$db) { 
    die("Unable to select database"); 
} 

$box = mysqli_real_escape_string($con, $_POST['box']); 

if($box != '') { 
    $qry = "SELECT * FROM members WHERE box='$box'"; 
    $result = mysqli_query($con,$qry); 
    if($result) { 
     if(mysqli_num_rows($result) > 0) { 
      $errmsg_arr[] = 'Box already in use'; 
      $errflag = true; 
     } 
     @mysql_free_result($result); 
    } 
    else { 
     die("Query failed"); 
    } 
} 

if($errflag) { 
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr; 
    session_write_close(); 
    header("location: test1.php"); 
    exit(); 
}else { 
    header("location: test2.php"); 
    exit(); 

mysqli_close($con); 

} 
?> 

そして、ここではtest2.php

<!doctype HTML> 
<html> 
<head> 
</head> 

<form id="loginForm" name="loginForm" method="post" action="register.php"> 
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> 
<tr> 
<th>Email </th> 
<td><input name="box" type="text" class="textfield" id="box" value="<?php echo $_POST['box']; ?>" /></td> 
</tr> 
<td><input type="submit" name="submit" value="Submit" /></td> 
</tr> 
</table> 
</form> 
+0

他のPHPページにリダイレクトしたいだけですか?たぶんこれはあなたを助けることができるものです:http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php – Roger

+0

@Rogier、彼らは2 html、1 phpです。 htmlの1つがphpにフォームを送信し、phpが入力を実行し、次のページに入力をエコーし​​ます。 –

+0

私はそれを行うことができました。とにかくありがとう。 –

答えて

1
です10
関連する問題