anandi
-
Posts
6 -
Joined
-
Last visited
Posts posted by anandi
-
-
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.
-
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.
-
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.
-
<? 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
-
Hi
I have some data that i display on screen and i need to be able to export to excel as is. Whatever i have found online only refers to data in a single table but my sql statement is of joins. I am searching for a simple way to do this using this code below. Would very much appreciate some help. thanks. anandis
$OR = " SELECT * FROM address a LEFT JOIN Cities USING(CITYID) JOIN Customers c USING(CID) WHERE a.SID = '$sid' ORDER BY c.`Company` asc, `CITYID` asc "; $resultOR = mysqli_query($link2, $OR) or die(mysqli_errorno()); $numofrows = mysqli_num_rows($resultOR); echo "<table border='1' style='border-collapse: collapse' bordercolor='#111111' width='100%'>\n"; echo "<tr bgcolor='#FFEAED'> <td><b><font size=3 face=Calibri color=brown>S.No</b></td> <td><b><font size=3 face=Calibri color=brown>CAID</b></td> <td><b><font size=3 face=Calibri color=brown>CID</b></td> <td><b><font size=3 face=Calibri color=brown>Company</b></td> <td><b><font size=3 face=Calibri color=brown>Street</b></td> ETC \n"; for ($p = 1; $p <= $numofrows; $p++) { $myrow = mysqli_fetch_array($resultOR); $caid = $myrow["CAID"]; $cid = $myrow["CID"]; $cityid= $myrow['CITYID']; $result2 = mysqli_query($link2, "SELECT * FROM Cities WHERE `CITYID` = '$cityid' "); $myrow2 = mysqli_fetch_array($result2); $city = $myrow2["City"]; $sql22 = "SELECT * FROM Customers WHERE `CID` = '$cid' "; $result22 = mysqli_query($link2, $sql22) or die (mysqli_errorno ()); $myrow22=mysqli_fetch_array($result22); $company = $myrow22["Company"]; if ($p % 2) { //this means if there is a remainder echo "<TR bgcolor=\"#FAF0F0\">\n"; } else { //if there isn't a remainder we will do the else echo "<TR bgcolor=\"white\">\n"; } echo " <td><font face=\"Calibri\" size=\"3\" color=\"brown\">$p </TD> <td><font face=\"Calibri\" size=\"3\" color=\"brown\">$city </TD> <td><font face=\"Calibri\" size=\"3\" color=\"brown\">$cid </TD> <td><font face=\"Calibri\" size=\"3\" color=\"brown\">$company</TD> <td><font face=\"Calibri\" size=\"3\" color=\"brown\">" . $myrow["Street"] . " </TD> echo "</TR>\n"; } echo "</TABLE>\n";
Unable to get two PHP_SELF working on the same page
in PHP Coding Help
Posted
Thank you. I have noted this and will be more mindful going ahead.