我有一個非常簡單的表單,它將數據發送到另一個頁面,然後在將數據插入數據庫之前檢查它是否存在。它在MAMP中完美地在本地環境中工作,但在服務器上它不會插入任何數據。它似乎不會發送任何數據,因爲我刪除了isset檢查它運行該程序,但將空白字段插入到數據庫中。表單本地提交數據但不是遠程提交數據
我不明白爲什麼它不起作用。安全不是問題。
HTML
<form method="post" action="input.php">
<tbody>
<tr>
<td>Nombre</td>
<td><input type="text" class="form-control" value="" name="nombre" id="nombre"></td>
</tr>
<tr>
<td>Apellido</td>
<td><input type="text" class="form-control" value="" name="apellido" id="apellido"></td>
</tr>
<tr >
<td>Correo</td>
<td><input type="text" class="form-control" value="" name="correo" id="correo"></td>
</tr>
<tr >
<td>Telefono</td>
<td><input type="text" class="form-control" value="" name="telefono" id="telefono"></td>
</tr>
<tr>
<td>Nivel de interés</td>
<td><select name="nivel" id="nivel"><option value="none">Elige uno</option><option value="Licenciatura">Licenciatura</option><option value="Maestria">Maestría</option><option value="Doctorado">Doctorado</option><option value="Curso de ingles">Curso de inglés</option></select></td>
</tr>
<tr >
<td>Universidad</td>
<td><input type="text" class="form-control" value="" name="universidad" id="universidad"></td>
</tr>
<tr >
<td>Hoy</td>
<td><input type="text" class="form-control" value="<?php echo date("Y-m-d"); ?>" name="fecha" id="fecha" readonly></td>
</tr>
<tr >
<td></td>
<td><input class="btn btn-default" type="submit" name="submit" id="submit" value="Guardar"></td>
</tr>
</tbody>
</form>
PHP
if(isset($_POST['submit']))
{
$nombre = mysql_real_escape_string(htmlspecialchars($_POST['nombre']));
$apellido = mysql_real_escape_string(htmlspecialchars($_POST['apellido']));
$correo = mysql_real_escape_string(htmlspecialchars($_POST['correo']));
$telefono = mysql_real_escape_string(htmlspecialchars($_POST['telefono']));
$nivel = mysql_real_escape_string(htmlspecialchars($_POST['nivel']));
$universidad = mysql_real_escape_string(htmlspecialchars($_POST['universidad']));
$fecha = mysql_real_escape_string(htmlspecialchars($_POST['fecha']));
if($nombre == '' || $apellido == '' || $correo == '' || $telefono == '' || $nivel == '' || $universidad == '' || $fecha == '') {
header('Location: fallo.php');
} else {
$db = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
$data = $db->prepare("INSERT INTO ferias (nombre, apellido, correo, telefono, nivel, universidad, fecha) VALUES (:nombre, :apellido, :correo, :telefono, :nivel, :universidad, :fecha)");
$data->execute(array(
'nombre' => $nombre,
'apellido' => $apellido,
'correo' => $correo,
'telefono' =>$telefono,
'nivel' => $nivel,
'universidad' => $universidad,
'fecha' => $fecha));
}
}
使用'PDO :: quote()'而不是棄用的(在你的情況下完全不必要的,因爲你正在使用準備語句)'mysql_real_escape_string()'。 – nietonfir
您的活網站probaly已禁止錯誤消息。您需要查看服務器日誌或在'$ data-> execute'之後放置打印或其他語句,以查看實際發生的情況。 – jeff
可能是PHP版本問題。你確定你在本地和服務器上有相同的版本嗎? – zzxx53