Solved

Run php program without having to "CLICK"

Posted on 2011-09-26
7
194 Views
Last Modified: 2012-05-12
I have an HTML program that on CLICK1 sets some hidden field values that are passed to php program 1. The same program has a CLICK2 that sets some hidden field values that are passed on to php program 2.

The data that I am passing is NOT from a form per se. I am loading the hidden fields as 'placeholders' for data that I have collected in localStorage. ALL data that I will be passing to both php programs will originate from localStorage

The code below works fine BUT I do not want the user to have to click 2 times. Once to load the header data and again to load the item data.

What are some options to have the HTML 'launch' php program 1 and php program 2 from a single click?

At this point I am not interested in using AJAX. So no AJAX options at this time.

Here is the code:

<form action="putcarthdr.php" method="post" onsubmit="return sethdrValue()">
  <fieldset>
    <input type="hidden" name="hiddenVal1" id=hiddenVal1 value="" /><br />
    <input type="hidden" name="hiddenVal2" id=hiddenVal2 value="" /><br />
    <input type="hidden" name="hiddenVal3" id=hiddenVal3 value="" /><br />
    <input type="submit" name="Submit" value=" Send Cart HEADER" autofocus />
  </fieldset>      
</form>      
                  
  <script type="text/javascript">
          function sethdrValue() {
              var d=new Date();
              var t=d.getTime();
              var randvar=(Math.floor(Math.random()*11111));
              var ukeyvar=t+randvar;
              localStorage.ukey = ukeyvar;
              document.getElementById("hiddenVal1").value=localStorage.ukey;
              document.getElementById("hiddenVal2").value=localStorage.HCLUser;
              document.getElementById("hiddenVal3").value=localStorage.EMAdd;
              return true;
           }
  </script>      
      

      
<form action="putcartitem.php" method="post" onsubmit="return setitemValue()">
  <fieldset>
    <input type="hidden" name="hiddenVal4" id=hiddenVal4 value="" /><br />
    <input type="hidden" name="hiddenVal5" id=hiddenVal5 value="" /><br />
    <input type="submit" name="Submit" value=" Send Cart ITEM" autofocus />
  </fieldset>      
</form>      
                  
  <script type="text/javascript">
          function setitemValue() {
             document.getElementById("hiddenVal4").value=localStorage.ukey;
             document.getElementById("hiddenVal5").value="XYZITEM";
             return true;
          }
  </script>      





putcarthdr.php

<?php
    $ukey = $_POST['hiddenVal1'];
    $hcluser = $_POST['hiddenVal2'];
    $email_add = $_POST['hiddenVal3'];
    $vardate = date("Y-m-d");
    $vartime = date("H:i:s");
                                    
    $conn = mysql_connect("localhost", "X", "Y") or die(mysql_error());
                  mysql_select_db("test");
                  mysql_query("INSERT INTO itemhdr (ukey, hcluser, trxdate, trxtime, email_add, email_sent)
                  VALUES ('$ukey', '$hcluser', '$vardate', '$vartime', '$email_add', 'N')");
                  mysql_close($conn);
?>



putcartitem.php

<?php
    $ukey = $_POST['hiddenVal4'];
    $item = $_POST['hiddenVal5'];
                                          
    $conn = mysql_connect("localhost", "X", "Y") or die(mysql_error());
                  mysql_select_db("test");
                  mysql_query("INSERT INTO itemdtl (ukey, item)
                                        VALUES ('$ukey', '$item')");
                  mysql_close($conn);
?>
0
Comment
Question by:kbios
  • 3
  • 3
7 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36632912
If they're really that simple, include the second one at the end of the first one.
0
 

Author Comment

by:kbios
ID: 36656621
I'm not sure what part is simple. I want to launch both php's from within the HTML with 1 click. What second one at the end of the first one?
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 36669812
Set the hidden fields values in session variable so that you can use them from any other pages.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:kbios
ID: 36701836
Why would I need to set up a session variable? As I understand it the session variable is set on the server-side. ALL of the data elements I need are already set on the client-side and I am passing them just fine. Perhaps I am missing something but I find it hard to believe that there is not a way to do what I am requesting.

Perhaps a response with a little more detail may help me out.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 36707887
Use the code below as the single 'action' page and combine the two javascripts above into one and the forms into one form.
<?php
include "putcarthdr.php";
mysql_close();
include "putcartitem.php";
?>

Open in new window

0
 

Author Closing Comment

by:kbios
ID: 36709255
THANK YOU!

I added the code and took you suggestion and it worked perfectly. Thanks again.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36712097
You're welcome, glad to help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question