Jump to content

Print Is Printing Variable Names Not Values?


wongadob

Recommended Posts

I have been working on this for 1 hour now and I just can't figure out why this is happening. I know single quotes normally show the variable names and double quotes don't so why is this code printing the variable name and not the value. PHP code is

<!--------------------------------------------------------------------------------------------------------------------PHP file for loginCreated - Thursday November 3rd, 2011----------------------------------------------------------------------------------------------------------------------><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"><head>  <meta http-equiv="content-type" content="text/xml; charset=utf-8" />  <title>Login</title></head><body>  <?php  $txtUserName = $_POST["txtUserName"];  $txtPassword = $_POST["txtPassword"];  print "<p>Username is $txtUserName and the password is $txtPassword</p>";  ?></body></html>

It is called from this HTML code

<div id = "mainbody">   <form method = "post" action = "php\login.php">    <fieldset>	 <p>	  <br/><br/><br/>	  <label>Username </label>	  <input type ="text"		  name = "txtUserName"/>	  <br/><br/><br/>	  <label>Password </label>	  <input type ="password"		  name = "txtPassword"/>	  <br/><br/><br/>		 	  <button type = "submit"> <img src = "Art\Menu Buttons - Enter.png" alt = "Enter"/> </button>	  <br/>   	  	 </p>	 <div id = "ErrorMessageArea">	 </div>    </fieldset>   </form>  </div>

The output I get is this:- Username is $txtUserName and the password is $txtPassword " ?> WHY!!!!!

Link to comment
Share on other sites

Are you trying to get the browser to tell you what the Username and password is?If so then use this code instead:

echo "<p>Username is {$txtUserName} and the password is {$txtPassword}</p>";

Link to comment
Share on other sites

I tried that change and got slightly different output ???? Username is {$txtUserName} and the password is {$txtPassword} "; ?> WTF is going on here it makes no sense. I have checked if there are any wierd characters that are confusing the system but I can't see any! Why is the ";?> bring printed at all looks like it does not know how to finish the PHP. Maybe does not even know that it is PHP but how ?

Link to comment
Share on other sites

Also something else worth noting is that I have Microsoft Visual Studio installed on my Laptop (not on the server where Xampp is) so when I use localhost it connects to IIS7 on my Laptop. I assume it is visual studio that installed it on my laptop so there is also Microsoft SQL server on my laptop. Don't know if this will cause a conflict. i know there are problems if it is installed on the same PC as Xampp.

Link to comment
Share on other sites

The local IP address is accessed as such I guess. I tried typing this into my browser (on my laptop) http://192.168.1.2/xampp/htdocs/compliance But when I try to access that I get this Access forbidden!

New XAMPP security concept:
Access to the requested object is only available from the local network.This setting can be configured in the file "httpd-xampp.conf". If you think this is a server error, please contact the webmaster. Error 403 192.168.1.2 11/03/11 21:26:59 Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 But this machine is on my network, The settings in httpd-xampp.conf seem to allow all on my network. ( the allow statement seems to show the full ip range) The firewall on my main PC (xampp pc) has access allowed for xampp and port 80 is open. ??
Link to comment
Share on other sites

There does not seem to be an option to do such things in xampp. I go onto apache server and it doesn't seem to have any options like that. If you are using Wamp then that is apache is it not. Surely they would be the same. How do you get to that option in your WAMP?

Link to comment
Share on other sites

Yes, but WAMP has its own interface so I don't need to modify apache directly. It's just a context menu from the WAMP icon in the taskbar. I can also use it to activate PHP libraries and Apache modules without having to change httpd.conf or anything like that.You'll have to see your configuration files to find a way to give access to the server from other computers on the network.

Link to comment
Share on other sites

Try this print "<p>Username is ".$txtUserName." and the password is ".$txtPassword."</p>"; Hope it helps.
The code wasn't the problem. Have you been reading the thread?
Link to comment
Share on other sites

Just a suggestion.If you haven't done really anything with xampp I would maybe suggest switching to WAMP. In my opinion very user friendly and Fox and I could help you with it.You don't have to switch, but if you haven't made any databases it wont hurt to switch. Totally up to you.

Link to comment
Share on other sites

I have solved it !!!!!! This is now Solved - However it was nothing to do with my code. The reason was the htt[d-xampp.conf file needed modifying in the following way. I am adding this in case anybody has simiar issues and they know how it was resolved.

# Close XAMPP sites here<LocationMatch "^/(?i:(?:xampp|licenses|phpmyadmin|webalizer|server-status|server-info))">Order deny,allowDeny from allAllow from ::1 127.0.0.0/8 \fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \fe80::/10 169.254.0.0/16ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var</LocationMatch>

Don't ask me what any of this actually means, but I guess it is allowing access to machines on a local network. Anyway once I did this and re-booted my Webserver PC (must be done apparently) it all worked. Hope this helps solve somebody else's problem as this had me pulling my hair out for most of a day. Once this was done my code worked fine. I knew there was nothing wrong with the code. It has to be right, but in moments of extreme stress you doubt even your own name!! Thanks for all the advice everyone!

Link to comment
Share on other sites

@newbie - I already have my database set up on Xampp, although I do have all the SQL scripts to set it up anywhere and the population code in excel that poulated the database, I have made it as portable as my limited knowledge will allow, but my learning curve has been so steep I don't really want to add any more to learn just now. Thanks for the tip and once I complete this project (if my brain has not exploded with new information) I will investigate better solutions for future work. I have been out of programming for a long time. I was a game programer 1978-1990 so the last code I wrote (until recently and aside from Excel VBA) was 68000 assembly language for Amiga and ST! Moved over to the dark side (management) for the last 20 years, but returning to coding now! And I am really enjoying it (apart from the network issues). Once again thanks all for your info and help, one day when I am more au fait with all this stuff I shall return the favour!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...