Jump to content

Recommended Posts

I tried to solve this on my own but I can't seem to figure out what is wrong. I have a form to submit data into a database - when I submit the form, I do not get an error message but the data does not go into the database. Any help would be greatly appreciated. See code below ...

<?
require_once('./Connections/db.php');
?>
<html> 
<head> 
<title>Add to detention</title> 
</head> 
<body>
<?php
if ($_POST['submit']) 
{ 
// data from form
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$date = $_POST['date'];
$days = $_POST['days'];
$reason = $_POST['reason'];
$comments = $_POST['comments'];


# THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE 
$query ="INSERT INTO detention (detentionID, fname, lname, date, days, reason, comments) VALUES (NULL, '$fname', '$lname', '$date', '$days', '$reason', '$comments')";
$result = mysql_query($query) or die ('Data not entered');
echo 'All set'; 
}
else
{
?>

<h3>Add a student to detention database:</h3>
<p> </p>

<form action=""   method="POST" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">First name:</td>
      <td><input type="text" name="fname" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Last name:</td>
      <td><input type="text" name="lname" value="" size="32" /></td>
    </tr>

    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Date:</td>
      <td><input type="text" name="date" value="<?php echo date("Y-m-d"); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Reason for detention:</td>
      <td><textarea name="reason" cols="50" rows="5"></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Number of assigned detention days:</td>
      <td><input type="text" name="days" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Comments:</td>
      <td><textarea name="comments" cols="50" rows="5"></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"> </td>
      <td><input type="submit" value="submit" /></td>
    </tr>
  </table>
</form>
<?
}
?>

Link to comment
https://forums.phpfreaks.com/topic/137370-need-help-please/
Share on other sites

also

change

$query ="INSERT INTO detention (detentionID, fname, lname, date, days, reason, comments) VALUES (NULL, '$fname', '$lname', '$date', '$days', '$reason', '$comments')";

into

$query ="INSERT INTO detention (fname, lname, date, days, reason, comments) VALUES ('$fname', '$lname', '$date', '$days', '$reason', '$comments')";

 

if your detentionID is primary key, autoincrement

Link to comment
https://forums.phpfreaks.com/topic/137370-need-help-please/#findComment-717744
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.