Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7

    Pass PHP var to HTML <title>


    I'm attempting to pass a variable from FLASH to PHP to an HTML page to dynamically increment the <title> tag. I'm getting the variable to PHP (from FLASH) fine but can't get the number to appear in the <title> tag.

    Here is my approach:

    HTML Page:
    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript" src="swfobject.js"></script>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    </head>
    <body bgcolor="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="no">
    	<div id="flashcontent">
    		<strong>You need to upgrade your Flash Player.</strong>
    	</div>
        <?php require('cartnum.php');?>
    	<script type="text/javascript">
    		var so = new SWFObject("DatabaseBeta.swf", "sotester", "100%", "100%", "8", "#000000");
    		so.addParam("allowFullScreen", "true");
    		so.addParam("scale", "noscale");
    		so.addParam("menu", "false");
    		so.write("flashcontent");
    	</script>
    </body>
    </html>
    PHP Page:
    Code:
    <?php
    $cartnum = $_POST['cartnum']; // From FLASH
    echo "<title>".(isset($title)?$title:"Page / Number [". $cartnum ."]")."</title>";
    ?>
    All I can get to appear in the HTML title is: "Page / Number []" when what I'm trying to accomplish is "Page / Number [1]", "Page / Number [2]", "Page / Number [3]", etc.

    Again, the number is definitely being passed to PHP but not to HTML. Any idea on what I'm overlooking?

    Thanks for taking a moment to look,
    Kumba
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,383
    Rep Power
    594
    Obviously the value of '$cartnum' is not being set the way you expect. Thus $_POST['cartnum'] must not be what you expected. That means your assumption that flash is passing the value correctly is wrong. Add this to your code to see what $_POST really contains:
    PHP Code:
    echo "<pre>";
    print_r($_POST);
    echo 
    "</pre>"
    As an aside, you can place variables within double quotes if you wish. This would be valid:
    PHP Code:
    "Page / Number [$cartnum]" 
    Also note the use of [ PHP ] tags rather than [ CODE ] tags.
    Last edited by gw1500se; November 19th, 2012 at 09:27 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7
    Okay, so here is what is being returned from the PHP:

    PHP Code:
    NoticeUndefined indexcartnum in /home/daily/public_html/cartnum.php on line 2  Array ( ) 
    I'm working a lot with FLASH and if I echo back to FLASH the $cartnum var, it shows up as a number.

    So how do I get PHP to recognize the FLASH var as a number?

    I'm new to working with PHP so I appreciate your insight.

    Thanks,
    Kumba
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    previous statement removed, I didn't read carefully enough

    The error you're getting says that $_POST['cartnum'] isn't set. Are you sure you're using it properly?

    Also, you're including that PHP file outside the <head></head> tags, so the title won't ever be right.
    Last edited by ManiacDan; November 19th, 2012 at 10:43 AM.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,383
    Rep Power
    594
    I haven't used flash myself but this might help:

    http://www.devx.com/webdev/Article/36748/0/page/2
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7
    I am able to pass the $_POST['cartnum'] back to FLASH using:

    PHP Code:
    echo "&phptoflash = Reponse: ".$cartnum
    It shows up as the number I have incrementing that was originally sent to PHP.

    Also, I am able to get the <title> tag to show up as "Page / Number []"....it just doesn't see the $cartnum var.

    So, I can definitely send the $cartnum back to FLASH as a var but not the HTML page.

    Also, I am using loadVars in FLASH and the send and receive functions are working perfectly.

    Is this a type casting issue? I've tried converting the var:
    PHP Code:
    $cartnum = (int)$cartnum
    ...but to no avail.

    Any other ideas?

    Thanks,
    Kumba
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    What's the difference in these pages? Are you making two separate pages from two separate requests?

    $_POST is an array of the data posted to that single instance of the script. It is not available to any other requests or on any other pages. If you POST cartnum to this script and have it echo back out for raw flash to parse, then visit a different page (or even the same page) in your browser, you will not see the same POST data.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7
    What I'm attempting to do is just add an incremental number to a <title> tag of the same HTML page (Carts.html) every time it is opened. The "Carts.html" page will be opened via (FLASH) on another page but it will be opened multiple times.

    So when it is opened, I have a counter set in the FLASH page that opens the "Carts.html" page and also passes the incremental number to PHP (the one included in the Carts.html page). All I want to do is append that number each time "Carts.html" is opened to the <title> tag.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7
    So technically yes, I am making two separate pages from two separate requests.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,383
    Rep Power
    594
    Again the values in $_POST need to be your focus. Echo that array as I suggested so you can see exactly what is available in it on any given page.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7
    So my result is:

    PHP Code:
    Array ( ) 
    So what I see happening is that PHP doesn't see anything in the $_POST but when I echo it back to FLASH:

    PHP Code:
    echo "&phptoflash = Response: ".$_POST['cartnum']; 
    ....I get "Response: 1", "Response: 2", "Response: 3", etc.

    How can PHP see it to send it back to FLASH but nowhere else?
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,383
    Rep Power
    594
    Without seeing your form or understanding your logic flow it will be difficult to help. However, ManiacDan has already suggested what the problem might be. I agree that it appears you are trying to use $_POST in a different context than that of the form you are submitting.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7
    Okay, I'll work on it some more and see if I can find the culprit on the POST issue. Thanks you guys for taking a few minutes to look at this.

    Best,
    Kumba

    p.s. What is the best way to resolve/close/delete a post on this forum? Want to make sure I abide by the procedures in the forum.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,383
    Rep Power
    594
    There is no need to close it. You may be back in any case. If you post your form it might help.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  28. #15
  29. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    I'm not sure you understood my post, so I'll say it again:

    Each PHP request, each page you load, each ajax call, each refresh, is an entirely separate instance of your script, with no knowledge of other requests, no history, and no future.

    If you POST to a script, that single instance of that script and only that single instance of that script has access to the data you POSTed.

    If you then access that SAME script another way (through another request) and do not POST any data, that entirely new copy of the script in request #2 will not have any post data.

    This is what I believe you are doing. Your flash POSTs data, then you hit that same script in a webpage and wonder why the POST data isn't available. You're not understanding the underlying flow of client-server web programming. There is no maintained state.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo