[ why insert query result doesn't show in database? ]
$db = new PDO("mysql:host=$host;dbname=$dbname",$user,$password) ;
$insert = $db->query("INSERT INTO register (First_name,Last_name) VALUES ('ram','shyam')") ;
if($insert) {
echo "true" ;
} else {
$db->errorCode() ;
echo "false" ;
}
it give output true but there is no entry in database .
Answer 1
If entries don't show up on the same host with the same credentials and database, and your query does work, the driver says, the entries were successfully inserted, then your database is most probably configured in non-autocommit mode. Check this output:
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF |
+---------------+-------+
1 row in set (0.00 sec)
You need to turn it back on (default) or add a COMMIT
statement (with PDO). BTW, you can SELECT
the uncommitted entry in the same connection:
var_dump($db->query('select * from register')->fetchAll());
Answer 2
please you can try this
<?php
function Conect()
{
if (!($link=mysql_connect("localhost","root","")))
{
echo "error to connect to database.";
exit();
}
if (!mysql_select_db("database_name",$link))
{
echo "Error to select database.";
exit();
}
return $link;
}
$link=Conect();
$value1=$_POST['value1'];
$value2=$_POST['value2'];
$value3=$_POST['value3'];
$query="insert into database.tablename(field1,field2,field3)".
"values('$value1','$value2','$value3')";
$action =mysql_query($query,$link);
if (!$action) {
die('has not insert: ' . mysql_error());
?> <font color="blue" face="arial" size="4">not insert</font> <?php
}
?> <font color="blue" face="arial" size="4">was insert</font> <?php
mysql_close($link);
is a little example