Jump to content

Recommended Posts

<?
header("Cache-Control: public");

include ("header.php"); //db info for DB2
include ("logl.php"); 

if ($_POST['submit']) {

    $type = $_POST["type"];
    $cgid = $_POST["cgid"];
    $comp = $_POST["comp"];
    
   // echo $cgid;    value gets passed 
 //   echo  $comp;   value gets passed
 //   echo $type;    value gets passed


if ($type == "UG") {  
 if(isset($_POST) && !empty($_POST["group2"]))
{
 
 //   this value does NOT get passed
$group2 = $_POST["group2"]; 
$cgid = $_POST["cgid"];

$sqla = "UPDATE `Cgroup` SET `Group ` = '$group2' WHERE CGID = '$cgid' ";
$resulta = mysqli_query($link1, $sqla);
 // this sql doesnt run. The value of $group2 doesn't get passed into the sql;


} else {
 ?>
 
 <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" >

$sqla = "SELECT * FROM `Cgroup` WHERE CGID = $cgid ";
$resulta = mysqli_query($link1,$sqla);
$myrowa=mysqli_fetch_array($resulta);
?>

<table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#000066" width="95%" cellpadding="5"  >
<tr><td colspan="3" bgcolor="#B5CBEF" height="16" width="100%" bordercolor="#FFFFFF" ><font size="1" face="Calibri"><b><font face="Calibri" size="2" color="#000066">&nbsp;</font></b></td></tr><tr><td colspan="4" bgcolor="#D6DFEF" height="16" width="100%" bordercolor="#FFFFFF"><tr><td height="30" width="55" bgcolor="#EFF3F7" bordercolor="#FFFFFF">

<font face="Calibri" size="2" color="#004080" >Old Group : <input type=text name='group1' size=50  value="<? echo $myrowa["Group"] ?>"></td></tr>
<tr><td height="30" width="55" bgcolor="#EFF3F7" bordercolor="#FFFFFF">

<font face="Calibri" size="2" color="#004080" >New Group : <input type=text name='group2' size=50> </td></tr>  
<tr><td height="30" width="55" bgcolor="#EFF3F7" bordercolor="#FFFFFF">

<input name='submit' type='submit' value='Rename'> 

<input type="hidden" name="cgid" value="<? echo $cgid ?>" >

</td></tr><tr><td colspan="3" bgcolor="#B5CBEF" height="25" width="737" ><p align="center"><font face="Calibri" size="2"></td></tr>

</table>

</form>
<?
}
}
?>
<html>

<head>
</head>

<body>

<div class=Section1>

<input type="hidden" name="userid" value="<? echo $userid ?>">
<input type="hidden" name="sid" value="<? echo $sid ?>">


<?php


} else {

?>


 <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" >
   
  // The first form - this works perfectly 
   
   
   <input type="submit" name = "submit" value="Select"></span></b></p>
  <input type="hidden" name="userid" value="<? echo $userid ?>" >
</form>
<?php

}

?>

I have the above old file. I am able to get the first php self working but the one inside it is not working. The form processes but the value doesn't get passed on submit .

Where am i going wrong ? 

Thanks in advance

A

2 hours ago, anandi said:
<input type="hidden" name="userid" value="<? echo $userid ?>" >

Have a look at the page source and see if the userid value is there. You may need either

<?= $userid ?>

or

<?php echo $userid ?>

Also, you don't need those PHP_SELFs. Jus omit the action attribute completely from the form tag. (The default action is "self")

<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
  
  // The first form - this works perfectly
    <input type="submit" name="submit" value="Select"></span></b></p>
	<input type="hidden" name="userid" value="<? echo $userid ?>">
</form>

There's no field named 'type' here (actually, there's no field named 'type' anywhere in the code you've supplied). So, $_POST['type'] can never be "UG" and this conditional:

