Reputation: 1033
I've the following code in my file:
$s.='<form method="post">';
$s.='NAME: <input type="text" name="name" id="name" /><br>';
$s.='Email: <input type="text" name="email" id="email" /><br>';
$s.='Comment:<br />';
$s.='<textarea name="comment" id="comment" /></textarea><br>';
$s.='<input type="hidden" name="articleid" id="articleid" value="' . $id . '" />';
$s.='<input type="submit" name="submit" value="Submit" />';
$s.='</form>';
if(isset($_POST['submit'])&&$_POST['submit']=='Submit'){
$table = 'comment';
$row = array(
'blog_id' => $_POST['articleid'],
'name' => $_POST['name'],
'email' => $_POST['email'],
'comment' => $_POST['comment']
);
$x = pdoQuick::getManager()->insert($row, $table);
header('location: example.com/xyz ');
}
The insert ()
I'm using from here
The id
that I'm using in articleid
hidden field is not posing any problem. The problem is somewhere else.
The values in my database table comment
are not inserted.
Upvotes: 1
Views: 115
Reputation: 539
Probably not what you want to hear but i would say in the time you spent here and trying to solve the problem yourself, it might benefit you more to learn PDO then you would not have to reliant on someone else's code that should of worked for you in theory. The basics of PDO can be easy to learn within a hour no joke. my 2 cents.
Try to see if code below works for you.
$db=new PDO("mysql:host=localhost;dbname=test;","root","password");
$sql = "INSERT INTO comment (blog_id,name,email,comment) VALUES (:blog_id,:name,:email,:comment)";
$ami = $db->prepare($sql);
$ami->execute(array(
':blog_id' => $_POST['articleid'],
':name' => $_POST['name'],
':email' => $_POST['email'],
':comment' => $_POST['comment']
));
print_r($ami->errorInfo()); // debug
http://php.net/manual/en/pdo.prepared-statements.php
Upvotes: 0
Reputation: 50563
You should give a name to your submit button, if you pretend to retrieve it from php like $_POST['submit']
, like this:
$s.='<input type="submit" name="submit" value="Submit" />';
^----- YOU FORGOT THIS
Upvotes: 2