Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:03:21+00:00 2026-06-10T02:03:21+00:00

I just have rewritten my mysql code to PDO, but I just don’t get

  • 0

I just have rewritten my mysql code to PDO, but I just don’t get it working. I’ve been debugging, but just don’t seem te be getting it right. It is all new for me, but it connect tot the database, it reads from the database in my vardump, but it won’t post in the textarea, or even echo for that matter. Let alone, writing to the database… I’ve got a gut feeling that is it the $result var that is doing some weird stuff, but I doublechecked everything as far as I know.

<html>
    <head>
    <title>Milan CMS</title>
    </head>

<body>

    <?php
        $host= "";
        $dbname= "";
        $username= "";
        $password= "";
        $dbh = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
        $sth = $dbh->prepare("SELECT * FROM milan WHERE tag='trainingen'");
        $sth->execute();
        $result = $sth->fetchAll();
        var_dump($result);
        echo $result['value'];
        echo $result;   
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="trainingen">
    Trainingen:<textarea name="nametrainingen" rows="10" cols="60"><?php echo $result['value']; ?></textarea></p>
    <input name="submit" type="submit" value="Verzenden"><input type="reset" value="Veld leeg maken">
    </form>

    <?php
        $invoer = $_POST['nametrainingen'];

        if (isset($_POST['submit'])) { //test if submit button is clicked
        $sql = "DELETE FROM milan WHERE tag = 'trainingen'";
        $sql = "INSERT INTO milan (tag, value) VALUES ('trainingen', '$result')";   
        $sth->execute();
        $result = $sth->fetchAll();
        $myFile = "trainingen.json"; 
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, json_encode($result));
        fclose($fh);}
    ?>
<p>
</body>
</html>

Output of the var_dump:

array(1) { 
    [0]=> array(6) { 
        ["id"]=> string(1) "0" 
        [0]=> string(1) "0" 
        ["tag"]=> string(10) "trainingen" 
        [1]=> string(10) "trainingen" 
        ["value"]=> string(17) "Hgioejigojerigjer" 
        [2]=> string(17) "Hgioejigojerigjer" 
    } 
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:03:23+00:00Added an answer on June 10, 2026 at 2:03 am
    if (isset($_POST['submit'])) { //test if submit button is clicked
        $sql = "DELETE FROM milan WHERE tag = 'trainingen'";
        $sql = "INSERT INTO milan (tag, value) VALUES ('trainingen', '$result')";   
        $sth->execute();
    

    That’s just going to re-run the previous contents of $sth – you’ll need to prepare those two statements and then run them. You need to run them like this:

    if (isset($_POST['submit'])) { //test if submit button is clicked
        $sql = "DELETE FROM milan WHERE tag = 'trainingen'";
        $sth = $dbh->prepare($sql);
        $sth->execute();
        $sql = "INSERT INTO milan (tag, value) VALUES ('trainingen', '$result')";   
        $sth = $dbh->prepare($sql);
        $sth->execute();
    

    Editted to add:

    $result = $sth->fetchAll();
    var_dump($result);
    echo $result['value'];
    echo $result;
    

    $result ends up with an array of values – you’ll have to step through each item in the array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just have learnt how cool RSpec and Cabybara is, and now working around
I just have a quick question about how to get the length of a
I just have a system crash and reinstall Ubuntu 11.10, and my code produces
I'm just about finished my first release of automailer, a program I've been working
Have just started to get into CakePHP since a couple of weeks back. I
I have been trying to add a mod_rewrite to a site but its only
I have just rewritten my personal resume web page in HTML 5 and I
I've just rewritten the following C89 code, that returns from the current function: //
I had really a simple site written in PHP that I have just rewritten
I have just re-written the authentication for one of our internal web applications to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.