here is the code...
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
if(!$_POST['submit']) {
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Item name : <input type="text" name="name" />
Item price : <input type="text" name="price" />
<input type="submit" name="submit" />
</form>
<?php
}
else {
$name = (trim($_POST['name']) =='')? die('ERROR: Enter a name') : mysql_escape_string($_POST['name']);
$price = (trim($_POST['price'] == '') || !is_numeric($_POST['price'])) ? die("Error: Enter price") : $_POST['price'];
$con = mysql_connect('localhost', 'root', 'iitiit') or die ('Unable to connect');
mysql_select_db('db2') or die('Unable to select database');
$query = "insert into items (itemname, itemprice) values ('$name', '$price')";
$result = mysql_query($query) or die("Error in query: $query. " . mysql_error());
echo "New record inserted with ID " . mysql_insert_id() . "<br\>\n";
echo mysql_affected_rows() . ' record(s) affected';
mysql_close($con);
}
?>
</body>
</html>
Code: Select all
Notice: Undefined index: submit in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ins1.php on line 10
Item name : Item price : Code: Select all
Forbidden
You don't have permission to access /< on this server.