Wednesday, November 21, 2018

How can insert the data in mysql using php?

step 1:- Firstly create a database name & secondly create a table in MySQL.

step 2:-After that create a table structure eg. Column Name1 , Coulmn Name2 , Coulmn NameN...

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//insert data in database using submit button request
if (isset($_REQUEST['submit']))
{
$n=$_REQUEST['name'];
$p=$_REQUEST['pass'];
$g=$_REQUEST['gender'];
$h=$_REQUEST['chk'];
if ($h)
{
$ch=implode(",",$h);//implode is a string function that are implode a multipal array value like chk[];
}
$ins="insert into user(name,pass,gender,hobby) values('$n','$p','$g','$ch')";
$ex=mysql_query($ins);
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
    <tr>
        <td>name</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
        <td>password</td>
            <td><input type="text" name="pass"></td>
        </tr>
        <tr>
        <td>male</td>
            <td><input type="radio" name="gender" value="male">male<input type="radio" name="gender" value="female">female</td>
        </tr>
        <tr>
        <td>hobby</td>
            <td><input type="checkbox" name="chk[]" value="cricket">cricket<input type="checkbox" name="chk[]" value="hockey">hockey</td>
        </tr>
        <tr>
        <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>

Related Posts:

  • PHP Error Types - And their Differences Notices : It will be shown in below condition like if we will try to access a variable which is not defined yet. it will not stop script execution. Warning : It will be shown while using include(), it will not a… Read More
  • Delete data using core php ? <?php if(isset($_REQUEST['del_id'])) {    $del=$_REQUEST['del_id'];     $de="delete from user where uid='$del'";     $ex=mysql_query($del);     header("lo… Read More
  • How can edit the data in MySql using core php ? form.php <?php mysql_connect("localhost","root",""); mysql_select_db("project"); //edit if (isset($_REQUEST['edit_id'])) { $eid=$_REQUEST['edit_id']; $select="select * from tbl_user where id='$eid' ";… Read More
  • How can insert the data in mysql using php? step 1:- Firstly create a database name & secondly create a table in MySQL. step 2:-After that create a table structure eg. Column Name1 , Coulmn Name2 , Coulmn NameN... <?php mysql_connect("localhost","root"… Read More
  • How can fetch the records in MySQL using php? Create  a  form.php  for the inserting data & view.php for the fetching data in the  Data base Fetching Records  in the database using Mysql_fetch_array ( ) Function. Select Command use for the … Read More

0 comments:

Post a Comment