0

我正在尝试创建一个 URL 缩短脚本,当用户提交他们的 URL 时,它应该返回一个包含缩短 URL 的文本字段,但事实并非如此,请你看看我的代码,看看你是否可以停止这个问题?

谢谢。

<html>
<head></head>

<body>

<?php

if ($_POST['shortbtn']) {
    $url = $_POST['url'];

    if ($url) {

        require("./connect.php");

        $charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $len = 5;
        $numrows = 1;

        while ($numrows != 0) {
            for ($i = 0; $i <= $len; $i++) {
                $rand = rand() % strlen($charset);
                $tmp = substr($charset, $rand, 1);
                $code .= $tmp;
            }

            $query = mysql_query("SELECT * FROM items WHERE code='$code'");
            $numrows = mysql_num_rows($query);
        }

        $date = date("F d, Y");

        mysql_query("INSERT INTO items VALUES('', '$url', '$code', '$date')");

        $query = mysql_query("SELECT * FROM items WHERE code='$code'");
        $numrows= mysql_num_rows($query);

        if ($numrows == 1) {
            $site = "http://dthms.dev:8888/projects/url-short/";
            echo "Your URL: <input type='text' value='$site/$code' size='40'>";
        } else
            echo "Not Added";

        mysql_close();

    } 

    else echo "<script type='text/javascript'>window.location = './'</script>";
} else echo "";

?>

</body>
</html>

在您提交 URL 时,它会返回“未添加”

if ($numrows == 1) {
                $site = "http://dthms.dev:8888/projects/url-short/";
                echo "Your URL: <input type='text' value='$site/$code' size='40'>";
            } else
                echo "Not Added";
4

0 回答 0