How to insert data using php & MySql
Insert Value In Mysql using php form
Many ways to use Insert data using php in mysql database but today we discuss
Core Php method.It is a basic and easy way to learn php with mysql.
We just Create a HTML page and form.
We just Create a HTML page and form.
Explanation
- first we create a html page and save into htdocs as a index.php.
- Than create a connection with your database .
- Make two input field and one submit button.
- Write the accurate name of your inputs fields and PHP variables e.g $_POST['value1'].
- Than Run this code with connection .
- for connection check another article .
Html Form
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<style >
</style>
</head>
<body>
<form method="post" action="index.php">
<input type="text" name="value1">
<input type="text" name="value2">
<input type="submit" name="submit" Value="Ok!">
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<style >
</style>
</head>
<body>
<form method="post" action="index.php">
<input type="text" name="value1">
<input type="text" name="value2">
<input type="submit" name="submit" Value="Ok!">
</form>
</body>
</html>
we get Post Values from (HTML FORM)
if(isset ($_POST['submit'])){
$a=$_POST['Value1'];
$b=$_POST['Value2'];
$q="INSERT INTO (TABLE NAME) (col name1,col name2(in database)) VALUES('$a','$b')";
$run=mysql_query($q);
}
if(isset ($_POST['submit'])){
$a=$_POST['Value1'];
$b=$_POST['Value2'];
$q="INSERT INTO (TABLE NAME) (col name1,col name2(in database)) VALUES('$a','$b')";
$run=mysql_query($q);
}
col name: mean you should write name of your database column.
$a,$b,$q,$run: is variable its not necessary but its good habit to store every value in variable.
for any query about my post please comment here below.
Keep Visiting this blog for more helpful article.
Regards (haider ali uppal(software Engineer))
No comments:
Post a Comment