Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
4
Reply
How to connecting to MySQL database from PHP designer 8
Mike abban
Jun 24 2015 2:27 PM
1.7k
Reply
i am new to PHP. i am trying to create a page that will input data into
mysql database. i created a database called 'form1' and a table called 'demo'
with 2 columns ID(auto Increase) and input1(varchar).
i created a html file called demo-form with this codes
!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="gencyolcu" />
<title>Untitled 2</title>
</head>
<body>
<form action="demo.php" method="post" />
<p>Input 1: <input type="text" name="input1" /> </p>
<input type="submit" value="Submit" />
</form>
</body>
</html>
and a PHP file called 'demo' with code
php
/**
* @author gencyolcu
* @copyright 2015
*/
define('DB_NAME', 'form1');
define('DB_USER','root');
define('DB_PASSWORD','');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use' . DB_NAME . ':' . mysql_error());
}
echo 'Connected successfully';
$value = $_POST['input1'];
$sql = "INSERT INTO demo (input1) VALUES ('$value')";
if (!mysql_query($sql)) {
die('Error: '. mysql_error());
}
mysql_close();
but after running the demo-form in my browser and i enter text into the
textbox and click submit.
no action takes please. dont really no what the problem is. please help me out
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
how to convert any wordpress url into json format data.
upload csv file mapping with database table