mysql脚本只重新加载

时间:2017-02-03 17:25:16

标签: php mysql sql

如果我点击提交,则只刷新网站。 connect.php是正确的。但有些事情必须是错误的。

in.php

<form id="mathe1" action="script.php" method="post">
    <input name="nummer" type="number" value=""/><br><br>
    <label id="label"><p>Hausübung</p></label>
    <textarea name="hu" cols="60" rows="5"></textarea><br><br>
    <input name="Submit1" type="submit" value="Senden"/>
</from>

的script.php:

<?php    
include('include/connect.php');

$nummer = $_POST['nummer'];
$hu = $_POST['hu'];
$db = "hu";

if (empty($nummer)) {
    header('Location:in.php');
}
if (empty($hu)) {
    header('Location:in.php');
}
else {
    $sql = "INSERT INTO $db VALUES ('$nummer','$hu')";
    $query = mysql_query($sql);
}
?>

1 个答案:

答案 0 :(得分:0)

如果声明和位置应该绝对定义,那么看起来你的定义是错误的,所以:

in include / connect.php

  $mysqli = new mysqli('sqlhost', 'user', 'password', 'db');

在scpipt.php中

  $nummer = $_POST['nummer'];
  $hu = $_POST['hu'];
  $table = "hu";
  $url = "http://yourdevhost/in.php";

  if (empty($nummer) || empty($hu)) {
    header('Location: '.$url);
  } else {
    $stmt = $mysqli->prepare('INSERT INTO ? VALUES (?, ?)');
    $stmt->bind_param('sss', $table, $nummer, $hu);
    $stmt->execute();
  }