Jump to content

form data not posted using PDO help needed


andybriggs

Recommended Posts

<?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

 

 

 

 

 

 

 

 

 

 

post-169782-0-84809000-1408104731_thumb.jpg

Link to comment
Share on other sites

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";
}
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.