任何人都认为这个链接缩短代码有任何错误

时间:2016-02-01 17:48:15

标签: php mysql mysqli

在向其提交数据时显示白屏。 请帮忙.. 我是PHP的新手

require_once '../config.php';

$conn = new mysqli($server, $username, $password, $database);
if ($conn->connect_error) {
  die("<p style=color:white>Could not connect to database: " . $conn->connect_error . "</p>");
}

$title = $_GET['title'];
$result = $conn->prepare("SELECT * FROM links WHERE title=?");
$result->bind_param("s", $title);
$result->execute();
$goto = $result->get_result()->fetch_array();

if ($goto != "") {
  $goto = $goto;
  $g = $goto[1];
  header("Location: $g");
}

function GenerateString($string_length = 3) {
  $permissible_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $char_length = strlen($permissible_characters);
  $random = '';
  for ($i = 0; $i < $string_length; $i++) {
    $random .= $permissible_characters[rand(0, $char_length - 1)];
  }
  return $random;
}

$url = $_POST['url'];
$code = GenerateString();

if (isset($_POST['submit'])) {
  if (substr($url, 0, 7) == "http://" ) {
    $url = $url;
  } elseif (substr($url, 0, 8) == "https://") {
    $url = $url;
  } else {
    $url = "http://".$url;
  }
  $result = $conn->prepare("INSERT INTO links VALUES('',?,?)");
  $result->bind_param("ss", $url, $code);
  $result->execute();
}

这是error_log文件:

[01-Feb-2016 17:39:50 UTC] PHP Parse error:  syntax error, unexpected '}' in /home/etcl/public_html/9ui/code/main.php on line 14
[01-Feb-2016 17:39:54 UTC] PHP Parse error:  syntax error, unexpected '}' in /home/etcl/public_html/9ui/code/main.php on line 14
[01-Feb-2016 17:42:01 UTC] PHP Parse error:  syntax error, unexpected '}' in /home/etcl/public_html/9ui/code/main.php on line 14
[01-Feb-2016 17:42:07 UTC] PHP Parse error:  syntax error, unexpected '}' in /home/etcl/public_html/9ui/code/main.php on line 14
[01-Feb-2016 17:42:39 UTC] PHP Notice:  Undefined index: title in /home/etcl/public_html/9ui/code/main.php on line 7
[01-Feb-2016 17:42:39 UTC] PHP Stack trace:
[01-Feb-2016 17:42:39 UTC] PHP   1. {main}() /home/etcl/public_html/9ui/code/main.php:0
[01-Feb-2016 17:42:39 UTC] PHP Fatal error:  Call to undefined method mysqli_stmt::get_result() in /home/etcl/public_html/9ui/code/main.php on line 11
[01-Feb-2016 17:42:39 UTC] PHP Stack trace:
[01-Feb-2016 17:42:39 UTC] PHP   1. {main}() /home/etcl/public_html/9ui/code/main.php:0

提前致谢。 - 扎克

0 个答案:

没有答案