andybriggs Posted August 15, 2014 Share Posted August 15, 2014 <?php include("add_p2.php"); //basic pdo connection (with added option for error handling) if (isset($_POST['submit'])) { try { $stmt = $dbh->prepare("INSERT INTO passwords (description, username, password ) VALUES (:description, :username, :AES_ENCRYPT)"); $stmt->bindParam(':description', $description); $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $password); try { $statement->execute(array( "description" => "description", "username" => "username", "password" => "password" )); } catch(PDOException $e) { echo "Exception caught: $e"; } //insert one row $name = 'one'; $value = 1; $stmt->execute(); header( 'Location: localhost/password_added.php' ); exit(); ?> <?php $dsn = "mysql:host=127.0.0.1;dbname=pword_db;charset=utf8"; $opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $pdo = new PDO($dsn,'root','', $opt); ?> <form action="add_p.php" method="post"> <span class="cursive">Description: </span><br> <textarea name="description" rows="20" cols="50"></textarea> <br> <span class="cursive">Username: </span><br> <input type="text" name="username" /> <br> <span class="cursive">Password: </span><br> <input type="text" name="password" /> <br> <input type="submit"/> </form> Hi, above is the 3 components that should add form data into MySQL database using PDO. all it's doing is entering empty values, I'm really not sure why this is? please could someone help me with pointing me in the right direction, offer hint's making this work Thanks Quote Link to comment https://forums.phpfreaks.com/topic/290466-form-data-not-posted-using-pdo-help-needed/ Share on other sites More sharing options...
fastsol Posted August 15, 2014 Share Posted August 15, 2014 You've got a couple issues. First you're naming of the bindValues doesn't match the sql string. The 3 bind you label :AES_ENCRYPT in the query string but then you bind it with :password below. Secondly, you are using bindValue but then also using an array in the execute() too. You only need one or the other, not both. Plus you have 2 try{} which is wrong. Lastly, you were trying to run the execute with $statment but you called the prepare on $stmt, so that won't work either. You need to make sure you're paying attention to what and how you are naming things and be consistent about it. Try this try { $stmt = $dbh->prepare("INSERT INTO passwords (description, username, password ) VALUES (:description, :username, :password)"); $stmt->bindParam(':description', $description); $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $password); $stmt->execute(); } catch(PDOException $e) { echo "Exception caught: $e"; } Quote Link to comment https://forums.phpfreaks.com/topic/290466-form-data-not-posted-using-pdo-help-needed/#findComment-1487859 Share on other sites More sharing options...
jazzman1 Posted August 15, 2014 Share Posted August 15, 2014 all it's doing is entering empty values, ............. Really? In addition what fastsol said, check the status out of this if statement - if (isset($_POST['submit'])) ...... I don't see where is the name attribute called "submit" in your html form. Quote Link to comment https://forums.phpfreaks.com/topic/290466-form-data-not-posted-using-pdo-help-needed/#findComment-1487862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.