[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Run php program without having to "CLICK"

Posted on 2011-09-26
7
Medium Priority
?
200 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 84

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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

Expert Comment

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

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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).
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

649 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