dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: [PHP] Parser does not receive data from submit form

  1. #1
    Join Date
    Sep 2014
    Posts
    7

    [PHP] Parser does not receive data from submit form

    OK, very very strange things going on here...

    I have a contact form on my site and when pushing "Submit", logically the form data gets submitted to the parser which then will upload the data into my MySQL table and also sent out via email.

    Now the weird thing is that the data does not seem to be passed on properly from the form to the parser. Chrome just spits out a regular "No data received error", while IE just times out. Funny enough, the data does get written TWICE into the database, so there definitely is some processing of the parser. Also, this seems to occur randomly since it didnt work in the morning, then worked again in the afternoon, and now in the evening again stopped working.

    Issues:
    * form data is submitted to parser although it often times out and no error pops up
    * MySQL gets the form data written into it several times (At least twice)
    * Email is never sent, which means the process dies before the email is generated, but after the mysql query has been executed

    The form:
    HTML Code:
    <form name="Guest Problem Alert" action="./scripts/GPA/email_parser.php" method="POST">
    						<div>
    							<label for="property">Property:</label><br />
    								<select name="property" style="width: 300px">
    									<option value="DADHA">DADHA</option>
    								</select>
    						</div>
    						<div>
    							<label for="name">Staff name (*):</label><br />
    							<input type="text" name="staff_name" size="30"/>
    						</div>
    // data data data
    
                                                    <div align="center">
    						<input type="submit" value="Submit" onclick="this.disabled=true; this.value = 'Wait...'; this.form.submit(); return true;" /> <input type='reset' value='Reset'>
    						</div>
    						
    					</form>
    the parser
    PHP Code:

    <html>
        <head>
            <title>Guest Problem Alert</title>
            <link rel="shortcut icon" href="./images/favicon.ico">    
            <meta name="viewport" content="width=device-width, user-scalable=no">
        </head>

        <body>
        
    <?php
    require("../PHPMailer-master/class.phpmailer.php");            // load the PHPmailer script
    date_default_timezone_set('Etc/UTC');                        // set timezone in PHP.ini,required by SMTP
    ini_set('display_errors''On');                            // show all errors
    $edit_url="http://".$_SERVER['HTTP_HOST']."/QCI/scripts/GPA/edit.php";                        // edit.php location and $id value link
       
    error_reporting(E_ALL);
      
    // VARIABLES HANDED OVER FROM GPA FORM
        
    $id uniqid();                                            // Unique ID for identification purposes
        
    $property $_POST['property'];                         // Property Holidex Code
        
    $date date("Y-m-d"strtotime('+7 hours'));            // Add 7 hours to date
        
    $time date("H:i:s"strtotime('+7 hours'));            // Add 7 hours to time
        
    $staff_name $_POST['staff_name'];                     // required
        
    $staff_department $_POST['staff_department'];         // not required
        
    $problem $_POST['problem'];                             // required
        
    $priority $_POST['priority'];                         // not required
        
    $gst_name $_POST['gst_name'];                         // not required
        
    $gst_room $_POST['gst_room'];                         // not required
        
    $incident $_POST['incident'];                         // required
        
    $action $_POST['action'];                             // not required
        
    $followup $_POST['followup'];                         // not required
        
    $gst_temp $_POST['gst_temp'];                         // not required
        
    $case_status $_POST['case_status'];                     // required
        
    $gst_profile $_POST['gst_profile'];                     // not required

        
    $email_message "<img src='cid:ic_logo' width='400' height='66' alt='IC Logo' /><br/>
        <p>A guest problem alert has been raised for your property, please see details below:</p>
          <table>
            <tr><th>Item</th>
            <th>Details</th></tr>
            <tr><td>Property</td><td>
    $property</td></tr>
            <tr><td> </td></tr>
            <tr><td>Date & Time</td><td>
    $date - $time</td></tr>
            <tr><td>Staff Name</td><td>
    $staff_name</td></tr>
            <tr><td>Staff Department</td><td>
    $staff_department</td></tr>
            <tr><td>Problem</td><td>
    $problem</td></tr>
            <tr><td>Priority</td><td>
    $priority</td></tr>
            <tr><td>Guest Name</td><td>
    $gst_name</td></tr>
            <tr><td>Guest Room</td><td>
    $gst_room</td></tr>
            <tr><td>Incident</td><td>
    $incident</td></tr>
            <tr><td>Action</td><td>
    $action</td></tr>
            <tr><td>Follow up</td><td>
    $followup</td></tr>
            <tr><td>Guest Manner</td><td>
    $gst_temp</td></tr>
            <tr><td>Case closed?</td><td><b>
    $case_status</b></td></tr>
            <tr><td>Guest profile updated by:</td><td>
    $gst_profile</td></tr>
          </table>
          <p><b>All OPEN CASES must be followed up within 1 hour from now.</b> Please consult with the Resort Assistant Manager on-duty for more details or assistance.<br/>
          <br/><a href=
    $edit_url?id=$id>$edit_url?id=$id</a><br/><br/>
          Kind regards"
    ;

        
    // CHECK IF ALL NECESSARY FIELDS HAVE BEEN FILLED
        
    if ($staff_name == "" OR $problem == "" OR $incident == "" OR $case_status == ""
            {
            echo 
    "<img src=\"../../images/iclogo_small.jpg\" style=\"width: 300px\"><br/><font size=\"3\"><b><u>ERROR</u></b><br/></font>
            You did not enter a valid Staff Name, Guest Problem, Incident Message or Case Status.<br/><br/>Please <a href=\"javascript:history.go(-1)\">[Go Back]</a> and fix this.<br/><br />
            <input action=\"action\" type=\"button\" value=\"Back\" onclick=\"history.go(-1);\" />"
    ;
            exit;
            }

        
    // WRITE INTO LOCAL TEXTDATABASE
            
    if    (    isset($staff_name) && isset($problem) && isset($incident) && isset($case_status)    )
                    {
                        
    $data $property '|' $id '|' $date '|' $time '|' $staff_name '|' $staff_department '|' $problem '|' $priority '|' $gst_name '|' $gst_room '|' $incident '|' $action '|' $followup '|' $gst_temp '|' $case_status '|' $gst_profile "\n";
                        
    $ret file_put_contents('GPAdata.txt'$dataFILE_APPEND LOCK_EX);
                        
                        if    (
    $ret === false)    
                            {
                            die(
    'There was an error writing this file');
                            }
                    }
                    
        
    // WRITE INTO MYSQL DATABASE
            
    mysql_connect("host""user""password") or die(mysql_error());
            
    mysql_select_db("b24_15096338_GPA") or die(mysql_error());
            
    mysql_query("INSERT INTO `GPA` VALUES ('$id','$property','$date','$time','$staff_name','$staff_department','$problem','$priority','$gst_name','$gst_room','$incident','$action','$followup','$gst_temp','$case_status','$gst_profile')");
        
            
        
    // PHPMAILER START
            
    $mail = new PHPMailer();
            
    $mail->isSMTP();                                                // Set connection type to SMTP
            
    $mail->SMTPDebug 0;                                            // Enable SMTP debugging, 0 = off (for production use), 1 = client messages, 2 = client and server messages
            
    $mail->Debugoutput 'html';                                    // Set the output format for SMTP Debug
                
            
    $mail->Host "mail.host.com";                                    // Mail Host Server
            
    $mail->Port 25;                                                // SMTP Port (usually 25)
            
    $mail->SMTPAuth true;                                            // Authentication needed? true/false
            
    $mail->Username " mail@mail.com";                                // Login Username
            
    $mail->Password "pw";                                            // Login Password
            
            
    $mail->setFrom('mail@mail.com');                                // Sent FROM
            
    $mail->addReplyTo('mymail@mail.com');                            // Add REPLY-TO address
            
    $mail->addAddress('someones@mail.com');                            // Send TO

            
    $mail->Subject $property ' - Guest Problem Alert';
            
    $mail->Body $email_message;
            
    $mail->isHTML(TRUE);                                            // HTML body? true/false
            
    $mail->AddEmbeddedImage('../../images/iclogo_small.jpg''ic_logo');
            
    //$mail->msgHTML("<table><tr><th>cat1</th><th>cat2</th></tr><td>Date & Time</td><td>".$time_GMT11."</td></table>");                                // Message body - HTML
            //$mail->body = $email_message;                                    // Message body - regular
            //$mail->AltBody = $email_message;                                // Message body - plain text
            //$mail->addAttachment('../../images/iclogo_small.jpg');        // Attachment if necessary
            
            //send the message, check for errors
            
    if (!$mail->send()) 
            {
                echo 
    "Mailer Error: " $mail->ErrorInfo;
            } 
            else    {
                    echo     
    "<img src=\"../../images/iclogo_small.jpg\" style=\"width: 300px\"><br/><font size=\"3\"><b><u>MESSAGE SENT!</u></b><br/></font>
                            Thank you very much for submitting the Guest Problem Alert. <br><br>All OPEN CASES must be follow up within 1 hour, please consult with the Resort Assistant Manager on-duty for further follow up.<br/>
                            <br/>
                            <input action=\"action\" type=\"button\" value=\"Back\" onclick=\"history.go(-1);\" />"
    ;
                    }
    ?>
    No idea, really. It used to work fine before, just since this morning that I have all these issues. Can this be my host? Since the script seem to die in the middle of parsing, maybe a connectivity issue?

    Thanks for any suggestions,
    A2k
    Last edited by NogDog; 09-15-2014 at 01:33 PM. Reason: changed [code] tags to [php]

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,153
    What is this parser you speak of?

    And how are the two blocks of code you provided tied together?
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    20,320
    I see nothing obvious that would cause a submit to update the DB twice, though I might be tempted to remove the onclick event from your submit tag just to see if that has any bearing on things. (If you have JavaScript do the submit, then return true, does the form submit itself again?)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,153
    Two things I don't like.

    1 - you don't check the results of your query call. Do so to be sure it actually ran.
    2 - this code is not standard
    PHP Code:
    <a href=$edit_url?id=$id
    the attributes of this statement should be in quotes:
    PHP Code:
    <a href="$edit_url?id=$id"
    And - IMHO - a text file is In No Way a database. Please stop referring to it as one. Maintaining your data in two distinct formats is really kind of silly. Write yourself a simple 'dump' script that will produce a text-only document from your true database when you need one.

    And what's up with the formatting of your post? Very hard to read.

    And - It's time to update your html knowledge and stop using ancient tags and styling. No more <font> tags.

    And make your life easier by using both double and single quotes so you don't have to keep escaping them in your code.

    And - add this to your code:
    error_reporting(E_ALL | E_NOTICE);
    before you turn on display_errors.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  5. #5
    Join Date
    Sep 2014
    Posts
    7
    haha, well, thanks for all the complaints

    My HTML is indeed ancient as all of this is based on what I learned maybe 10-12 years ago when HTML4 was the talk of the block, guess I do have to freshen up.

    Alright, lets wrap this up:
    Code:
    <a href=$edit_url?id=$id>
    is currently in there only for testing purposes, has no actual use yet

    2. I did remove the onclick procedure before but have no different result. I didnt try to change the submit to TRUE, will see what happens
    3. I am writing into a textfile first because I would like to have a backup on my local server, but naturally am primarily using my MySQL database
    4. I have E_ALL on top already but do not receive any error message

    Funny enough, the script was running well again this morning. Unless anyone else here suggests otherwise, I would say its time for me to find another webhost.... Any suggestions on free webhosts that have MySQL and PHP5 with min. 20mb space?

    Thanks,
    A2k

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,153
    Free webhosts? Remember - you get what you pay for. Ads.

    I am very happy with my host - been with them for 10+ years. Had one daylong downtime I think. Good response when seeking TS help. Biggest plan less than $100 a year. 123ehost.com
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  7. #7
    Quote Originally Posted by NogDog View Post
    (If you have JavaScript do the submit, then return true, does the form submit itself again?)
    *DING*DING*DING*DING*DING
    We have a winner. That should be EXACTLY what's going on... and why relying on scripttardery to prevent double submit is silly nonsense.

    Instead of that garbage I'd put in a input[hidden] with a unique random hash on it; store the hash in sessions server side and compare on submit, no match it must be a mistake.

    Of course it would be a lot easier to figure out what was going on if the markup was dragged kicking and screaming out of the late '90's browser wars, what with tags and attributes like FONT and ALIGN that have no business in any code written after 1997; likewise this is 2014 not 2006, why are you still using the mysql_ functions that we've been told to stop using since PHP 5 dropped and that they've now added GIANT RED WARNING BOXES to the manual waving you off from it's use?

    The bizarroland willy-nilly formatting isn't helping matters either.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles