Jump to content

Form data not being entered into MYSQL Database


drakecai

Recommended Posts

I have deleted mysql info for safety reasons.

 

Here are the two webpage's codes i'm using right now

 

menu.php

<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}

?>

<html><title>ChronoServe - Saving Time</title>
<link href="style.css" rel="stylesheet" type="text/css">
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="container">
  <tr>
    <td>
    <table width="335px" height="50%" border="1" align="center" cellpadding="0" cellspacing="0" class="centered">
      <tr>
        <td>
              <form method="post" action="insertvalues.php">
        <table width="100%" border="0" align="center" cellpadding="3" cellspacing="10">
      <tr>
        <td colspan="2"><div align="center" class="font2">Activation Information</div></td>
      </tr>
      <tr>
        <td colspan="2"></td>
      </tr>
      <tr>
        <td width="40%" class="font3">First Name :</td>
        <td width="60%">          <div align="center">
            <input name="firstname" type="text" class="font3" id="firstname" maxlength="25" />
            </div></td>
      </tr>
      <tr>
        <td class="font3">Last Name :</td>
        <td>          <div align="center">
            <input name="lastname" type="text" class="font3" id="lastname" maxlength="25" />
            </div></td>
      </tr>
      <tr>
        <td height="28" class="font3">Phone Number :</td>
        <td>          <div align="center">
            <input name="pnumber" type="text" class="font3" id="pnumber" maxlength="10" />
            </div></td>
      </tr>
      <tr>
        <td class="font3">Personnel Activated :</td>
        <td>          <div align="center">
            <input name="numberactivated" type="text" class="font3" id="numberactivated" maxlength="3" />
            </div></td>
      </tr>
      <tr>
        <td height="37" colspan="2"></td>
      </tr>
      <tr>
        <td colspan="2"><div align="center">
          <input name="submit" type="Submit" class="font3" value="Submit" />
        </div>
       </td>
      </tr>
    </table>
     </form></td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</body>
</html>

 

insertvalues.php

<?php
if(isset($_POST['Submit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$pnumber = $_POST['pnumber'];
$numberactivated = $_POST['numberactivated'];

mysql_connect ("deleted", "deleted", "deleted") or die ('Error: ' . mysql_error());
mysql_select_db ("deleted");

$query = "INSERT INTO disney_database (id, firstname, lastname, pnumber, numberactivated, date) VALUES ('NULL', '".$firstname."', '".$lastname."', '".$pnumber."', '".$numberactivated."', 'NULL')";

mysql_query($query) or die('Error updating database');
header("location:menu.php");
echo "Database Updated With: ".$firstname."" - "".$lastname."" - "".$pnumber."" - "".$numberactivated."";
}
else {
echo "Database Error"
{
?>

 

Here is my problem. I set a one <form> on every form field I have including the submit button. Now whenever I press the submit button it redirects to insertvalues.php which it should be doing. In insertvalues i told it to query the form data and post it into my database's table. Its not doing that and tells me that it has a database error which i set it to tell me if something goes wrong. Anyone can help me? BTW I can manually query in the information using sql with phpmyadmin.

 

so can someone please review my code for me? thanks big help!

 

You can see what is happening.

Visit www.chronoserve.com

 

The username and password are "admin"

Link to comment
Share on other sites

Thank you pawn, I am guess my stubbornness caused this failure. Thank you so much guys :D

 

I have one more questions, is there anyway I can make mysql delete the information i just inserted everyday? or every few hours? I want it to be automated.

 

 

 

 

Link to comment
Share on other sites

Write a simple script to delete what you want, e.g.

 

<?php
$sql = "DELETE * FROM table";
if(!$query = mysql_query($sql)) {
    error_log("Cronjob failed on line ".__LINE__."! ".mysql_error());
}
?>

Because you won't be executing the script directly, but running it automatically, it's important to log errors. To run the script every few days or hours, you will need to use crontab. Google is your friend.

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.