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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Data won't send to DB

    This is a pretty basic form but for some reason the results won't send to the database. I know the DB connection is good because the technician drop down box gets the data from the DB. That is the one field that won't send data out either. I have added the print() to check it and all fields are being sent except the technician field.(only one obtaining data from DB) Any ideas why the technician field won't work and why it won't send data to the DB

    Code:
    <?php
    include_once "myconnect.php";
    ?>
    <?php
    /* WorkOrder.php */
    if (!isset($_POST['submit'])){
    ?>
    <head>
    <link href="ge.css" rel="stylesheet" type="text/css">
    <title>GE Work Order</title>
    </head>
    <form action="" method="post">
    <div>Work Order #:<input type="text" size="12" maxlength="12" name="order">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <?php
    $result = mysql_query("SELECT * FROM employees") or die(mysql_error());
    echo "Technician Name:<select name='tech'>";
    while($row=mysql_fetch_array($result))
    {
      echo"<option value=\"{$row[Employee_ID]}\">{$row[First_Name]}  {$row[Last_Name]}</option>";
    }
      echo"</select>";
    
    ?></select>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Site:<select name="Site">
    <option value="No Selection Made">Select Site</option>
    <option value="Burdett">Burdett</option>
    <option value="Coaldale">Coaldale</option>
    <option value="Fort McLeod">Fort McLeod</option>
    <option value="Taber">Taber</option>
    </select>
    </div> <BR>
    <div> Unit Serial #:<input type="text" size="10" maxlength="10" name="Serial">
    &nbsp;&nbsp;
    Unit Hours:<input type="text" size="6" maxlength="6" name="Hours">
    &nbsp;&nbsp;
    Unit Starts:<input type="text" size="6" maxlength="6" name="Starts">
    &nbsp;&nbsp;
    &nbsp;&nbsp; Severity:<select name="Severe">
    <option value="No Selection Made">Please Select Level</option>
    <option value="Low Level">Low Level</option>
    <option value="A.S.A.P.">A.S.A.P.</option>
    <option value="Immediate Attention">Immediate Attention</option>
    <option value="Severe">Severe</option>
    </select>
    &nbsp;&nbsp; Safety:<select name="Safe">
    <option value="No Selection Made">Please Select Level</option>
    <option value="Low Risk of Injury">Low Risk of Injury</option>
    <option value="Medium Risk of Injury">Medium Risk of Injury</option>
    <option value="High Risk of Injury">High Risk of Injury</option>
    <option value="Injury has Occurred">Injury has Occurred</option>
    </select>
    </div> <BR>
    <div>Description of Issue:<BR><textarea rows="4" name="Issue" cols="116"></textarea>
    </div><BR>
    <div>Possible Resolution<BR><textarea rows="4" name="Resolve" cols="116"> </textarea>
    </div><BR>
    <div>List of Parts Required (known at this time):</div>
    <div><input type="text" size="155" maxlength="155" name="PartsA"><BR>
    <input type="text" size="155" maxlength="155" name="PartsB"><BR>
    <input type="text" size="155" maxlength="155" name="PartsC"><BR>
    <input type="text" size="155" maxlength="155" name="PartsD"><BR>
    <input type="text" size="155" maxlength="155" name="PartsE"><BR>
    <input type="text" size="155" maxlength="155" name="PartsF"><BR>
    <input type="text" size="155" maxlength="155" name="PartsG"><BR>
    </div><BR>
    
    <div>Request for Assistance:<BR><textarea rows="4" name="Assist" cols="116"></textarea>
    </div><BR><BR>
    
    <p align="center"><input type="submit" name="Submit" value="Submit Work Order">  <BR>
    <p align="center"><input type="reset" name="Submit" value="Clear Form">
    </form>
    <?php
    print_r($_POST);
    ?>
    <?php
    } else {
    $Technician = $_POST[‘Tech’];
    $Site = $_POST[‘Site’];
    $Serial = $_POST[‘Serial’];
    $Hours = $_POST[‘Hours’];
    $Starts = $_POST[‘Starts’];
    $Issue = $_POST[‘Issue’];
    $Resolution = $_POST[‘Resolve’];
    $Assistance = $_POST[‘Assist’];
    $PartsA = $_POST[‘PartsA’];
    $PartsB = $_POST[‘PartsB’];
    $PartsC = $_POST[‘PartsC’];
    $PartsD = $_POST[‘PartsD’];
    $PartsE = $_POST[‘PartsE’];
    $PartsF = $_POST[‘PartsF’];
    $PartsG = $_POST[‘PartsG’];
    $Safety = $_POST[‘Safe’];
    $Severity = $_POST[‘Severe’];
    mysql_query("INSERT INTO 'work order'(Technician, Site, Serial, Hours, Starts, Issue, Severity, Resolution, Assistance,
    PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG, Safety,) VALUES ('$Technician', '$Site', '$Serial',
    '$Hours', '$Starts', '$Issue', '$Severity', '$Resolution', '$Assistance','$PartsA', '$PartsB', '$PartsC', '$PartsD',
    '$PartsE', '$PartsF', '$PartsG', '$Safety')");
    echo "Your Work Order Has Been Successfully Submitted!";
    }
    ?>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    when queries fail, it's immensely useful to know exactly what it is that is sent to the database.
    So, whenever you have mysql_query(), expand it to be something like:
    PHP Code:
    $query='INSERT INTO '//etc.
    mysql_query($query) or die (mysql_error().$query); 
    then, if you're still stuck, you can post the error message and the actual query to mysql forums, so people wanting to help you don't have to wade through lines and lines of probably irrelevant php and html.

    Does the technician happen to have an ' in his name? (good old mr O'Reilly perhaps?)
    All data going into mysql should first be put through the escaping function mysql_real_escape_string()
    http://php.net/mysql-real-escape-string

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am getting the successful sent page when I try it on my local server/db, but when i check the db the results are not there. I am not getting an error showing up at all.

    I can't figure out what is happening that it won't actually make it to the database. On line 6 I had a capital letter missing which has been fixed, and that is why i now get the success page.

    ken

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You're getting the success message becuase you are printing it regardless
    You have single quotes around your table name, which should be removed + you have a comma after your last field name in your column listing. As suggested by GJay add mysql_error() as well(which probably would've pointed these out for you).

    Code:
    $result = mysql_query("INSERT INTO 'work order'(Technician, Site, Serial, Hours, Starts, Issue, Severity, Resolution, Assistance,
    PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG, Safety,) VALUES ('$Technician', '$Site', '$Serial',
    '$Hours', '$Starts', '$Issue', '$Severity', '$Resolution', '$Assistance','$PartsA', '$PartsB', '$PartsC', '$PartsD',
    '$PartsE', '$PartsF', '$PartsG', '$Safety')") or die(mysql_error());
    if($result)
    {
       echo "Your Work Order Has Been Successfully Submitted!";
    }
    else
    {
       echo 'Something went wrong';
    }
    Good luck;


  •  

    Posting Permissions

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