How To Store Data In Sql Database In Php
I have created register form using php and jquery. I need to store input details to sql database. I created config.php and included in index.php and submit.php file. But still didn
Solution 1:
Thats not the way to do it. You have to use an INSERT statement, not SELECT.
Try the following example:
You have to change the code based on your database structure. In here i just assume there's a table called table and there are 3 fields.
<?php$stmt = $con->prepare("INSERT INTO table VALUES (:one, :two, :three)");
// values to enter$data = array(
'one' => 'value one',
'two' => 'value two',
'three' => 'value tree'
);
if ($stmt->execute($data)) echo"Inserted successfully";
Solution 2:
That's not the way to get it done.
$stmt = $db->prepare("INSERT INTO ".$table." ('column1', 'column2') VALUES ('value1', 'value2');");
$stmt->execute();
But I suggest you bind the query first to avoid SQL injection.
Post a Comment for "How To Store Data In Sql Database In Php"