SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting Zero Errors using an Insert command but 0 data is going into my Database

    Hi,

    I got a database with 2 columns. Retrieving data from it I have 0 problems, but inserting Data is a different story. The code I got from a tutorial seems pretty straightforward, but implementing it seems a bit of a challenge especially that I am getting 0 errors. Been at this code for quite sometime, and I think at this point it would be beneficial to have someone take a second look at it.
    Code:
     
    try{
    $conn = new PDO('mysql:host=Jamal-PC;dbname=japanesewords',$username,$password);
    
    
    if(isset($_POST['EnglishWord'])){
    $Englishword = $_POST['EnglishWord'];
    $Japaneseword = $_POST ['JapaneseWord'];
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';
    $q = "INSERT INTO Japanesedefinition(Japaneseword,Englishword)VALUES(:Japaneseword,:Englishword):";
    $query = $conn->prepare($q);
    $result = $query->execute(array(
    ":Englishword"=>$Englishword,
    ":Japaneseword"=>$Japaneseword
    
    ));
    }
    }catch(PDOException $e){
     echo 'ERROR: ' . $e->getMessage();
    }
    
    }
    myTest();
    
    The query returns:
    Array
    (
        [JapaneseWord] => konnichiwa
        [EnglishWord] => hi
    )
    Last edited by louis345; Sep 12, 2013 at 20:59. Reason: adding informatio

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,033
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    The variables have to be pound to parameters, this is done inbetween preparing the SQL query and executing it. Have a read of the http://php.net/manual/en/pdostatement.bindparam.php for some more info
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,162
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, the only thing I see is the : at the end of your Query... Execute can take an array to bind on prepared statements, so that looks okay.

    What looks odd, is the part in red
    Code:
    "INSERT INTO Japanesedefinition(Japaneseword,Englishword)VALUES(:Japaneseword,:Englishword):"

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Try echoing out $query->errorInfo(); after the execute.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Okay, the only thing I see is the : at the end of your Query... Execute can take an array to bind on prepared statements, so that looks okay.

    What looks odd, is the part in red
    Code:
    "INSERT INTO Japanesedefinition(Japaneseword,Englishword)VALUES(:Japaneseword,:Englishword):"

    It was the bloodily colon. Thank you so much.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •