Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,
I have a working mysql database with my PHP code. I can create a new row and delete a row BUT when I click the btn delete the page just continually keeps loading and never goes to my header(). For my create btn the page does the same thing just keeps
Is PDO one of the best phps to use these days?

For doing prepared statements how is this for my example of code below. Anything that i should do differently?

Can you all look at this.
How do you think this is for my prepared statements. Someone said PDO PHP is the way PHP should be used now adays? Is the correct.
Here is my prepared statement. Am I doing everything correctly or what should i change? loading. Here is my code.
PHP
//Full DELETE
  if(isset($_POST["id"]) && !empty($_POST["id"])) {
        require_once "php/config.php";
      // Prepare a DELETE statement
      $sql = "DELETE FROM users WHERE id=:id";

      if($stmt = $pdoConnect->prepare($sql)) {
        $stmt->bindParam(":id", $param_id);
        $param_id = trim($_POST["id"]);
        if($stmt->execute()) {
          header("location: index.php");
          exit();
        } else {
              echo "Something went wrong with DELETE.";
        }
      }
      // Close $stmt statement
      unset($stmt);
      // Close connections
      unset($pdoConnect);
    } else {
        // Check existence of 'id' parameter
        if(empty(trim($_GET["id"]))) {
          //URL doesn't contain parameter send ERROR
          header("location: error.php");
          exit();
        }
    }
// Create php code
            $sql = "INSERT INTO users(name, language, date) VALUES " .
                   "(:name, :language, :date)";

            if($stmt = $pdoConnect->prepare($sql))
            { // Bind variables to prepared statement as parameters.
                $stmt->bindParam(":name", $para_name);
                $stmt->bindParam(":language", $para_lang);
                $stmt->bindParam(":date", $para_date);
              // Set parameters
                $para_name = $name;
                $para_lang = $language;
                $para_date = $currentDate;
              // Attempt to execute prepared statement
                if($stmt->execute())
                { // Determine if Success or Error
                    header("Location:index.php");
                    exit();
                } else {
                    echo "Something went wrong with INSERT, please try again later.";
                }


What I have tried:

My page just keeps loading and never executes a new page I also have a question about PHP langauge what one should i be using now adays PDO? and is that ok for doing parameters how i have mine setup in the code?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900