...

View Full Version : Sending php variables



Doom87
11-04-2007, 06:35 AM
Ok so i have a form that has a username field, a password and a confirm password field.

When the submit button is pressed it adds that info to a database and opens a popup window with the onsubmit attribute in the form tag (the main window from before now goes back to the page to have a new user/password combo entered for another account)

I need to know how i can have the username displayed on this popup window.

Does anybody know how to do this?

thanks.

mathew edison
11-04-2007, 01:32 PM
You should be able to use the $_GET['fieldname'] function to display what the user has filled into the field you want to show the result of (e.g. the username field)

Doom87
11-04-2007, 05:35 PM
no that didn't work.

drscares
11-04-2007, 05:42 PM
I think he's saying you would pass your variable in the string you use to call up your popup window, and then use the $_GET in the popup window.

IE (URL To Popup page)
<script>
window.open ("your-popup-page.php?username="<?php echo $username; ?>";
</script>

And in the popup page:
$username = $_GET['username'];
echo "Thanks for signing up ".$username."!";

Inigoesdr
11-04-2007, 05:42 PM
It would work if you did it properly. Post the code you're using that "didn't work" if you want help.

$username = $_GET('username');
You need to use brackets, not parenthesis:
$username = $_GET['username'];

drscares
11-04-2007, 05:45 PM
Oops, good catch. Just woke up ;-)

Doom87
11-04-2007, 06:10 PM
the method $username = $_GET['username']; still didn't work

i tried drscares way but the popup window wouldn't work at all. I think with this way i'm doing somthing wrong.

Here's my onsubmit code:

onsubmit='popout("../scripts/printouts/newuser/printout.php?user=<?php echo $_POST['username']; ?>?password=<?php echo $_POST['password']; ?>, "_help",-1,-1);'

Inigoesdr
11-04-2007, 06:13 PM
View the source of the page with the JavaScript and post the URL that's generated for the popout() function. Popout is defined, right?

Doom87
11-04-2007, 06:28 PM
yes popout's defined. Here's the javascript for it:



<SCRIPT Language="javascript">
<!--
uniqueUrl = 1;
// This needs to be fixed if the current page plans to use the "bUseSame" option
// for more than one window. ViewWin is obviously not sufficient for tracking multiple windows
var ViewWin = null;
function popout(url, targetWin, h, w, bTouchUrl, bUseSame )
{
if( bUseSame && ViewWin != null && !ViewWin.closed && ViewWin.name == targetWin )
{
ViewWin.focus();
}
else
{

if (bTouchUrl)
{
if (bTouchUrl == 1)
{
url += "&z=" + uniqueUrl;
uniqueUrl++;
}
}

if (h && h > 0)
height=h;
else
height=470;

if (w && w > 0)
width=w;
else
width=630;

if( bUseSame )
ViewWin=window.open(url, targetWin,
'width='+width+',height='+height+',resizable=yes,menubar=yes,scrollbars=yes,status=yes' );
else
window.open(url, targetWin,
'width='+width+',height='+height+',resizable=yes,menubar=yes,scrollbars=yes,status=yes' );



}

} // popout
// -->
</SCRIPT>


it worked before i added the ?user=...?pass=... to the end of the url

Inigoesdr
11-04-2007, 06:30 PM
View the source of the page with the JavaScript and post the URL that's generated for the popout() function. Popout is defined, right?
Also, you're only supposed to use "?" once in the URL; it defines the start of the query string. Use "&" to separate the parts of the query string.

drscares
11-04-2007, 06:32 PM
Try this:



onsubmit='popout("../scripts/printouts/newuser/printout.php?user=<?php echo $_POST['username']; ?>&password=<?php echo $_POST['password']; ?>", "_help",-1,-1);'

Doom87
11-04-2007, 06:41 PM
ok the popup is opening again but the no data is being sent.

the url of the popup is just this: http:// domain. com/scripts/printouts/newuser/printout.php?user=&password=

the username & password doesn't get added in its place.

Doom87
11-04-2007, 07:12 PM
here's the code from the printout.php page:



<?php

$uname = $_GET['user'];

echo $uname;

?>

Inigoesdr
11-04-2007, 08:52 PM
ok the popup is opening again but the no data is being sent.

the url of the popup is just this: http:// domain. com/scripts/printouts/newuser/printout.php?user=&password=

the username & password doesn't get added in its place.

Ok, now find out why the $_POST variables are empty. Are you not naming the form inputs? Or are you not posting the form to the correct page? etc.

toddandrae
11-04-2007, 10:00 PM
If I'm following what you are saying, this isn't going to work. The variable's aren't being passed to the javascript window onsubmit, because at that point there are no PHP post variables. The URL for the javascript window has already been created.

Right now, your popup will show up with the right information from the first submit on the second go around.

What you may want to do is set it up to check for POST variables, and on page load for the form, if that variable exists, open your popup window.

I'm sorry if I am not following what you are trying to say.

Doom87
11-04-2007, 10:03 PM
yes the form inputs are named accordingly. the form is posting to the same page the form is on (its set up for multiple account creation)

here's all the form code tags (from createuser.php):



<?php
/* This code checks for the add user button to be clicked then adds the info to the db and creates account folder */

include("../db.php");

if(isset($_POST['adduser'])) {
if(!$_POST['username'] || !$_POST['password'] || !$_POST['confirmpass']) {
die("FIELD NOT CORRECTLY FILLED IN");
}

$pass1 = md5($_POST['password']);
$pass2 = md5($_POST['confirmpass']);
if($pass1 != $pass2) {
die("PASSWORDS DO NOT MATCH!");
}

$user = $_POST['username'];
$md5pass = md5($_POST['password']);

mysql_query("INSERT INTO engr_users (username, password) VALUES ('$user', '$md5pass')");

mkdir("../accounts/$user");
}

?>

Actual form code here:


<form method="post" action="createuser.php" onsubmit='popout("../scripts/printouts/newuser/printout.php?user=<?php echo $_POST['username']; ?>&password=<?php echo $_POST['password']; ?>", "_help",-1,-1);'>

Username: <input type="text" name="username" size="50" maxlength="30">
Password: <input type="password" name="password" size="50" maxlength="32">
Confirm Password: <input type="password" name="confirmpass" size="50" maxlength="32">

<input type="submit" name="adduser" value="Add New User">
</form>

Doom87
11-04-2007, 10:06 PM
If I'm following what you are saying, this isn't going to work. The variable's aren't being passed to the javascript window onsubmit, because at that point there are no PHP post variables. The URL for the javascript window has already been created.

Right now, your popup will show up with the right information from the first submit on the second go around.

What you may want to do is set it up to check for POST variables, and on page load for the form, if that variable exists, open your popup window.

I'm sorry if I am not following what you are trying to say.

no ur following everything correctly. the info does show up the second time around.

Does anybody know how i can get this to work another way then?

toddandrae
11-04-2007, 10:13 PM
change your PHP code so that if those POST variables exist it adds it to the body onload to open the window.

Doom87
11-04-2007, 10:17 PM
i'm not sure exactly what you mean

toddandrae
11-04-2007, 10:29 PM
echo"<body";
if($_POST['username'] && $_POST['password']){
echo " onload=onsubmit='popout(\"../scripts/printouts/newuser/printout.php?user=" . $_POST['username'] . "&password=" . $_POST['password'] . "\", \"_help\",-1,-1);'";
}
echo ">";


Although you should probably set up a variable for if the user has been successfully entered and compare to that.

Doom87
11-04-2007, 10:41 PM
wow that worked. thank you so much



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum