Jump to content

Passing multiple variables to javascript popup


ashrobbins87

Recommended Posts

I am currently building the user management section of my site, and I am at the editing users stage. I have a popup which takes the id of a user from MySQL database and populates textfields with their info. I then want the user to be able to alter these textfields and send the new values to the database. Sounds simple enough but....

 

I can get the popup to pass the id number, but not the altered text from the txt fields.

 

The script sending the data is below...

<?php

if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else
{	
$id = $_GET["i"];

$mysqli = mysqli_connect("localhost","root","Cadbury5","opp_group");

$getDetails_sql = "SELECT * FROM cms_users where id='".$id."'";
$getDetails_res = mysqli_query($mysqli, $getDetails_sql)or die(mysqli_error()); 



if ($getDetails_res) 
{
	$row = mysqli_fetch_assoc($getDetails_res);
	$f = $row['firstname'];
	$s = $row['surname'];
	$u = $row['username'];
	$p = $row['password'];
} 
else 
{
		printf("Could not retreive records: %s\n", mysqli_error($mysqli));
}
	mysqli_close($mysqli);
}





echo "<h2>".$f." ".$s."</h2>";
?> <form method="post" action="user.php"> <?php
echo "

<table>
<tr><td>First Name: </td><td><input type=\"text\" name=\"firstname\" size=\"20\" value=\"".$f."\" /></tr>
<tr><td>Surname: </td><td><input type=\"text\" name=\"surname\" size=\"20\" value=\"".$s."\"  /></tr>
<tr><td>Username: </td><td><input type=\"text\" name=\"username\" size=\"20\" value=\"".$u."\" /></tr>
<tr><td>New Password: </td><td><input type=\"text\" name=\"newpassword\" size=\"20\" value=\"Enter New Password\" /></tr>
<tr><td>Re-enter Password: </td><td><input type=\"text\" name=\"confirmpassword\" size=\"20\" value=\"Confirm New Password\" /></tr>
</table></form>
<br/><br/>
";


$new_f = $_POST['firstname'];
$new_s = $_POST['surname'];
$new_u = $_POST['username'];
$new_p = $_POST['newpassword'];
$conf_p = $_POST['confirmpassword'];


echo"<table>
<tr>
<td><input type=\"submit\" name=\"update\" value=\"Update User\" onclick=\"javascript:eventWindow('cms/updateuser.php?i=".$id."&f=".$new_f."');\"></td>
<td><input type=\"button\" name=\"delete\" value=\"Delete\" onclick=\"javascript:eventWindow('cms/deletevalidation.php?i=".$id."');\"></td>
</tr>
</table>";

?>

and this is the code receving the data.

<php
$id = $_GET["i"];
$f = $_GET["f"];

echo $id;
echo $f;
?>

at the moment I'm just trying to echo the variables that are being passed to the new page, to make sure that they are being populated. Any help please????

It won't work because the form hasn't actually been submitted, you've basically replaced the submit button with an onclick function so no form data is being sent.

 

I don't have a suggestion on how to fix it or what you can do instead though I'm afraid - just thought I'd point that out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.