if ($type == "UG") {

will always fail. So your first block of code won't run, which is apparently exactly what you're seeing.

Edited by maxxd
typo

Take a look at what your code REALLY looks like when you stop entering and leaving PHP mode.  Stick to PHP mode and use the echo statement (or learn about heredocs) to output your non-PHP code lines.

<?PHP
header("Cache-Control: public");
include "header.php"; //db info for DB2
include "logl.php"; 
if ($_POST['submit']) 
{
	$type = $_POST["type"];
	$cgid = $_POST["cgid"];
	$comp = $_POST["comp"];
	if ($type == "UG") 
	{  
		if(isset($_POST) && !empty($_POST["group2"]))
		{
			//   this value does NOT get passed
			$group2 = $_POST["group2"]; 
			$cgid = $_POST["cgid"];
			$sqla = "UPDATE `Cgroup` SET `Group ` = '$group2' WHERE CGID = '$cgid' ";
			$resulta = mysqli_query($link1, $sqla);
			// this sql doesnt run. The value of $group2 doesn't get passed into the sql;
		} 
		else 
		{
			echo "<form method='POST' action='{$_SERVER['PHP_SELF']}'>";	// semi not colon
			$sqla = "SELECT * FROM `Cgroup` WHERE CGID = $cgid ";
			$resulta = mysqli_query($link1,$sqla);
			$myrowa=mysqli_fetch_array($resulta);
			echo "<table border='1' cellspacing='1' style='border-collapse: collapse;' bordercolor='#000066' width='95%' cellpadding='5'>
				<tr>
				<td colspan='3' bgcolor='#B5CBEF' height='16' width='100%' bordercolor='#FFFFFF' >
				<font size='1'  face='Calibri'>
				<b>
				<font face='Calibri' size='2' color='#000066'>&nbsp;
				</font>
				</b>
				</td>
				</tr>
				<tr>
				<td colspan='4' bgcolor='#D6DFEF' height='16' width='100%' bordercolor='#FFFFFF'>
				<tr>
				<td height='30' width='55' bgcolor='#EFF3F7' bordercolor='#FFFFFF'>
				<font face='Calibri' size='2' color='#004080' >
				Old Group : <input type='text' name='group1' size=50  value='{$myrowa[\"Group\"]}>
				</td>
				</tr>
				<tr>
				<td height='30' width='55' bgcolor='#EFF3F7' bordercolor='#FFFFFF'>
				<font face='Calibri' size='2' color='#004080' >
				New Group : <input type='text' name='group2' size=50>
				</td>
				</tr>
				<tr>
				<td height='30' width='55' bgcolor='#EFF3F7' bordercolor='#FFFFFF'>
				<input name='submit' type='submit' value='Rename'> 
				<input type='hidden' name='cgid' value='$cgid'>
				</td>
				</tr>
				<tr>
				<td colspan='3' bgcolor='#B5CBEF' height='25' width='737' >
				<p align='center'>
				<font face='Calibri' size='2'>
				</td>
				</tr>
				</table>
				</form>";
		}
	}
	echo "
		<html>
		<head>
		</head>
		<body>
		<div class='Section1'>
		<input type='hidden' name='userid' value='$userid'>
		<input type=;hidden' name='sid' value='$sid'>
		";
} 
else 
{
	echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>
	<input type='submit' name='submit' value='Select'>
	</span>
	</b>
	</p>
	<input type='hidden' name='userid' value='$userid'>
	</form>
	";
}

Note the use of a single block of php code with html embedded in it.  Note also the use of " quotes to wrap the long strings of code with single quotes around the attributes.  This allows you to insert php variables into the html without having to enter and exit php mode which is silly and makes for difficult interpretation.

Lastly - this html code is so outdated.  Where did you get it?  Please learn a little CSS and also the proper sequence of html tags.  You are outputting an entire html table before you ever enter the html tag or the body tag.  Incorrect.  The style attributes you are using I don't think exist.  And the font tag is deprecated as well.  And the dimensions without units may or may not work, but switching to a CSS class can resolve that and avoid having to repeat all that code in every one of your html tags.  You also have missing closing tags and rows inside of other rows which you may be able to see now that I have broken down your lines to show you how you have composed this block of html.

I didn't try and correct anything - just present it better so you can see your syntactical and presentational mistakes.

Edited by ginerjm
20 hours ago, Barand said:

Have a look at the page source and see if the userid value is there. You may need either

<?= $userid ?>

or

<?php echo $userid ?>

Also, you don't need those PHP_SELFs. Jus omit the action attribute completely from the form tag. (The default action is "self")

I changed to <?php echo $userid ?> . That's one issue solved. Thank you. 

 

20 hours ago, maxxd said:
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
  
  // The first form - this works perfectly
    <input type="submit" name="submit" value="Select"></span></b></p>
	<input type="hidden" name="userid" value="<? echo $userid ?>">
</form>

There's no field named 'type' here (actually, there's no field named 'type' anywhere in the code you've supplied). So, $_POST['type'] can never be "UG" and this conditional:

if ($type == "UG") {

will always fail. So your first block of code won't run, which is apparently exactly what you're seeing.

It is there - its in the form that works perfectly so for sake of brevity I didn't copy all of the code here. My  issue is with the second submit that doesn't pick up the $group2 variable. Thank you.

18 hours ago, ginerjm said:

Take a look at what your code REALLY looks like when you stop entering and leaving PHP mode.  Stick to PHP mode and use the echo statement (or learn about heredocs) to output your non-PHP code lines.

<?PHP
header("Cache-Control: public");
include "header.php"; //db info for DB2
include "logl.php"; 
if ($_POST['submit']) 
{
	$type = $_POST["type"];
	$cgid = $_POST["cgid"];
	$comp = $_POST["comp"];
	if ($type == "UG") 
	{  
		if(isset($_POST) && !empty($_POST["group2"]))
		{
			//   this value does NOT get passed
			$group2 = $_POST["group2"]; 
			$cgid = $_POST["cgid"];
			$sqla = "UPDATE `Cgroup` SET `Group ` = '$group2' WHERE CGID = '$cgid' ";
			$resulta = mysqli_query($link1, $sqla);
			// this sql doesnt run. The value of $group2 doesn't get passed into the sql;
		} 
		else 
		{
			echo "<form method='POST' action='{$_SERVER['PHP_SELF']}'>";	// semi not colon
			$sqla = "SELECT * FROM `Cgroup` WHERE CGID = $cgid ";
			$resulta = mysqli_query($link1,$sqla);
			$myrowa=mysqli_fetch_array($resulta);
			echo "<table border='1' cellspacing='1' style='border-collapse: collapse;' bordercolor='#000066' width='95%' cellpadding='5'>
				<tr>
				<td colspan='3' bgcolor='#B5CBEF' height='16' width='100%' bordercolor='#FFFFFF' >
				<font size='1'  face='Calibri'>
				<b>
				<font face='Calibri' size='2' color='#000066'>&nbsp;
				</font>
				</b>
				</td>
				</tr>
				<tr>
				<td colspan='4' bgcolor='#D6DFEF' height='16' width='100%' bordercolor='#FFFFFF'>
				<tr>
				<td height='30' width='55' bgcolor='#EFF3F7' bordercolor='#FFFFFF'>
				<font face='Calibri' size='2' color='#004080' >
				Old Group : <input type='text' name='group1' size=50  value='{$myrowa[\"Group\"]}>
				</td>
				</tr>
				<tr>
				<td height='30' width='55' bgcolor='#EFF3F7' bordercolor='#FFFFFF'>
				<font face='Calibri' size='2' color='#004080' >
				New Group : <input type='text' name='group2' size=50>
				</td>
				</tr>
				<tr>
				<td height='30' width='55' bgcolor='#EFF3F7' bordercolor='#FFFFFF'>
				<input name='submit' type='submit' value='Rename'> 
				<input type='hidden' name='cgid' value='$cgid'>
				</td>
				</tr>
				<tr>
				<td colspan='3' bgcolor='#B5CBEF' height='25' width='737' >
				<p align='center'>
				<font face='Calibri' size='2'>
				</td>
				</tr>
				</table>
				</form>";
		}
	}
	echo "
		<html>
		<head>
		</head>
		<body>
		<div class='Section1'>
		<input type='hidden' name='userid' value='$userid'>
		<input type=;hidden' name='sid' value='$sid'>
		";
} 
else 
{
	echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>
	<input type='submit' name='submit' value='Select'>
	</span>
	</b>
	</p>
	<input type='hidden' name='userid' value='$userid'>
	</form>
	";
}

Note the use of a single block of php code with html embedded in it.  Note also the use of " quotes to wrap the long strings of code with single quotes around the attributes.  This allows you to insert php variables into the html without having to enter and exit php mode which is silly and makes for difficult interpretation.

Lastly - this html code is so outdated.  Where did you get it?  Please learn a little CSS and also the proper sequence of html tags.  You are outputting an entire html table before you ever enter the html tag or the body tag.  Incorrect.  The style attributes you are using I don't think exist.  And the font tag is deprecated as well.  And the dimensions without units may or may not work, but switching to a CSS class can resolve that and avoid having to repeat all that code in every one of your html tags.  You also have missing closing tags and rows inside of other rows which you may be able to see now that I have broken down your lines to show you how you have composed this block of html.

I didn't try and correct anything - just present it better so you can see your syntactical and presentational mistakes.

Indeed it is a very old code from a very old file but we need to run it to get the data. Short of rewriting all those php scripts I don't know what else to do.  I've looked at it so often I simply can not see why $group2 is not getting passed. Thank you.

 

45 minutes ago, anandi said:

I changed to <?php echo $userid ?> . That's one issue solved

you need to fix all the occurrences of short opening php tags. the occurrences in the form that isn't working are probably breaking the html markup and preventing the form fields from being recognized.

you can check what the submitted form data is by adding the following near the top of the php code -

echo '<pre>'; print_r($_POST); echo '</pre>';

 

47 minutes ago, anandi said:

for sake of brevity I didn't copy all of the code here.

by doing that, you prevented anyone here from directly helping and wasted the time of those that looked at the posted information. you have some sql related code in a html context, some form fields outside of any form, form data that you state work without existing in any of the posted code. if you want actual, direct help post all the code needed to reproduce the problem.

On 10/20/2022 at 2:38 PM, mac_gyver said:

you need to fix all the occurrences of short opening php tags. the occurrences in the form that isn't working are probably breaking the html markup and preventing the form fields from being recognized.

you can check what the submitted form data is by adding the following near the top of the php code -

echo '<pre>'; print_r($_POST); echo '</pre>';

 

by doing that, you prevented anyone here from directly helping and wasted the time of those that looked at the posted information. you have some sql related code in a html context, some form fields outside of any form, form data that you state work without existing in any of the posted code. if you want actual, direct help post all the code needed to reproduce the problem.

Thank you. I have noted this and will be more mindful going ahead. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.