i have tried some but i dont know where i get stucked
<html>
<head>
<title>Login</title>
</head>
<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>
</form>
</html>
<?php
$host="localhost";
$username="root";
$password="";
$db_name="sample_ramki";
$tbl_name="pcs_employee";
// 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
$name="Ramki";
$lastname="glitz";
// Insert data into mysql
$sql="INSERT INTO pcs_employee(name, description)VALUES('$name', '$lastname')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
}
else {
echo "ERROR";
}
?>
Answers
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
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "
" . $e->getMessage();
}
$conn = ;
?>
Hope this help.
@pallav
February 07,2017 At 01:27 PM
Solution #1