INSERT, SELECT,REQUEST help

Hey :blush:
edpro.php

<center>
       <?php
  
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
    // collect value of input field
    $data = $_REQUEST['comment'];
  
    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}
?>
        <form action="pro.php" method="post">
               <label for="comment">Bio</label>
                <input type="text" name="comment" id="comment">
                 
            <input type="submit" value="Submit">
        </form>
    </center>
  </div>

pro.php

<?php
        $conn = mysqli_connect("");
        if($conn === false){
            die("ERROR: Could not connect. " 
                . mysqli_connect_error());
        }
        $comment =  $_REQUEST['comment'];
        $sql = "INSERT INTO comment (comment)
        VALUES ('$comment')";
            if(mysqli_query($conn, $sql)){
            echo "<h3>data stored in a database successfully." 
                . " Please browse your localhost php my admin" 
                . " to view the updated data</h3>"; 
  
            echo $comment;
        } else{
            echo "ERROR: Hush! Sorry $sql. " 
                . mysqli_error($conn);
        }
          
        // Close connection
        mysqli_close($conn);
        ?>

The info for the edpro.php file transfers to the pro.php file but is not inserting into DB. Goal is to have the DB info inserted display on pro.php. How do I fix my code if possible?

Thank ya :heart:

I suggest using PDO instead of mysqli - (The only proper) PDO tutorial - Treating PHP Delusions

Here’s a small tutorial that I did - https://www.miniaturephotographer.com/

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service