Page 1 of 1

form submission error

Posted: Sun Sep 27, 2009 8:02 am
by lipun4u
I want to get two input from the user and insert into the database.

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>
 
before the form submission it shows following error ...

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 :  
After form submission, it gives following error

Code: Select all

 
Forbidden
 
You don't have permission to access /< on this server.
Please help me to rectify this !!!

Re: form submission error

Posted: Sun Sep 27, 2009 8:06 am
by jackpf
Do you have short tags enabled?

Re: form submission error

Posted: Sun Sep 27, 2009 9:14 am
by lipun4u
I changed this to....

Code: Select all

 
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
now its working...

Re: form submission error

Posted: Sun Sep 27, 2009 9:18 am
by lipun4u
How to enable short tags ???

Re: form submission error

Posted: Sun Sep 27, 2009 11:07 am
by jackpf
Change it to "on" in php.ini.

Or use a htaccess php flag.

Or ini_set().

Re: form submission error

Posted: Sun Sep 27, 2009 12:10 pm
by lipun4u
thank you :drunk: