automatically create new pages with php and mysqli

前端 未结 2 1162
醉酒成梦
醉酒成梦 2021-01-16 06:28

still getting my feet wet with php and mysqli, have so much to learn, but at this point this question is one of my most important priorities.

I did some research abo

相关标签:
2条回答
  • 2021-01-16 06:41

    If I'm understanding you correctly, I believe you're waiting to create pages from the database Dynamically. You can use a get variable in the request http://yoursite.com/page.php?group=1. Then in your code update your query to do:

    $query = "SELECT word FROM demo WHERE group=".$_GET['group'];
    

    That query is insecure, as any user could inject raw mysql into the $_GET['group'] variable.

    $group = mysqli_real_escape_string($conn, $_GET['group']);
    $query = "SELECT word FROM demo WHERE `group`='$group'";
    

    This is much safer.

    0 讨论(0)
  • 2021-01-16 06:44

    So PHP will look for a file called index.php by default in any directory that it accesses. You can place such a file in the root of public_html or www or where ever your site accesses. Now in this file you can do something like:

    <?php
        if($_GET['group']){ //Make sure you have the var
             $query = "SELECT word FROM demo WHERE `group`=?"; //The query with param
            if ($stmt = mysqli_prepare($conn, query){ // try it out
                mysqli_stmt_bind_param($stmt, "i", $_GET['group']); // bind the data
                $stmt->execute(); //run it
                $result = $stmt->get_result(); // get results
    
                //use result to echo and stuff
            }
        } else {
            //Do something incase there is not a group specified.
            echo "Nothing here";
        }
    ?>
    

    Now when you go to your site you will get something like 'localhost/index.php' and see Nothing here but if you type localhost/index.php?group='55' you will have access to the page 55 data in result.

    0 讨论(0)
提交回复
热议问题