Solved

Run php program without having to "CLICK"

Posted on 2011-09-26
7
196 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

737 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