Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Data does not go into database

    Hello I have a employee training database and need to be able to add and update employees to it. I had it working and made a few changes and now it doesn't insert data into the database and i can't figure out what happened. (all I did was add some more fields) I get no error just a blank white page. First I need to get it to add a new employee working again.
    Here is what I have.

    TrainingDataBaseAdd.php File:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <
    html xmlns="http://www.w3.org/1999/xhtml">

    <
    head>

        <
    title>ADD a NEW EMPLOYEE Training Record</title>
        
        <
    meta name="keywords" content="HTML, CSS, PHP" />    </meta>

        <
    link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
        
    </
    head>

    <
    body>

    <
    br>
    <
    br>

    <!--  
    ADD NEW EMPLOYEE and TRAINING -->

    <
    h1 align="center"><u><strong><font face="arial">Add New Employee Training Record</font></strong></u></h1>

    <
    br>

    <
    h3 align="center"><strong><font face="arial">PLEASE FILL IN <u>EVERY</uBOX</font></strong></h3>

    <
    br>
    <
    h2 align="center"><u><strong><font face="arial">Add New Employee Information</font></strong></u></h2>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter a EMPLOYEE NUMBER:
    <
    input type="text" name="Emp_Id" />

    <
    br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter a FIRST NAME: <input type="text" name="FirstName" />

    <
    br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter a LAST NAME: <input type="text" name="LastName" />

    <
    br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter a DEPARTMENT: <input type="text" name="Dept" />

    <
    br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter a SHIFT: <input type="text" name="Shift" />

    <
    br>
    <
    br>
    <
    br>
    <
    h2 align="center"><u><strong><font face="arial">Add New Quality Training</font></strong></u></h2>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter the date of ISO 13485 Internal Audit Training: <input type="text" name="iso13485" />  example:  mm/dd/yyyy OR for NO Training

    <br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter the date of ISO 9001 Training: <input type="text" name="iso9001" />  example:  mm/dd/yyyy OR for NO Training

    <br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter the date of QUALITY Training: <input type="text" name="quality" />  example:  mm/dd/yyyy OR for NO Training

    <br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter the date of DHR Training: <input type="text" name="dhr" />  example:  mm/dd/yyyy OR for NO Training

    <br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter the date of ORIENTATION: <input type="text" name="orientation" />  example:  mm/dd/yyyy OR for NO Training

    <br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter the date of WORK INSTRUCTIONS Training: <input type="text" name="workinstructions" />  example:  mm/dd/yyyy OR for NO Training

    <br>
    <
    br>

    <
    form action="AddTraining.php" method="post">
    Please enter the date of 6S Training: <input type="text" name="6S" />  example:  mm/dd/yyyy OR for NO Training

    <br>
    <
    br>
    <
    br>
    <
    br>

    <
    center><input type="submit" value="Add New Employee"></center>
    </
    form>

    <
    br>
    <
    br>

    </
    body>

    </
    html
    Here is the AddTraining.php File:
    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title>Employee Has Been Added to Database</title>
        
    <meta name="keywords" content="HTML, CSS, PHP" />    </meta>
        
        <link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
        
    </head>

    <body>

    <div align="center">

    <br>

    <?php

    $con 
    mysql_connect("localhost","root","");
    if (!
    $con)
    {
    die(
    'Could not connect: ' mysql_error());
      }
      
    mysql_select_db("training_db"$con);
      
    // Employee Data Variables
        
    $Emp_Id $_POST['Emp_Id'];
        
    $FirstName $_POST['FirstName'];
        
    $LastName $_POST['LastName'];
        
    $Dept $_POST['Dept'];
        
    $Shift $_POST['Shift'];
        
    // Quality Data Variables     
        
    $iso13485 $_POST['iso13485']; 
        
    $iso9001 $_POST['iso9001']; 
        
    $quality $_POST['quality']; 
        
    $dhr $_POST['dhr'];     
        
    $orientation $_POST['orientation']; 
        
    $workinstructions $_POST['workinstructions'];
        $
    6S $_POST['6S'];     
      
    // Insert Data Into Database Tables

    mysql_query(INSERT INTO employee('Emp_Id'
       
    'FirstName',
       
    'LastName',
       
    'Dept',
       
    'Shift'
      
    )
    VALUES ('$Emp_Id',
       
    '$FirstName',
       
    '$LastName',
       
    '$Dept',
       
    '$Shift'
    ));

    mysql_query(INSERT INTO quality('Emp_Id'
       
    'iso1348',
       
    'iso9001',
       
    'quality',
       
    'dhr',
       
    'orientation',
       
    'workinstructions',
       
    '6S'
      
    )
    VALUES ('$Emp_Id',
       
    '$iso13485',
       
    '$iso9001',
       
    '$quality',
       
    '$dhr',   
       
    '$orientation',
       
    '$workinstructions',
       
    '$6S'   
    ));

    mysql_close($con);
      
    ?>

    <h3 align="center"><u><strong><font face="arial"><?php echo $FirstName." ".$LastName;
    ?>  Has Been Added to Database</font></strong></u></h3>

    <br>
    <br>

    </div>

    </body>

    </html>
    Thanks for any and all help.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,855
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    If you are not getting any error message, turn ON error reporting on your server.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Blank pages usually mean the function cannot load. I suspect it may be because you don't have a isset $_POST in your AddTraining.php

    Try this to see if anything changes. If it doesn't we will move to the next possible attempt.

    AddTraining.php

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title>Employee Has Been Added to Database</title>
        
    <meta name="keywords" content="HTML, CSS, PHP" />    </meta>
        
        <link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
        
    </head>

    <body>

    <div align="center">

    <br>

    <?php

    $con 
    mysql_connect("localhost","root","");
    if (!
    $con)
    {
    die(
    'Could not connect: ' mysql_error());
      }
      
    mysql_select_db("training_db"$con);
      if (isset(
    $_POST['submit'])) {
    // Employee Data Variables
        
    $Emp_Id $_POST['Emp_Id'];
        
    $FirstName $_POST['FirstName'];
        
    $LastName $_POST['LastName'];
        
    $Dept $_POST['Dept'];
        
    $Shift $_POST['Shift'];
        
    // Quality Data Variables     
        
    $iso13485 $_POST['iso13485']; 
        
    $iso9001 $_POST['iso9001']; 
        
    $quality $_POST['quality']; 
        
    $dhr $_POST['dhr'];     
        
    $orientation $_POST['orientation']; 
        
    $workinstructions $_POST['workinstructions'];
        $
    6S $_POST['6S'];     
      
    // Insert Data Into Database Tables

    mysql_query(INSERT INTO employee('Emp_Id'
       
    'FirstName',
       
    'LastName',
       
    'Dept',
       
    'Shift'
      
    )
    VALUES ('$Emp_Id',
       
    '$FirstName',
       
    '$LastName',
       
    '$Dept',
       
    '$Shift'
    ));

    mysql_query(INSERT INTO quality('Emp_Id'
       
    'iso1348',
       
    'iso9001',
       
    'quality',
       
    'dhr',
       
    'orientation',
       
    'workinstructions',
       
    '6S'
      
    )
    VALUES ('$Emp_Id',
       
    '$iso13485',
       
    '$iso9001',
       
    '$quality',
       
    '$dhr',   
       
    '$orientation',
       
    '$workinstructions',
       
    '$6S'   
    ));

    mysql_close($con);
      
    ?>

    <h3 align="center"><u><strong><font face="arial"><?php echo $FirstName." ".$LastName;
    }
    ?>  Has Been Added to Database</font></strong></u></h3>

    <br>
    <br>

    </div>

    </body>

    </html>
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Variables cannot start with a number:
    PHP Code:
    // Quality Data Variables      
        
    $iso13485 $_POST['iso13485'];  
        
    $iso9001 $_POST['iso9001'];  
        
    $quality $_POST['quality'];  
        
    $dhr $_POST['dhr'];      
        
    $orientation $_POST['orientation'];  
        
    $workinstructions $_POST['workinstructions']; 
        $
    6S $_POST['6S']; 
    Once that problem has been corrected, it will likely work as expected.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Fou-Lu you ROCK. I didn't even think about the variable starting with a number. Changed it work perfect. Thanks so much that was about to drive me crazy... Now on to the next challenge updating the tables.

  • #6
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    mysql_query(INSERT INTO employee('Emp_Id',
    'FirstName',

    Erm, mysql_query requiers a string not a word,

    E.G mysql_query("INSERT INTO `employee` (`Emp_Id`, `FirstName`)");

    Please notice the correct syntax you only use '' qotes for input ` for names ` is the key to the left of the one and a english/us/GB keyboard and ' is the second key in from the return Please learn syntax
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)

  • #7
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK I need to be able to update the records in the database. How I have it set up is you select the employee it update. Then goto the next page and it lists the employee records from the database. Change the record you need to and click submit and it SHOULD update the record. Everything works and looks as it should but when I check the database it doesn't update. Here are my php files

    Here is the postupdate.php file
    PHP Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

        <title>Updated EmployeeTraining Records</title>
        
    <meta name="keywords" content="HTML, CSS, PHP" />    </meta>
        
    </head>

    <body>

    <br>
    <br>

    <?php
    foreach($HTTP_POST_VARS as $varname => $value)
    $formVars[$varname]=$value;

    require_once(
    "config.php");

    $db1=mysql_connect($dbhost$dbuname$dbpass);
    mysql_select_db("training_db");

    echo 
    "Record updated&nbsp;<a href=\"TrainingUpdate.html\"> click here</a> to update another record<br>";

    $query="UPDATE `employee` SET ".

    "FirstName= \"".$formVars["FirstName"]."\",".
    "LastName= \"".$formVars["LastName"]."\",".
    "Dept= \"".$formVars["Dept"]."\"".
    "Shift= \"".$formVars["Shift"]."\"".

    "\" WHERE Emp_Id = \"".$formVars["EID"]."\"";

    mysql_query($query);
    mysql_close($db1);
    ?>

    </body>

    </html>
    Here is the TrainingUpdate.php file:
    PHP Code:
    <?php
    foreach($HTTP_POST_VARS as $varname => $value)
    $formVars[$varname]=$value;

    require_once(
    "config.php");

    $db1=mysql_connect($dbhost$dbuname$dbpass);
    mysql_select_db("training_db");

    $query="SELECT * FROM employee WHERE Emp_Id = \"".$formVars["EID"]."\"";

    $result=mysql_query($query);
    $row=mysql_fetch_array($result);
    $formVars = array();

    $formVars["FirstName"]=$row["FirstName"];
    $formVars["LastName"]=$row["LastName"];
    $formVars["Dept"]=$row["Dept"];
    $formVars["Shift"]=$row["Shift"];

    mysql_close($db1);
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

        <title>Existing Employee Training Records</title>
        
    <meta name="keywords" content="HTML, CSS, PHP" />    </meta>
            
    </head>

    <body> 

    <br>
    <br>

    <div align="center">
    <form method="post" action="postupdate.php">

    <table>

    <col span="1" align="right">

    <tr>
    <td><font color="blue">First Name:</font></td>
    <td><input type="text" name="FirstName" 
    value="<? echo $formVars["FirstName"]; ?>" size=50></td>
    </tr>
    <tr>
    <td><font color="blue">Last Name:</font></td>
    <td><input type="text" name="LastName" 
    value="<? echo $formVars["LastName"]; ?>" size=50></td>
    </tr>
    <tr>
    <td><font color="blue">Department:</font></td>
    <td><input type="text" name="Dept" 
    value="<? echo $formVars["Dept"]; ?>" size=50></td>
    </tr>
    <tr>
    <td><font color="blue">Shift:</font></td>
    <td><input type="text" name="Dept" 
    value="<? echo $formVars["Shift"]; ?>" size=50></td>
    </tr>

    </table>

    <br>

    <input type="submit" value="Submit">
    </form>
    </div>

    </table>

    <br>

    <input type="submit" value="Submit">

    <br>
    <br>

    </form>

    <br>
    <br>

    </div>

    </body>

    </html>
    Thanks for all the help

  • #8
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Good catch fou lu, I also forgot variables can't start with numbers.

    Um I believe your query is suppose to be like this.

    PHP Code:
    $query = ("UPDATE `employee` SET FirstName=".$formVars["FirstName"].",
    LastName="
    .$formVars["LastName"].",Dept=".$formVars["Dept"]."Shift=".$formVars["Shift"]." WHERE Emp_Id = '".$formVars["EID"]."'"); 
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •