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
https://forums.phpfreaks.com/topic/81331-form-is-insering-null-records-in-db/
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";

  }

 

?>

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

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.