Problem with PDO->execute();

From: Date: Sat, 02 Jun 2007 16:59:01 +0000
Subject: Problem with PDO->execute();
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-35592@lists.php.net to get a copy of this message
Hi i'm learning connecting to mysql DB with PDO since 3 or 4 days.... Now i've got a really big problem: $dbinsert -> execute(); kills my application! Please help me and have a look at my source code..... : The einfuegen.php has as form-action hisself! if your take a look into the function DBinsert(); you'll see that i've found the problem through echo's when i activate DBinsert(); he writes only the numbers till 4 not the 5 (afte the execute!) I hope you can help me! Georg Lindner Germany <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php function DBinsert($nickname,$password,$prename,$name){ $strdb = 'mysql:dbname=flashgame;host=localhost'; $struser = 'root'; $strpass = 'root'; try { $objdb = new PDO($strdb,$struser,$strpass); echo 'Verbindung erfolgreich erstellt!1<br>'; $dbinsert = $objdb->prepare('Insert
                            INTO
                            userdaten (username,password,vorname,nachname)
                            VALUES
                            (:username, :password, :vorname, :nachname)
                            ') or die(mysql_error());
                       echo $dbinsert.' <p>';
$dbinsert -> bindParam('username', $nickname) or die(mysql_error()); echo '1'; $dbinsert -> bindParam('password', $password) or die(mysql_error()); echo '2'; $dbinsert -> bindParam('vorname', $prename) or die(mysql_error()); echo '3'; $dbinsert -> bindParam('nachname', $name) or die(mysql_error()); echo '4'; $dbinsert -> execute() or die(mysql_error()); echo '5'; $objdb = null; $obinsert = null; } catch (PDOException $e) { echo 'Fehler bei dem Verbinden!' . $e -> getMessage(); } } function DBview (){ $strdb = 'mysql:dbname=flashgame;host=localhost'; $struser = 'root'; $strpass = 'root'; try { $objdb = new PDO($strdb,$struser,$strpass); echo 'Verbindung erfolgreich erstellt!2<br>'; $dbresult = $objdb->query('SELECT *
                            FROM userdaten
                            ORDER BY id_user') or die($e->getMessage());
echo 'USERDATEN<p>'; foreach($dbresult as $row) {
      echo 'id_user: '. $row[0];
      echo 'Username: '. $row[1];
      echo 'Password: '. $row[2];
      echo 'Vorname: '. $row[3];
      echo 'Nachname: '. $row[4];
} $objdb = null; $obresult = null; } catch (PDOException $e) { echo 'Fehler bei dem Verbinden!' . $e -> getMessage(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Unbenanntes Dokument</title> </head> <body> <form action="einfuegen.php?do=check" method="post"> USERNAME: <input type="text" size="60px" name="user" value="<?php echo $_POST['user']; ?>"><br> PASSWORD: <input type="password" size="60px" name="pass" ><br> whd pass: <input type="password" size="60px" name="wdhpass"><br> &nbsp;VORNAME: <input type="text" size="60px" name="vor" value="<?php echo $_POST['vor']; ?>"><br> NACHNAME: <input type="text" size="60px" name="nach" value="<?php echo $_POST['nach']; ?>"><p> <input type="submit" value="OK!"> <input type="reset" value="neue werte"> <p>&nbsp;</p> </form> <?php
    if(!$_GET['do']) {
        DBview();
        echo 'fall 1';
    }
    else {
         if($_GET['do'] == 'check') {
         //$dpsec = $_GET['do'];
         //echo 'erstens';
         if($_POST['pass'] == $_POST['wdhpass']) {
             echo 'fall II1';
DBinsert($_POST['user'],$_POST['pass'],$_POST['vor'],$_POST['nach']);
             DBview();
             echo 'fall II';
         }
         else {
             echo 'Passwoerter sind falsch oder nich ausgefuellt!<p>';
         }
      }
    }
?> </body> </html>

« previous php.mirrors (#35592) next »