标题不工作PHP [英] headers not working PHP
本文介绍了标题不工作PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是页面PHP1.php在这里我试图验证用户输入,如果名称和ID在数据中,他将被转发填写第二部分的注册,如果不是它只会给出错误。
<?php
session_start();
$ _SESSION [acb] =好的;
$ _SESSION ['team'] = $ _POST ['team_name'];
$ con = mysql_connect(localhost,user,password);
if(!$ con)
{die('Could not connect:'。mysql_error());}
mysql_select_db(mydbName);
if(isset($ _ POST ['team_name'],$ _ POST ['id'])){
$ team_name = mysql_real_escape_string($ _ POST ['team_name']);
$ id = mysql_real_escape_string($ _ POST ['id']);
if(!empty($ team_name)){
$ result = mysql_query(SELECT COUNT(`teamname`)FROM`table` WHERE`teamname` ='$ team_name'AND`id` =' $ ID');
$ team_result = mysql_fetch_row($ result);
if($ team_result [0] =='0'){//如果不存在,则打印失败。
echo'Varification failed';
} else {
header('Location:http://www.abc.com/REGISTERpart2.php');
}}}?>
RegisterPART2.php是我检查会话是否存在的地方(我在最后一个文件)。如果不是,我想重新回到表格填写,然后填写第一个表格,然后进入注册部分2
`<?php
session_start();
$ name = $ _SESSION ['team']; //存储在会话中的值,我在这个页面上使用
if(($ _SESSION [abc]!=='good')){
header('Location:http:// www .abc.com / page1.html'); //带回第1阶段,因为用户没有填写第一部分。
}
else {
echo $ name。 '您已完成注册程序第一部分,您可以继续!';
?>
$ c如果你使用新的MySQL版本(MySQLi),那么第一页就会变成:
<?php
session_start();
$ _SESSION [acb] =好的;
$ _SESSION ['team'] = $ _POST ['team_name'];
$ con = new mysqli(localhost,user,password,mydbName);
if(!$ con){
die('Could not connect:'。$ con> error());
};
if(isset($ _ POST ['team_name'],$ _ POST ['id'])){
$ team_name = $ con> real_escape_string($ _ POST ['team_name']);
$ id = $ con> real_escape_string($ _ POST ['id']);
if(!empty($ team_name)){
$ result = $ con> prepare(SELECT COUNT(`teamname`)FROM`table` WHERE`teamname` ='$ team_name'AND `id` = '$ ID');
$ result-> execute();
$ result-> bind_result($ one,$ two,$ three,$ etc);
$ result-> fetch();
if(empty($ one)and empty($ two)and empty($ three)and empty(etc)){//可以和/或(选择一个)
echo'Varification failed' ;
} else {
header('Location:http://www.abc.com/REGISTERpart2.php');
}
}
}
?>
Page 1 abc.html.. on submit it will jump to this PHP page . This is page PHP1.php here i am trying to validate user input if name and id in in data he will be forwarded to fill out second part of registration if not it will just give error.
<?php
session_start();
$_SESSION["acb"] = "good";
$_SESSION['team'] = $_POST['team_name'];
$con = mysql_connect("localhost", "user", "password");
if (!$con)
{die('Could not connect: ' . mysql_error());}
mysql_select_db("mydbName");
if(isset($_POST['team_name'],$_POST['id'])){
$team_name = mysql_real_escape_string($_POST['team_name']);
$id = mysql_real_escape_string($_POST['id']);
if (!empty($team_name)) {
$result= mysql_query("SELECT COUNT(`teamname`) FROM `table` WHERE `teamname`='$team_name' AND `id`='$id'");
$team_result = mysql_fetch_row($result);
if ($team_result[0] == '0') { //if does not exist print failed.
echo 'Varification failed';
} else {
header('Location: http://www.abc.com/REGISTERpart2.php');
}} } ?>
RegisterPART2.php is where i am checking my session exist or not (the one i started in last file). if not i want to redirect back to form one and fill that first then come to registration part 2
`<?php
session_start();
$name = $_SESSION['team']; //a value stored in session which i used on this page
if (($_SESSION["abc"] !== 'good')) {
header('Location: http://www.abc.com/page1.html'); //take back to stage 1 coz user did not fill first part.
}
else{
echo $name. 'you have completed register process part one you may continue!';
}
?>
解决方案
If you're using the new MySQL version (MySQLi), so the first page will become:
<?php
session_start();
$_SESSION["acb"] = "good";
$_SESSION['team'] = $_POST['team_name'];
$con = new mysqli("localhost", "user", "password", "mydbName");
if (!$con) {
die('Could not connect: ' . $con->error());
};
if (isset($_POST['team_name'],$_POST['id'])) {
$team_name = $con->real_escape_string($_POST['team_name']);
$id = $con->real_escape_string($_POST['id']);
if (!empty($team_name)) {
$result = $con->prepare("SELECT COUNT(`teamname`) FROM `table` WHERE `teamname`='$team_name' AND `id`='$id'");
$result->execute();
$result->bind_result($one,$two,$three,$etc);
$result->fetch();
if (empty($one) and empty($two) and empty($three) and empty(etc)) { // may be and/or (pick one)
echo 'Varification failed';
} else {
header('Location: http://www.abc.com/REGISTERpart2.php');
}
}
}
?>
这篇关于标题不工作PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文