简体   繁体   English

我的SQL查询没有给出任何结果

[英]my sql query not giving any results

I am trying to make a sql query, but its not working out for me. 我正在尝试进行SQL查询,但它不适合我。

PHP CODE: PHP代码:

<?php 
    if(isset($_POST['gobtn'])) {

        mysql_select_db('sessions', $conn);
        $conn = mysql_connect('localhost', 'root', '');

        if(!$conn) {
            die('Cannot connect to the database');
        } else {

            $sesid = $_POST['sesid'];

            $sql = "INSERT INTO `sessions`.`sesinfo` (`id`) VALUES ('$sesid');";
            $retval = mysql_query($sql, $conn);

            if(!$retval){
                die('Cannot enetr into the database');
            } else {
                echo "Done bro!";
                mysql_close($conn);
            }

        }

    }
?>

And the HTML Part: 和HTML部分:

<form method="POST" action="<?php $_PHP_SELF ?>">
        <h1 style="height: 60px; width: 500px; color: Black; font-family: Times New Roman; text-align: center; font-style: italic; font-style: bold; font-size: 20px; margin-left: 45%;">
            Enter any session ID: <input type="text" name="session_id" id="sesid">
            <input type="submit" value="GO" name="go_button" id="gobtn">    
        </h1>       
    </form>

I created db named as 'sessions'. 我创建了名为'sessions'的数据库。 It contains two tables: 它包含两个表:

id and text id和文字

I want to add the value of textbox input entered by user to the id table. 我想将用户输入的文本框输入值添加到id表中。 But its not stopping on die command, and not even echoing out the last command. 但它没有停止die命令,甚至没有回应最后一个命令。 Any help would be appreciated alot. 任何帮助将不胜感激。

Thanks in advance. 提前致谢。

Try This, 尝试这个,

if(isset($_POST['go_button'])) {

$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('sessions', $conn);

    $sesid = $_POST['sesid'];

    $sql = "INSERT INTO `sessions`.`sesinfo` (id) VALUES ('$sesid')";
    $retval = mysql_query($sql, $conn);

    if(!$retval){
        die('Error!');
    } else {
        echo "Done bro!";
        mysql_close($conn);
    }
}     

If your id is integer then your query will be-> 如果您的id是整数,那么您的查询将是 - >

 $sql = "INSERT INTO `sessions`.`sesinfo` (id) VALUES ($sesid)";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM