我幾乎要完成我的第一個PHP/HTML網站,並且在使用'connect.php'提交HTML表單後,我將其堆疊在此重定向中。提交表單後,header()標記不會重定向
我猜這個'header()'標記有問題,因爲sql post工作正常。
首先,形式:
<div id="formulario">
<form action="connect.php" method="post" enctype="multipart/form-data" onSubmit="alert('Thank you for your feedback.')">
<p id="form_title">COMPLETA TUS DATOS Y ENVIA ESTA SOLICITUD <br> A LAS AUTORIDADES</p>
<label></label>
<input class="field" name="user_name" type="text" required="required" placeholder="NOMBRE">
<label></label>
<input class="field" name="user_last" type="text" required="required" placeholder="APELLIDO">
<label></label>
<input class="field" name="pais" type="text" required="required" placeholder="PAIS">
<label></label>
<input class="field" name="user_email" type="email" required="required" placeholder="EMAIL">
<label></label>
<input class="field" name="tel" type="number" required="required" placeholder="TELEFONO">
<input id="submit" name="submit" type="submit" value="SUBMIT">
<div id="masinfo">
<a href="" target="_blank"><img src="" alt="" />CLICK AQUI PARA MAS INFO</a>
</div>
</form>
現在, 'connect.php' 文件:
define('DB_NAME', 'm9000207_ficlog');
define('DB_USER', 'm9000207_ficlog');
define('DB_PASSWORD','25dutotePE');
define('DB_HOST','localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' .mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
$value1 = $_POST ['user_name'];
$value2 = $_POST ['user_last'];
$value3 = $_POST ['pais'];
$value4 = $_POST ['tel'];
$value5 = $_POST ['user_email'];
$sql = "INSERT INTO registros VALUES ('', '$value1', '$value2', '$value3', '$value4', '$value5')";
if($value1 !=''&& $value2 !=''&& $value3 !=''&& $value4 !=''&& $value5 !=''){
header("Location: index.html");
}
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
if (!$db_selected) {
die ('Cant use' . DB_NAME . ': ' . mysql_error());
}
mysql_close();
?>
哪些錯誤你好嗎?另外,請牢記[SQL注入](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)。切勿使用該代碼進行生產。 – Dencker 2015-02-11 16:11:06
仍然需要說:http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – CD001 2015-02-11 16:12:38
確定你正在進入if語句嗎? – 2015-02-11 16:13:16