anandi Posted October 19, 2022 Share Posted October 19, 2022 <? 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"> </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 Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/ Share on other sites More sharing options...
Barand Posted October 19, 2022 Share Posted October 19, 2022 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") Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601768 Share on other sites More sharing options...
maxxd Posted October 19, 2022 Share Posted October 19, 2022 (edited) <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 October 19, 2022 by maxxd typo Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601769 Share on other sites More sharing options...
ginerjm Posted October 19, 2022 Share Posted October 19, 2022 (edited) 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'> </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 October 19, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601774 Share on other sites More sharing options...
anandi Posted October 20, 2022 Author Share Posted October 20, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601793 Share on other sites More sharing options...
anandi Posted October 20, 2022 Author Share Posted October 20, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601795 Share on other sites More sharing options...
anandi Posted October 20, 2022 Author Share Posted October 20, 2022 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'> </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. Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601797 Share on other sites More sharing options...
mac_gyver Posted October 20, 2022 Share Posted October 20, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601800 Share on other sites More sharing options...
anandi Posted October 21, 2022 Author Share Posted October 21, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315438-unable-to-get-two-php_self-working-on-the-same-page/#findComment-1601826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.