fnan
MIS
- Apr 3, 2011
- 2
My laptop is installed xp professional service pack-2. I installed wampserver-2 to test my page in localhost before the actual release of it. I create a form and php code which will link it to my mysql table. Then to read the users comment from the form. Then When I tried it in localhost I receive this message: "Apache HTTP Server has encountered a problem and need to close"
This is the php code I writefile name: demo.php)
And of course I have a database named forms1 and a table named table-demo
This is the php code I writefile name: demo.php)
Code:
<?php
define('DB_NAME', 'forms1');
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['fname'];
$value2 = $_POST['lname'];
$value3 = $_POST['comment'];
$sql = "INSERT INTO table-demo VALUES('$value','$value2','$value3')";
if(mysql_query($sql)){
echo "one record addedd scucessfully";
}
mysql_close();
?>
</code>
And this is the form code I write (file name demo-from.php)
<code>
<html>
<head>
<title>This is the demo-form.php</title>
</head>
<body>
<h1>Fill the form</h1>
<form action="demo.php" method="post">
<p>First Name:<input type="text" name="fname" /></p>
<p>Last Name:<input type="text" name="lname" /></p>
<p>comment Box</p>
<textarea rows="8" cols="30" name="comment"></textarea>
<input type="submit" value="send" />
</form>
</body>
</html>