numan82 Posted December 12, 2007 Share Posted December 12, 2007 hi to all, I am using isset() function to set the form variables, but it isn't working. here is the piece of code if(isset($_REQUEST['submit'])) { $desc = $_REQUEST['desc']; $date = $_REQUEST['date']; $amount = $_REQUEST['amount']; $query ="INSERT INTO expenses_daily(exp_desc,exp_date,exp_amount) VALUES('$desc','$date','$amount')"; $result = mysql_query($query); if(!$result) { echo "Unable to insert record"; exit(); } else{ echo "record Added"; } } in the form action I am using <form id="form1" name="form1" method="post" action="<? $_SERVER['PHP_SELF'];?>"> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 12, 2007 Share Posted December 12, 2007 post your entire form Quote Link to comment Share on other sites More sharing options...
trq Posted December 12, 2007 Share Posted December 12, 2007 isset does not set variables, all your code does is simply checks if the form was submitted. Take a look at empty and check all posted fields. Quote Link to comment Share on other sites More sharing options...
numan82 Posted December 12, 2007 Author Share Posted December 12, 2007 Here is complete form! cheers too! <td valign="top"><form id="form1" name="form1" method="post" action="expenses.php"> <table border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <th valign="top" scope="row"><div align="left">Expense Description:</div></th> <td valign="top"><label> <textarea name="desc"></textarea> </label></td> </tr> <tr> <th valign="top" scope="row"><div align="right">Date:</div></th> <td valign="top"><label> <input type="text" name="date" size=20><td><a href="javascript:showCal('Calendar1')"><img src="images/calbtn.gif" border="0"/></a> </td> </tr> <tr> <th valign="top" scope="row"><div align="right">Amount:</div></th> <td valign="top"><label> <input name="amount" type="text"/> </label></td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"> </th> <td><label> <input type="submit" name="Submit" value="Add" onclick="return checkForm();"/> </label></td> </tr> </table> </form> </td> </tr> <tr> <td> </td> </tr> </table><? if(isset($_REQUEST['submit'])) { $desc = $_REQUEST['desc']; $date = $_REQUEST['date']; $amount = $_REQUEST['amount']; $query ="INSERT INTO expenses_daily(exp_desc,exp_date,exp_amount) VALUES('$desc','$date','$amount')"; $result = mysql_query($query); if(!$result) { echo "Unable to insert record"; exit(); } else{ echo "record Added"; } } ?> Quote Link to comment Share on other sites More sharing options...
farkewie Posted December 12, 2007 Share Posted December 12, 2007 I would also only use $_GET or $_POST not $_REQUEST unless you have data coming from two different methods, Quote Link to comment Share on other sites More sharing options...
farkewie Posted December 12, 2007 Share Posted December 12, 2007 but as a quik fix you can if(isset($_REQUEST['submit'])) to if(isset($_POST['Submit'])) php is case sensitive, EDIT: <?php if (isset($_POST['Submit'])) { if (empty($_POST['desc'])) { echo "desc empty"; exit; } if (empty($_POST['date'])) { echo "date empty"; exit; } if (empty($_POST['amount'])) { echo "amount empty"; exit; } $query = "INSERT INTO expenses_daily(exp_desc,exp_date,exp_amount) VALUES('" . $_POST['desc'] . "','" . $_POST['date'] . "','" . $_POST['desc'] . "')"; if (!$result = mysql_query($query)) { echo "Unable to insert record" . mysql_error(); exit(); } else { echo "record Added"; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.