ball420 Posted January 26, 2007 Share Posted January 26, 2007 i'm just learning php and making ok progress. i'm testing stuff out and having a major problem.. here is my simple html code ok..<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><h1>Search for the shit</h1><p> </p><form action="resultsbyname.php" method="post"> <p>enter the name of what your seeking</p> <p> </p> <p> <input name="name" type="text" /> </p> <p> <input name="submit" type="submit" value="search" /> </p></form><p> </p></body></html>so i have that now i have my simple php code<?echo $name;?>now when i type into my form and hit submit it should show that text on the next page, well it doesn't it connects to the page but it's just blank??i don't understand please help Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 26, 2007 Author Share Posted January 26, 2007 is there somthing i'm missing here Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 We'd need to see the code for the "blank" page.Make sure you have error reporting turned on. Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 26, 2007 Author Share Posted January 26, 2007 the code for the next php is <?echo $name?>when i type anyhting in the text field it should show up right cause name is my variable Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2007 Share Posted January 26, 2007 $name is set to $name = $_POST['name'] correct? Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 26, 2007 Author Share Posted January 26, 2007 on the html code input name is set to "name"that should echo anything typed in to show when you put in $name to your php scriptremember this is only to test nothing complicated Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 26, 2007 Share Posted January 26, 2007 Register_globals is probably disabled (good thing), so you need to reference the variable in the $_POST superglobal array:[code]<?phpecho $_POST['name'];?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Plus you need a ; at the end. Quote Link to comment Share on other sites More sharing options...
Asheeown Posted January 26, 2007 Share Posted January 26, 2007 ken is absolutely right it's not anything wrong with the echo statement or the page...when you post a form to a new page the values get entered in the $_POST array for example:If the name of the text box was "name":[code]$name = $_POST['name'];echo $name;[/code]or[code]echo $_POST['name'];[/code] Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 26, 2007 Author Share Posted January 26, 2007 it still not working here is my php code<?$name = $_POST['name'];echo $name;?>here is the code from the html page<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><h1>Search for the shit</h1><p> </p><form action="resultsbyname.php" method="post"> <p>enter the name of what your seeking</p> <p> </p> <p> <input name="name" type="text" /> </p> <p> <input name="submit" type="submit" value="search" /> </p></form></body></html>what am i doing wrong?? Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted January 26, 2007 Share Posted January 26, 2007 You should use <?php, that may be the problem anyway.[code]<?php$name = $_POST["name"];echo $name;?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><h1>Search for the shit</h1><p> </p><form action="" method="post"> <p>enter the name of what your seeking</p> <p> </p> <p> <input name="name" type="text" /> </p> <p> <input name="submit" type="submit" value="search" /> </p></form></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 26, 2007 Author Share Posted January 26, 2007 that worked what is the differance between the <? and <?phpthanks for the help these tutorials i'm doing suck it works for the guy doin them but when i do it stuff has to be different why is this??? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 In order to use <?, short tags must be on in the php.ini. I believe it's on by default, so it's weird that yours is off, but it is considered best practice to use <?php Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 26, 2007 Author Share Posted January 26, 2007 would ther be any way to turn it on??? i'm in the learning process and it could make some things difficult in the future don't you think. if the classes im taking the guy is doing it with his settings differnent than mine???thanks for the replies Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 Edit the php.ini file. (Google for help) Quote Link to comment Share on other sites More sharing options...
Caesar Posted January 27, 2007 Share Posted January 27, 2007 [quote author=ball420 link=topic=124222.msg514461#msg514461 date=1169855918]would ther be any way to turn it on??? i'm in the learning process and it could make some things difficult in the future don't you think. if the classes im taking the guy is doing it with his settings differnent than mine???thanks for the replies [/quote]Well, it's generally good practice to write your code with every scenario possible in mind. i.e, short tags or register globals being disabled. You want your code to be as compatible as possible under varrying circumstances/servers. Quote Link to comment Share on other sites More sharing options...
trq Posted January 27, 2007 Share Posted January 27, 2007 Its best to get in the habit of using the longer <?php tags. This is guaranteed to work on all setups.Also, if you don't want any errors you need to check this variable is set first. eg; Your code should look like....[code]<?php if (isset($_POST['name'])) { $name = $_POST['name']; echo $name; }?>[/code]Its also best to get in this habit as early as possible. Quote Link to comment 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.