Solved

Run php program without having to "CLICK"

Posted on 2011-09-26
7
192 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 82

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 82

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 82

Expert Comment

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now