Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    May 2011
    Posts
    9

    Unanswered: Form won't post to Database

    Hello, I have been trying for the last couple of days to get this to work and am unable to find my problem. I am just wondering if anyone would be able to help me with this.

    I have created a form and am trying to get it to post it's fields to an SQL database when submitted.

    I have created a file for the sql submission however it will not work, it is not displaying any errors when I try to submit the form and is just displaying a blank page.

    Any help would be greatly appreciated.

    My html form uses the POST method which sends to the following script which isn't working.

    Submit Script.

    PHP Code:
    <?php



    $username
    ="removed for forum";

    $password="removed for forum";

    $database="removed for forum";



    $Customer=$_GET['Customer'];

    $IWO=$_GET['IWO'];

    $Heat=$_GET['Heat'];

    $Start_Date=$_GET['Start_Date'];

    $Start_Time=$_GET['Start_Time'];

    $Start_Time_A=$_GET['Start_Time_A'];

    $Finish_Date=$_GET['Finish_Date'];

    $Finish_Time=$_GET['Finish_Time'];

    $Finish_Time_A=$_GET['Finish_Time_A'];

    $Source_Rack1=$_GET['Source_Rack1'];

    $Pipe_Nb1=$_GET['Pipe_Nb1'];

    $Product_Description1=$_GET['Product_Description1'];

    $Quantity1=$_GET['Quantity1'];

    $Cut_Size1=$_GET['Cut_Size1'];

    $Coupling1=$_GET['Coupling1'];

    $Finished_Rack1=$_GET['Finished_Rack1'];

    $Source_Rack2=$_GET['Source_Rack2'];

    $Pipe_Nb2=$_GET['Pipe_Nb2'];

    $Product_Description2=$_GET['Product_Description2'];

    $Quantity2=$_GET['Quantity2'];

    $Cut_Size2=$_GET['Cut_Size2'];

    $Coupling2=$_GET['Coupling2'];

    $Finished_Rack2=$_GET['Finished_Rack2'];

    $Source_Rack3=$_GET['Source_Rack3'];

    $Pipe_Nb3=$_GET['Pipe_Nb3'];

    $Product_Description3=$_GET['Product_Description3'];

    $Quantity3=$_GET['Quantity3'];

    $Cut_Size3=$_GET['Cut_Size3'];

    $Coupling3=$_GET['Coupling3'];

    $Finished_Rack3=$_GET['Finished_Rack3'];

    $Source_Rack4=$_GET['Source_Rack4'];

    $Pipe_Nb4=$_GET['Pipe_Nb4'];

    $Product_Description4=$_GET['Product_Description4'];

    $Quantity4=$_GET['Quantity4'];

    $Cut_Size4=$_GET['Cut_Size4'];

    $Coupling4=$_GET['Coupling4'];

    $Finished_Rack4=$_GET['Finished_Rack4'];

    $Source_Rack5=$_GET['Source_Rack5'];

    $Pipe_Nb5=$_GET['Pipe_Nb5'];

    $Product_Description5=$_GET['Product_Description5'];

    $Quantity5=$_GET['Quantity5'];

    $Cut_Size5=$_GET['Cut_Size5'];

    $Coupling5=$_GET['Coupling5'];

    $Finished_Rack5=$_GET['Finished_Rack5'];

    $Source_Rack6=$_GET['Source_Rack6'];

    $Pipe_Nb6=$_GET['Pipe_Nb6'];

    $Product_Description6=$_GET['Product_Description6'];

    $Quantity6=$_GET['Quantity6'];

    $Cut_Size6=$_GET['Cut_Size6'];

    $Coupling6=$_GET['Coupling6'];

    $Finished_Rack6=$_GET['Finished_Rack6'];

    $Source_Rack7=$_GET['Source_Rack7'];

    $Pipe_Nb7=$_GET['Pipe_Nb7'];

    $Product_Description7=$_GET['Product_Description7'];

    $Quantity7=$_GET['Quantity7'];

    $Cut_Size7=$_GET['Cut_Size7'];

    $Coupling7=$_GET['Coupling7'];

    $Finished_Rack7=$_GET['Finished_Rack7'];

    $Source_Rack8=$_GET['Source_Rack8'];

    $Pipe_Nb8=$_GET['Pipe_Nb8'];

    $Product_Description8=$_GET['Product_Description8'];

    $Quantity8=$_GET['Quantity8'];

    $Cut_Size8=$_GET['Cut_Size8'];

    $Coupling8=$_GET['Coupling8'];

    $Finished_Rack8=$_GET['Finished_Rack8'];

    $Source_Rack9=$_GET['Source_Rack9'];

    $Pipe_Nb9=$_GET['Pipe_Nb9'];

    $Product_Description9=$_GET['Product_Description9'];

    $Quantity9=$_GET['Quantity9'];

    $Cut_Size9=$_GET['Cut_Size9'];

    $Coupling9=$_GET['Coupling9'];

    $Finished_Rack9=$_GET['Finished_Rack9'];

    $Source_Rack10=$_GET['Source_Rack10'];

    $Pipe_Nb10=$_GET['Pipe_Nb10'];

    $Product_Description10=$_GET['Product_Description10'];

    $Quantity10=$_GET['Quantity10'];

    $Cut_Size10=$_GET['Cut_Size10'];

    $Coupling10=$_GET['Coupling10'];

    $Finished_Rack10=$_GET['Finished_Rack10'];

    $Reworked_No1=$_GET['Reworked_No1'];

    $Reworked_Reason1=$_GET['Reworked_Reason1'];

    $Reworked_Rectification1=$_GET['Reworked_Rectification1'];

    $Reworked_Date1=$_GET['Reworked_Date1'];

    $Reworked_No2=$_GET['Reworked_No2'];

    $Reworked_Reason2=$_GET['Reworked_Reason2'];

    $Reworked_Rectification2=$_GET['Reworked_Rectification2'];

    $Reworked_Date2=$_GET['Reworked_Date2'];

    $Reworked_No3=$_GET['Reworked_No3'];

    $Reworked_Reason3=$_GET['Reworked_Reason3'];

    $Reworked_Rectification3=$_GET['Reworked_Rectification3'];

    $Reworked_Date3=$_GET['Reworked_Date3'];

    $Reworked_No4=$_GET['Reworked_No4'];

    $Reworked_Reason4=$_GET['Reworked_Reason4'];

    $Reworked_Rectification4=$_GET['Reworked_Rectification4'];

    $Reworked_Date4=$_GET['Reworked_Date4'];

    $Reworked_No5=$_GET['Reworked_No5'];

    $Reworked_Reason5=$_GET['Reworked_Reason5'];

    $Reworked_Rectification5=$_GET['Reworked_Rectification5'];

    $Reworked_Date5=$_GET['Reworked_Date5'];

    $Reworked_No6=$_GET['Reworked_No6'];

    $Reworked_Reason6=$_GET['Reworked_Reason6'];

    $Reworked_Rectification6=$_GET['Reworked_Rectification6'];

    $Reworked_Date6=$_GET['Reworked_Date6'];

    $Reworked_No7=$_GET['Reworked_No7'];

    $Reworked_Reason7=$_GET['Reworked_Reason7'];

    $Reworked_Rectification7=$_GET['Reworked_Rectification7'];

    $Reworked_Date7=$_GET['Reworked_Date7'];

    $Reworked_No8=$_GET['Reworked_No8'];

    $Reworked_Reason8=$_GET['Reworked_Reason8'];

    $Reworked_Rectification8=$_GET['Reworked_Rectification8'];

    $Reworked_Date8=$_GET['Reworked_Date8'];

    $Reworked_No9=$_GET['Reworked_No9'];

    $Reworked_Reason9=$_GET['Reworked_Reason9'];

    $Reworked_Rectification9=$_GET['Reworked_Rectification9'];

    $Reworked_Date9=$_GET['Reworked_Date9'];

    $Reworked_No10=$_GET['Reworked_No10'];

    $Reworked_Reason10=$_GET['Reworked_Reason10'];

    $Reworked_Rectification10=$_GET['Reworked_Rectification10'];

    $Reworked_Date10=$_GET['Reworked_Date10'];

    $Delays=$_GET['Delays'];



    $conn1=mysql_connect($database,$username,$password);

    $mysql_query = ("INSERT INTO Casing_Job VALUES ('', '$Customer', '$IWO', '$Heat', '$Start_Date', '$Start_Time', '$Start_Time_A', '$Finish_Date', '$Finish_Time', '$Finish_Tima_A', '$Source_Rack1', '$Pipe_Nb1', '$Product_Description1', '$Quantity1', '$Cut_Size1', '$Coupling1', '$Finished_Rack1', '$Source_Rack2', '$Pipe_Nb2', '$Product_Description2', '$Quantity2', '$Cut_Size2', '$Coupling2', '$Finished_Rack2', '$Source_Rack3', '$Pipe_Nb3', '$Product_Description3', '$Quantity3', '$Cut_Size3', '$Coupling3', '$Finished_Rack3', '$Source_Rack4', '$Pipe_Nb4', '$Product_Description4', '$Quantity4', '$Cut_Size4', '$Coupling4', '$Finished_Rack4', '$Source_Rack5', '$Pipe_Nb5', '$Product_Description5', '$Quantity5', '$Cut_Size5', '$Coupling5', '$Finished_Rack5', '$Source_Rack6', '$Pipe_Nb6', '$Product_Description6', '$Quantity6', '$Cut_Size6', '$Coupling6', '$Finished_Rack6', '$Source_Rack7', '$Pipe_Nb7', '$Product_Description7', '$Quantity7', '$Cut_Size7', '$Coupling7', '$Finished_Rack7', '$Source_Rack8', '$Pipe_Nb8', '$Product_Description8', '$Quantity8', '$Cut_Size8', '$Coupling8', '$Finished_Rack8', '$Source_Rack9', '$Pipe_Nb9', '$Product_Description9', '$Quantity9', '$Cut_Size9', '$Coupling9', '$Finished_Rack9', '$Source_Rack10', '$Pipe_Nb10', '$Product_Description10', '$Quantity10', '$Cut_Size10', '$Coupling10', '$Finsihed_Rack10', '$Reworked_No1', '$Reworked_Reason1', '$Reworked_Rectification1', '$Reworked_Date1', '$Reworked_No2', '$Reworked_Reason2', '$Reworked_Rectification2', '$Reworked_Date2', '$Reworked_No3', '$Reworked_Reason3', '$Reworked_Rectification3', '$Reworked_Date3', '$Reworked_No4', '$Reworked_Reason4', '$Reworked_Rectification4', '$Reworked_Date4', '$Reworked_No5', '$Reworked_Reason5', '$Reworked_Rectification5', '$Reworked_Date5', '$Reworked_No6', '$Reworked_Reason6', '$Reworked_Rectification6', '$Reworked_Date6', '$Reworked_No7', '$Reworked_Reason7', '$Reworked_Rectification7', '$Reworked_Date7', '$Reworked_No8', '$Reworked_Reason8', '$Reworked_Rectification8', '$Reworked_Date8', '$Reworked_No9', '$Reworked_Reason9', '$Reworked_Rectification9', '$Reworked_Date9', '$Reworked_No10', '$Reworked_Reason10', '$Reworked_Rectification10', '$Reworked_Date10', '$Delays')");

    $resultset=@mysql_query($sql,$cnn) or die ("Error Occured <br> $sql";

    ?>
    All IDs are accurate in the html form.

    Thanks in advance.

    Kind Regards

    Jeremy Chequer
    TFG Servers

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    erm what is or shouldbe in $sql?
    have you tried looking at the MySQL error messages
    $resultset=@mysql_query($sql,$cnn) or die ("Error Occured <br>The SQL was:$sql<BR>The MySQL Error is:".mysql_errno().": ".mysql_error())";

    unless you know you will always have 10 worked No's your design is Im pretty certain not normalised

    offhand I'm expecting your problem to be unquoted text / char / varchar columns
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    May 2011
    Posts
    9
    When I submit the form no error comes up on the screen, however it still doesn't post to the sql database. I am able to provide the sql file that I created for the database as well if that would be of any help.

  4. #4
    Join Date
    May 2011
    Posts
    9
    Actually I found the error log the error that is coming up is

    [04-May-2011 16:54:27] PHP Parse error: syntax error, unexpected '"' in /home/tfg/public_html/ozcon/insert2.php on line 131


    Line 131 of the code is

    Code:
    $resultset=@mysql_query($sql,$cnn) or die ("Error Occured <br>The SQL was:$sql<BR>The MySQL Error is:".mysql_errno().": ".mysql_error())";

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    first off I reccommend you find out what error is being reported
    so
    make certain your are reporting all PHP errors using

    PHP Code:
    error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE); 
    note once you have got your code working you could / should reconsider that and decide if you want to turn errors off
    PHP Code:
    error_reporting(0); 
    see PHP: error_reporting - Manual for details

    next up you need to look at what your script is doing
    as far as I can see you don't assign a value to $sql

    im guessing you want to change

    PHP Code:
    $mysql_query = ("INSERT INTO Casing_Job VALUES... 
    to
    PHP Code:
    $sql = ("INSERT INTO Casing_Job VALUES... 
    I also suggest you examine the MySQL error message as recommended before
    then re run your script and see what happens

    as said before Im expecting it to be a problem with unquoted char / string / text values. numeric values shoudl be unquoted, string literals should be "quoted"

    eg
    Code:
    insert into mytable (ANumericColumn,ACharColumn) values (937,'Rudy Limeback');
    ..or using values from variables
    Code:
    $ID=937;
    $UserName='Rudy Limeback';
    $sql = 'insert into mytable (ANumericColumn,ACharColumn) values ($ID, "$UserName")';
    if you have quotes inside your text then you need to escape those by prepending another ' in front
    eg instead of 'Shamus O'Subcontractor' you should submit 'Shamus O\'Subcontractor'
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    There is a php function (mysql_real_escape_string) that escape characters your string for use in MySQL.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  7. #7
    Join Date
    May 2011
    Posts
    9
    Hello

    I have modified my code a couple of times now, however am still receiving the same error message when ever I submit the form.

    The code for the form can be viewed at Casing Job Sheet - Ozcon Industries Pty Ltd

    No matter what I change the error log is still saying the same thing.

    Also thanks for your help so far

  8. #8
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    First check I would perform is to display your INSERT SQL statement that you are attempting to run against the database. Then with this you can go directly to the database and issue the INSERT statement and debug it there before going back to change in the application.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by Jeremy Chequer View Post
    Hello

    I have modified my code a couple of times now, however am still receiving the same error message when ever I submit the form.

    The code for the form can be viewed at Casing Job Sheet - Ozcon Industries Pty Ltd

    No matter what I change the error log is still saying the same thing.

    Also thanks for your help so far
    so what code are you currently using?
    ..just the last three lines should do.....

    what MySQL error number and message are you getting?
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Just gone through your messages and found the following:

    $resultset=@mysql_query($sql,$cnn) or die ("Error Occured <br>The SQL was:$sql<BR>The MySQL Error is:".mysql_errno().": ".mysql_error())";

    The last " is not needed. Should be:

    $resultset=@mysql_query($sql,$cnn) or die ("Error Occured <br>The SQL was:$sql<BR>The MySQL Error is:".mysql_errno().": ".mysql_error());
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by it-iss.com View Post
    Just gone through your messages and found the following:

    $resultset=@mysql_query($sql,$cnn) or die ("Error Occured <br>The SQL was:$sql<BR>The MySQL Error is:".mysql_errno().": ".mysql_error())";

    The last " is not needed. Should be:

    $resultset=@mysql_query($sql,$cnn) or die ("Error Occured <br>The SQL was:$sql<BR>The MySQL Error is:".mysql_errno().": ".mysql_error());
    ..fairy snuff... it was air code after all
    I'd rather be riding on the Tiger 800 or the Norton

  12. #12
    Join Date
    May 2011
    Posts
    9
    Now I am having the following message come up when ever I press submit

    Error Occured
    The SQL was:INSERT INTO Casing_Job VALUES ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
    The MySQL Error is:0:

  13. #13
    Join Date
    May 2011
    Posts
    9
    Hello

    To make this easier on you guys who are trying to help me I have attached the form file and the insert file to this thread.
    Attached Files Attached Files

  14. #14
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    OK so that means that when you are building your SQL you are using null values, ie variables that are not set.
    if you query your database you will probably find blank rows inserted.

    so you need to find out what the problem is
    either they are not being set in the form or you are not pulling the correct values. my suspiscion is the latter
    looking at your forms code it looks like you are usign the POST method, so you need to use the POST global variables not the GET.
    In place of
    PHP Code:
    $Coupling8=$_GET['Coupling8']; 
    try
    PHP Code:
    $Coupling8=$_POST['Coupling8']; 
    as this is more of a PHP problem that a MySQL problem I'll move it there
    I'd rather be riding on the Tiger 800 or the Norton

  15. #15
    Join Date
    May 2011
    Posts
    9
    Hello

    I took your advice and changed all references from $_GET to $_POST and now the variables are displaying in the error but it is still having an error in the insert line which I still can not find.

    Code:
    Error Occured
    The SQL was:INSERT INTO Casing_Job VALUES ('gjh', 'dgf', 'vghc', 'ddmmyyyy', 'HH:MM', 'AM', 'ddmmyyyy', 'HH:MM', '', 'bhj', 'drgt', 'fgcd', 'dr', 'sd', 'ers', 'sder', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'vg', 'dtfresd', 'drtdtr', 'ddmmyyyy', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', '', '', '', 'DD/MM/YYYY', 'ddmmyyyy')
    The MySQL Error is:0:
    And yes I did use random jiberish for the lines when testing.

Posting Permissions

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