php mysql function insert into table code example
Example 1: php insert array into mysql table
$matstring=implode("','",$matrix[1]);
mysql_query('INSERT INTO Australia (Price, Company, Days, Weight) VALUES ('$matstring')');
Example 2: insert php code
<?php
$host = "localhost";
$username = "username";
$pass = "";
$db="furniture";
$conn=mysqli_connect($host,$username,$pass,$db);
if(!$conn){
die("Data connection error");
}
?>
Example 3: how to insert data in mysql using oop php
--
-- Table structure for table `tbl_posts`
--
CREATE TABLE IF NOT EXISTS `tbl_posts` (
`post_id` int(11) NOT NULL AUTO_INCREMENT,
`post_title` varchar(150) NOT NULL,
`post_desc` text NOT NULL,
PRIMARY KEY (`post_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `tbl_posts`
--
Example 4: how to insert data from a from in html to phpmyadmin using php
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form - PHP/MySQL Demo Code</title>
</head>
<body>
<fieldset>
<legend>Contact Form</legend>
<form name="frmContact" method="post" action="contact.php">
<p>
<label for="Name">Name </label>
<input type="text" name="txtName" id="txtName">
</p>
<p>
<label for="email">Email</label>
<input type="text" name="txtEmail" id="txtEmail">
</p>
<p>
<label for="phone">Phone</label>
<input type="text" name="txtPhone" id="txtPhone">
</p>
<p>
<label for="message">Message</label>
<textarea name="txtMessage" id="txtMessage"></textarea>
</p>
<p> </p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
</fieldset>
</body>
</html>