Reputation:
I'm not able to insert the data with this.
Here is my code:
<?php
include('includes/config.php');
if(isset($_POST['update'])) {
$sampleid=$_POST['sampleid'];
$aba11=$_POST['aba11'];
$aba12=$_POST['aba12'];
$sql="INSERT INTO 'aba1'(sampleid,aba11,aba12) VALUES(:sampleid,:aba11,:aba12)";
$query = $dbh->prepare($sql);
$query->bindParam(':sampleid',$sampleid,PDO::PARAM_STR);
$query->bindParam(':aba11',$aba11,PDO::PARAM_STR);
$query->bindParam(':aba12',$aba12,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
}
?>
<html>
<form>
<body>
<label> Sampleid </label> <input type="text" name="sampleid"><br>
<label> Start time </label> <input type="text" name="aba11"><br>
<label> Stoptime </label> <input type="text" name="aba12"><br>
<button type="submit" name="update" >Update</button>
</Form>
</body>
</html>
My database connection is correct. There is no error in config.php file.
Upvotes: 0
Views: 68
Reputation: 4033
use form method post
<form method="post" id="insert-data">
</form>
value in insert query put $sampleid,$aba11,$aba12
Upvotes: 0
Reputation: 289
Your form's method was missing and the value in your update button was missing
also, you must use ` instead of ' for database table names
try the code below
<?php
include('includes/config.php');
if(isset($_POST['update'])) {
$sampleid=$_POST['sampleid'];
$aba11=$_POST['aba11'];
$aba12=$_POST['aba12'];
$sql="INSERT INTO `aba1` (sampleid,aba11,aba12) VALUES(:sampleid,:aba11,:aba12)";
$query = $dbh->prepare($sql);
$query->bindParam(':sampleid',$sampleid,PDO::PARAM_STR);
$query->bindParam(':aba11',$aba11,PDO::PARAM_STR);
$query->bindParam(':aba12',$aba12,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
}
?>
<html>
<body>
<form method="POST" action="">
<label> Sampleid </label> <input type="text" name="sampleid"><br>
<label> Start time </label> <input type="text" name="aba11"><br>
<label> Stoptime </label> <input type="text" name="aba12"><br>
<button type="submit" name="update" value="1">Update</button>
</Form>
</body>
</html>
Upvotes: 1
Reputation: 1
Code seems pretty much ok for me.
Are you certain that $_POST['update']
is set to something?
The lack of error could indicate that it isn't even going through your PHP
block.
Upvotes: 0