从php传递给ajax的javascript变量不能仅用于insert中的sql select语句

57hvy0tb  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(235)

正如标题所说。我存储的从php到ajax再到另一个php的变量不能用在sql中的“select”语句中,只能用在“insert”上。我试着在sql的“insert”语句中使用变量“$\u post[”tweet“]”,它可以工作。在此处输入图像描述,但在select语句中它不起作用。我甚至不能在来自ajax的变量中使用echo。
chatproftouser.php

<?php

include 'header.php';
include 'connect.php';
session_start();

if(isset($_GET['UID'])){
    $userid = $_GET['UID'];
    $query = mysqli_query($conn,"SELECT * FROM usertable WHERE userid LIKE             '$userid'") or die(mysql_error());
if(mysqli_num_rows($query)>0)
{
    while ($a = mysqli_fetch_array($query))
    {
        $userid = $a['userid'];
        $username = $a['username'];
        $useremail = $a['useremail'];  
        ?>
        <html>
        <body>
        <div id=sendername>
            <p><?php echo $username ?></p>
            <p><?php echo $useremail ?></p>
        </div>
        <div class="container box">
        <form name="sendmessage" method="post">
            <div class="form-group">
            <textarea name="usermessage" id="usermessage" class="form-control" rows="3"></textarea>
            </div>
            <div class="form-group" align="right">
            <input type="button" name="sendusermessagebutton" id="sendusermessagebutton"  value="Send" class="btn btn-info" />
            </div>
        </form>
        </div>
        <div id=chatprof>
            <!-- HERE IS THE CHATLOG -->
        </div>
        <script>
        $(document).ready(function(){
            var tweet_txt = "<?php echo $useremail?>";
            $.ajax
            ({
                url:"chatprof.php",
                method:"POST",
                data:{tweet:tweet_txt},
                dataType:"text",
            });        
        });
        </script>
        <script>    
            $(document).ready(function(){
                setInterval( function(){ $('#chatprof').load('chatprof.php'); }, 2000 );
            });
        </script>
        <script type="text/javascript" src="js/insertusermessage.js"></script>
        </body>
        </html>
        <?php 
    }
    }else{

    echo "Theres is no ID like that";
    header("Location:chatprofmessenger.php");
    }
}

?>

这是我的另一个php for select语句。
chatprof.php软件

<?php
session_start();
include 'connect.php';
if(isset($_POST["tweet"]))
{       
    $prfemail = $_SESSION['prfemail'];
    $tweet = mysqli_real_escape_string($conn, $_POST["tweet"]);
    $sql = mysqli_query($conn,"SELECT * FROM chatlogs WHERE     useremail='".$tweet."' AND prfemail='$prfemail'");
if(mysqli_num_rows($sql) > 0)
    {
    while($a = mysqli_fetch_array($sql))
        {
            $useremail = $a['useremail'];
            $message = $a['message'];
            echo $useremail;
            echo "<br>";
            echo $message;
        }
    }
}
?>

先谢谢你。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题