|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi Folks,
I'm fairly new to this, so please, no flames! Is there a way you can run PHP code within another PHP session? I have a form that has some PHP code in it that I would like to protect with authentication. I have the following at the top of my code: <?php require ("authenticate.inc"); echo '<HTML page>'; ?> This form works fine, since the PHP statement only appears once within the code. Now, I have another web page that has some of this code in it: <?php $db = mysql_connect("myhost", "myroot"); mysql_select_db("webapges",$db); if ($submit) { ... etc ... How do I add the PHP second code to the first instance? When I try: <?php require ("authenticate.inc"); echo '<?php'; echo '$db = mysql_connect("myhost", "myroot");'; echo 'mysql_select_db("webapges",$db);' echo 'if ($submit) {'; ... etc ... ?> It fails and gives me a parsing error. Thanks in advance!! Brian. |
|
#2
|
|||
|
|||
|
You don't need to open another php session if ur already in one. That's why it's giving you a parse error. You can just get rid of ur inner PHP tags and it shoudl be fine. So ur code shoudl look something liek this:
<?php require ("authenticate.inc"); $db = mysql_connect("myhost", "myroot"); mysql_select_db("webapges",$db"); if ($submit) { ... etc ... ?> just remember, once ur in php, ur in php, so u don't need to "open" another php section. hope this helps |
|
#3
|
|||
|
|||
|
Hi There,
It still didn't work. I received another parse error. Here is my entire php file for the form I want to submit: <html> <head> <title>Bug Report / Enhancement Request Form</title> </head> <body> <?php if ($submit) { // process form $db = mysql_connect("myhost", "mypassword"); mysql_select_db("mydatabase",$db); $sql = "INSERT INTO buglist VALUES (0,'$name','$org','$phone','$fax','$email','$os','$software','$verson','$severity','$comments')"; $result = mysql_query($sql); $bugsql = mysql_query("select bugid from buglist where name='$name' and org='$org' and phone='$phone' and fax='$fax' and email='$email' and os='$os' and software='$software' and version='$verson' and severity='$severity' and comments='$comments'",$db); $myrow = mysql_fetch_array($bugsql); $mybugid = $myrow["bugid"]; // Send email to Quality Assurance for this comment! $address = "qa@oursite.com"; $Subject = "Bug or Comment Submitted from Website"; $Body = "Bug ID: $mybugidnName: $namenOrganization: $orgnPhone Number: $phonenFax Number: $faxnEmail Address: $emailnOperating System: $osnSoftware: $softwarenVersion: $versionnSeverity: $severitynComments: $comments"; $From = "$email"; mail("$address","$Subject","$Body","From: $FromnReply-To: $From"); printf("<BODY BODY BGCOLOR=A4A4A4 text=black link=blue vlink=red alink=#000000 leftmargin=0 topmargin=0>"); printf("<FONT FACE=ARIAL>"); printf("<CENTER>Thank you! Your comments have been sent to Q.A. for analysis!<BR>n"); printf("Your comments have been assigned ID number %sn",$myrow["bugid"]); printf("<BR><a href="%s">Return Home</A></CENTER>","main.html"); } else{ // display form ?> <BODY BODY BGCOLOR="A4A4A4" text="black" link="blue" vlink="red" alink="#000000" leftmargin=0 topmargin=0> <FONT FACE="ARIAL"> <center><img src="media/header_customerservice.gif"></center> <CENTER><Font face="arial" color="BLACK" size ="+2"><B>Bug Report / Enhancement Request Form</b></font></center> <BR> <form method="post" action="<?php echo $PHP_SELF?>"> <table> <tr> <td><STRONG>Name:</strong></td> <td><input type=text name="name" size=50></td> </tr> <tr> <td><STRONG>Organization:</strong></td> <td><input type=text name="org" size=50></td> </tr> <tr> <td><STRONG>Phone:</strong></td> <td><input type=text name="phone" size=15></td> </tr> <tr> <td><STRONG>Fax:</strong></td> <td><input type=text name="fax" size=15></td> </tr> <tr> <td><STRONG>E-Mail:</strong></td> <td><input type=text name="email" size=45></td> </tr> </table> <BR> <STRONG><font face="arial" size="+1" color="BLACK">PLEASE ANSWER THE FOLLOWING QUESTIONS:</font></strong><br><BR> <Strong>What operating system do you currently use on the client or workstation?</strong><br><BR> <font face="arial" color="BLACK"> <input type="radio" name="os" value="Windows 95">Windows 95<BR> <input type="radio" name="os" value="Windows 98">Windows 98<BR> <input type="radio" name="os" value="Windows NT 3.x">Windows NT 3.x<BR> <input type="radio" name="os" value="Windows NT 4.0">Windows NT 4.0<BR> <input type="radio" name="os" value="Windows 2000">Windows 2000<BR> <input type="radio" name="os" value="Windows 3.1 / 3.11">Windows 3.1 / 3.11<BR> <input type="radio" name="os" value="Other">Other<BR> <BR><BR></font> <Strong>What is the software on which you are reporting?</strong><BR> <input type="text" name="software" size="40" maxlength="25"><BR><BR> <Strong>What is the version of your software?</strong><BR> <input type="text" name="version" size="40" maxlength="10"><BR><BR> <Strong>What is the severity of the problem?</strong><BR> <font face="arial" size="-1" color="BLACK"><input type="radio" name="severity" value="Program crash or data corruption">Program crash or data corruption<BR> <input type="radio" name="severity" value="Program does not function as documented">Program does not function as documented<BR> <input type="radio" name="severity" value="Minor or cosmetic bug">Minor or cosmetic bug<BR> <input type="radio" name="severity" value="Suggestion or feature request">Suggestion or feature request<BR><BR> </FONT> <font face="arial" size="+1" color="BLACK">Please include all the necessary steps to reproduce the problem or define the enhancement request:<BR></font> <textarea name="comments" rows=10 cols=80 wrap=hard></textarea> <BR><BR> <CENTER><input type="submit" name="submit" value=" Send E-Mail "> <input type="Reset" value="Clear Responses"></center> </form> <?php } // end if ?> </body> </html> Now, I tried to remove all of the <?php, ?> instances, but it still failed. How would I add the fields: <?php require ("authenticate.inc"); ...(code)... ?> to the above code so that it would parse it properly?? The first form works fine on its own, but when I add the authentication lines, along with echo '...'; to each line, it fails. Thanks! Brian. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Running PHP code within another PHP Session |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|