Solved

Run php program without having to "CLICK"

Posted on 2011-09-26
7
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

707 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