Jump to content

Form is insering null records in DB


numan82

Recommended Posts

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'];?>">

Link to comment
Share on other sites

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";

  }

 

?>

Link to comment
Share on other sites

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";
    }

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.