有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将php搜索保存到数据库表

我只是想知道是否有人能帮我,我已经为此挣扎了几天。 基本上,我正在对后端php数据库进行动态搜索,并希望使用搜索到的信息添加到另一个表中。记录他们搜索过的数据。 搜索工作正常,但当我单击insert record时,php表中搜索的2个项目的值为空

我非常感谢你的帮助。我的php知识是基本的。 谢谢


共 (1) 个答案

  1. # 1 楼答案

    这里是一个基本的想法,你可以做什么,如果你试图“保存”他们的搜索到数据库中。首先,您将创建一个名为“$search\u string”的变量,然后在您为搜索数据库中的内容而创建的第一个工作函数中,您将把相同的字符串放入变量($search\u string)中。然后,您将把该字符串与用户ID(如果您有)以及他们搜索的字符串一起放入数据库,如下所示

    // So this with be the variable holding the search string that the user searched for E.G Beyonce
    $search_string = "";
    
    // This is the function you already made to search for that string ($search_string) in the database
    
    function search(){
         .... // This is the search code you already made
    
    $search_string = 'The variable thats holding the search string the person sent. It should be a $_POST variable or a variable you already made';
    
    // Now just put the string into the database like so
    
    $link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
    
    mysqli_query($link,"INSERT INTO searches (uid,search_string) VALUES ('". $uid . "', '".$search_string."')"); 
    
     }
    

    然后,您应该将它放在数据库中。现在我不知道您是如何设置数据库表的,但这正是您尝试执行的操作背后的理论。还请记住,您应该将“mysql\u connect”参数更改为您自己的数据库参数,但您可能不需要它,因为您可能已经打开了一个可以使用的连接。希望能有帮助