Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving variables for new windows to upload into database

    Case 1: I'm trying to submit information into a database via my php pages. It works fine if I use the same browser window which goes to different pages one at a time. But if I want to create a new page which fills in as a confirmation page (popup page), the variables don't exist anymore. It works if I go to a new page on the same browser window, but not if I open a new window.

    Any idea on how to go around this? I even tried global variables, that didn't work. Am I supposed to use sessions? I'd rather not.

    *************

    Problem 2: If i use the same page, it saves all the information on the pages, but refuses to store them into the database, in fact, it saves the variables as NULL. I've tried going around this problem, but the farthest (or backward) I ever get is by not getting even a line submitted into the database. I presume its all because of the variables not being stored, how can i ensure that they are being saved on different pages?

    Thanks
    Duniyadnd

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You lost me completely.

    It's better that you post the relevant PHP code of a simplified test case where your problem is, so we get a better understanding of what actually went wrong.

    As for opening the window, I don't get how that should affect any form variables sent to the receiving PHP page. But as I said, post some code.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    should have realized it wasn't straightforward, was just too sick with this code and thought it was really long and... well, enough ranting... here you go... two files, you submit the information here:

    <script language="JavaScript">
    <!--
    function openUp(){
    window.open("confirmnewplayer.php","")

    }
    -->
    </script>

    <?


    include "connect.inc";

    print ("<FORM ACTION=\"$PHP_SELF\" onSubmit=\"openUp()\" CLASS=\"formspecial\" NAME=\"formed\" METHOD=\"POST\")>\n");


    /***
    SAVE YOU TIME, JUST A WHOLE BUNCH OF TEXT FIELDS, THEY ALL WORK AND ARE CORRECT
    ***/


    print ("<INPUT TYPE=\"HIDDEN\" NAME=\"testit\" value=\"$parentID\">\n");

    print ("first name<br>\n");
    print ("<INPUT TYPE=\"TEXT\" NAME=\"firstName\" value=\"$firstName\"><br>\n");

    print ("last name<br>\n");
    print ("<INPUT TYPE=\"TEXT\" NAME=\"lastName\" value=\"$lastName\"><br>\n");

    print ("middle name<br>\n");
    print ("<INPUT TYPE=\"TEXT\" NAME=\"middleName\" value=\"$middleName\"><br>\n");


    /***END OF TEXT FIELDS ***/

    print ("<INPUT TYPE=\"RESET\" VALUE=\"DEFAULT\">");

    print ("<INPUT TYPE=\"SUBMIT\" NAME=\"submitting\" VALUE=\"SUBMIT\">");
    print ("</FORM>");
    ?>

    ****************************

    second file: (confirmnewplayer.php)


    <?
    include "connect.inc";

    print ($firstName);
    print ("<FORM ACTION=\"toputin.php\" NAME=\"formedit\" METHOD=\"POST\">\n");
    print ("Please confirm if it is correct, otherwise press the \"Back\" button to further edit:<br>\n");

    print ("<b>First Name:</b>" . stripslashes($firstName) . "<br>\n");
    print ("<b>Last Name:</b>" . stripslashes($lastName) . "<br>\n");
    print ("<b>Middle Name:</b>" . stripslashes($middleName) . "<br>\n");

    $first = $firstName;
    $last = $lastName;
    $middle = $middleName;

    print (first);
    print ($firstName);

    print ("<INPUT TYPE=\"SUBMIT\" NAME=\"submittingit\" VALUE=\"SUBMIT\">\n");
    print ("</FORM>\n");

    /***put into database***/

    if ($ACTION != "")
    {

    if ("SUBMIT" == $submittingit)
    {
    $Query = "INSERT INTO playertest ";
    $Query .= "VALUES( NULL, ";
    $Query .= "'" . addslashes($first) . "', ";
    $Query .= "'" . addslashes($last) . "', ";
    $Query .= "'" . addslashes($middle) . "', ";

    }

    ?>

    <script language="JavaScript" type="text/javascript">
    <!--
    alert("Submission Successful unless otherwise noted below");
    //-->
    </script>

    <?

    if (!($dbResult = mysql_Query($Query, $dbh)))
    {
    print ("No can do<br>\n");
    print ("report: " . mysql_error() . "<br>\n");
    exit();
    }

    }

    print ($first);

    ?>

    ****************

    Problem here is that the data that goes into the database is all "blank". Don't know how that happens. If I even start fooling around with some changes, the database doesn't even get updated, ie. not even a blank line is generated. Worked on this for the whole day, and couldn't get anywhere.

    Thanks in advance
    Duniyadnd

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortuanetely, that's so much code it really doesn't clear up things for me. I'm particularly confused why you use in one case

    PHP Code:
    print ("<b>First Name:</b>" stripslashes($firstName) . "<br>\n"); 
    print (
    "<b>Last Name:</b>" stripslashes($lastName) . "<br>\n"); 
    print (
    "<b>Middle Name:</b>" stripslashes($middleName) . "<br>\n"); 
    but in your query you write

    PHP Code:
    $Query .= "'" addslashes($first) . "', "
    $Query .= "'" addslashes($last) . "', "
    $Query .= "'" addslashes($middle) . "', "
    Are $firstName et al no longer interesting and where shall $first, $last and all the rest come from? Perhaps this is the cause of your error, I can't say for sure. Try to echo $Query and see what's really used as the SQL query, that might clear things up.

    Do yourself a favor and turn register_globals off, and use the superglobals array. That makes code much more readable, since we can see if you access variables from the $_POST, or $_GET etc. arrays. And if you have the nerve, add this at the top of your code:

    PHP Code:
    error_reporting(E_ALL); 
    That will report even small sources of error; it might totally fill your screen with error messages, but usually they are very helpful while debugging.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for the late reply, was sick, down and out...

    the stripslashes/addslashes was recommended in the book i was using, so I got used to the habit from the start.

    I put the $first, $last just for the hell of it to see if the variables come back in different forms. Dumb idea, but i was running out of them...

    I'm doing this all online with a host, and I don't know how to turn off the register_globals

    I'll try that error code and let you know what comes.

    Thanks
    Duniyadnd

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    From your first page:
    PHP Code:
    print ("<FORM ACTION=\"$PHP_SELF\" onSubmit=\"openUp()\" CLASS=\"formspecial\" NAME=\"formed\" METHOD=\"POST\")>\n"); 
    I know that I'm too late on this, but just wondering if you could solve your problem?

    BTW, I can't understand why you're using "PHP_SELF" for the actions of your first page's form. I don't think that it's possible to open a new page with JS and then expect the page to have your php variables from the previous page, unless you add them to the URL by JS. Does it mean anything to you?
    Last edited by ConfusedOfLife; 12-05-2002 at 09:53 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •