【问题标题】:PHP Link ShortenerPHP 链接缩短器
【发布时间】:2016-01-30 21:58:13
【问题描述】:

Zack here.. 我最近在使用 URL Shortener 时遇到了问题。您能检查下面的代码是否有错误吗?非常感谢!

    <?php 
    $db = new mysqli("localhost","pretzel_main","00WXE5fMWtaVd6Dd","pretzel");
    function code($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;
    }
    if (substr($_POST['long'], 0, 7) == http://) {
        $url = $_POST['long'];
    } elseif (substr($_POST['long'], 0, 8) == https://) {
        $url = $_POST['long'];
    } else {
        $url = "http://".$_POST['long'];
    }
    $result = $db->prepare("INSERT INTO links VALUES('',?,?)");
    $result->bind_param("ss",$url, $title);
    $result->execute();
    $title = $code();
?>

祝你好运,提前致谢! - 扎克

【问题讨论】:

  • ){]$ => 这无效...打开你的错误报告
  • @ZDavies 不,它已经随你编辑消失了,所以可能是一个错字。但是这个$code();还是不好
  • 什么你遇到了什么麻烦?具体错误。
  • @Blag 为什么不是 Blag?
  • @ZDavies 因为$code(); 的意思是$code = 'functionName'; {$code}(); /*same as*/ functionName(); 又名你不需要$ 在你的函数调用之前我认为:$title = code();

标签: php mysql database mysqli


【解决方案1】:

试试这个:

 <?php 
    $db = new mysqli("localhost","pretzel_main","00WXE5fMWtaVd6Dd","pretzel");
    function code($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;
    }
    if (substr($_POST['long'], 0, 7) == "http://") {
        $url = $_POST['long'];
    } elseif (substr($_POST['long'], 0, 8) == "https://") {
        $url = $_POST['long'];
    } else {
        $url = "http://".$_POST['long'];
    }
    $result = $db->prepare("INSERT INTO links VALUES('ss','$url','$title')");
    $result->execute();
    $title = code(); // no need of $ sign here
?>

【讨论】:

  • 不,只是不,所以在你得到一堆 -1 之前删除你的帖子;它们比您更改的代码错误更多
  • 太棒了!只是又遇到了一个错误.. 你能帮忙吗?
  • 致命错误:在第 43 行的 /home/etcl/public_html/9ui/index.php 中的非对象上调用成员函数 execute()
猜你喜欢
  • 2014-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
  • 2016-10-21
  • 1970-01-01
  • 2014-04-04
相关资源
最近更新 更多