how to store the values in database in runtime with php
0.00 (0 votes)

i have tried some but i dont know where i get stucked

<h3>Add details</h3>
<p> Welcome to our page</p>
<form action="trylog.php" method = "post">
  <label for="username">Username</label> <input type="username" id="usename" name="username"><br /><br />
  <label for="password">Password:</label> <input type="text" id="password" name="password"><br /><br />
  <button type = "submit">Login</button>



// Connect to server and select database.
mysql_connect("$host", "$username", "$password", "$db_name")or die("cannot connect");
mysql_select_db("sample_ramki")or die("cannot select DB");

// Get values from form

// Insert data into mysql
$sql="INSERT INTO pcs_employee(name, description)VALUES('$name', '$lastname')";

// if successfully insert data into database, displays message "Successful".
echo "Successful";
echo "<BR>";

else {
echo "ERROR";


06-02-2017 16:42:57


Solution #1

0.00 (0 votes)

Insert, update, delete from database is a very basic knowledge for a programmer. We can not provide you basic tutorials of programming but I can elaborate this with an example. See this example:

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $sql = "INSERT INTO MyGuests (firstname, lastname, email)
    VALUES ('John', 'Doe', '')";
    // use exec() because no results are returned
    echo "New record created successfully";
catch(PDOException $e)
    echo $sql . "<br>" . $e->getMessage();

$conn = null;

Hope this help.

Pallav Kumar
07-02-2017 13:27:12