1

the code below does mostly what it's supposed to do. It grabs the $id from a previous page and uses that to search the database for that ID and then shows the results. I am trying to get to where it shows the current $Name variable and then allows the user to change the name by using a form. So when the user changes the Name to a new name, the form in theory submit the new results to a new page AND also carry the $id variable over so I can go ahead and put the data into the same field. Currently only the $id is being passed over, I'm having issues with submitting the #NewName input. I tried using "hidden" input but that did not work since it is dynamic. How is it possible to send both?

<head>
<script type="text/javascript">
function SendEmail(button, db_ID) {

    //document.getElementById("ImpactNotifications").submit();
    window.open ('changenameto.php?db_ID='+db_ID,'newWin', 'width=600,height=200');
}
</script>

</head>
<body style="color: #black; background-color: #0000FF;">
<?php

$id = $_GET['id'];

$sql = "SELECT * FROM DBTABLE WHERE ID=$id";

$db_ID1=odbc_exec($conn,$sql);  
$db_ID = odbc_result($db_ID1,1);

echo "<strong>Name:</strong>";
echo "<br />";

$rs=odbc_exec($conn,$sql);
while($row = odbc_fetch_array($rs)) 
{
$Name=odbc_result($rs,"Name");
echo "$Name";
echo "<br />";
echo "<form method='post' name='ChangeName' enctype='multipart/form-data'>";
echo "<br />";
echo "<strong>Name Changed To:</strong><br />";
echo "<input name='NewName' type='text' style='width: 500px; height: 24px;' />";
echo "<br />";
echo '<br /><input type="submit" name="ChangedMe" value="Name Modified" onclick="SendEmail(this, ' . $db_ID . '); return false;" /><input name="Clear" type="reset" value="Reset" /><br />';
echo "</form>";
}

?>

UPDATE

<head>
<script type="text/javascript">
function SendEmail(button, db_ID) {

 document.getElementById('db_ID').value = db_ID; // inserting db_ID in hidden
    document.forms['ChangeMeetingName'].submit(); // submitting form 
}
</script>

</head>
<body style="color: #black; background-color: #0000FF;">
<?php

$id = $_GET['id'];

$sql = "SELECT * FROM DBTABLE WHERE ID=$id";

$db_ID1=odbc_exec($conn,$sql);  
$db_ID = odbc_result($db_ID1,1);

echo "<strong>Name:</strong>";
echo "<br />";

$rs=odbc_exec($conn,$sql);
while($row = odbc_fetch_array($rs)) 
{
$Name=odbc_result($rs,"Name");
echo "$Name";
echo "<br />";
echo "<form action='changenameto.php' method='post' name='ChangeName' enctype='multipart/form-data'>";
echo "<br />";
echo "<input name='db_ID' id='db_ID' type='hidden' value='' />";
echo "<strong>Name Changed To:</strong><br />";
echo "<input name='NewName' type='text' style='width: 500px; height: 24px;' />";
echo "<br />";
echo '<br /><input type="submit" name="ChangedMe" value="Name Modified" /><input name="Clear" type="reset" value="Reset" /><br />';
echo "</form>";
}

?>
Yusof
  • 73
  • 1
  • 9

1 Answers1

1

Ok, So I was thinking wouldn't it be easier if the form can be processes in the same window. I did a little research and found this How do I make a PHP form that submits to self?. That, in my opinion would be better than having more pages and worrying about data from one page to another. So what I ended up doing is leaving the action part of the form header blank.

echo "<form action='' method='post' name='ChangeName' enctype='multipart/form-data'>";

And then after the loop, I added:

if(isset($_POST['submit']))
{
$NewName  = $_REQUEST['NewName'];
echo "$NewName";
echo "$id";
}   

So Now I am hoping I can continue without any issues!

UPDATE: I forgot to mention, I also took out the javascript function since it is no longer needed

Community
  • 1
  • 1
Yusof
  • 73
  • 1
  • 9