tet3828 Posted November 3, 2006 Share Posted November 3, 2006 This should be an easy one...If this line of code was already inside a PHP bracket ( [color=red]<?php ?> [/color] ) how would I re-write it? <form method="post" action="[color=red]<?[/color]php echo $PHP_SELF;[color=red]?>[/color]"> Quote Link to comment https://forums.phpfreaks.com/topic/26025-forms-in-php/ Share on other sites More sharing options...
Daniel0 Posted November 3, 2006 Share Posted November 3, 2006 It would be [code]<form method="post" action="{$PHP_SELF}">[/code] Quote Link to comment https://forums.phpfreaks.com/topic/26025-forms-in-php/#findComment-118978 Share on other sites More sharing options...
tet3828 Posted November 3, 2006 Author Share Posted November 3, 2006 Do I need to echo "" before that line? or is there some options other then echo ""? Quote Link to comment https://forums.phpfreaks.com/topic/26025-forms-in-php/#findComment-118998 Share on other sites More sharing options...
.josh Posted November 3, 2006 Share Posted November 3, 2006 you need to be a bit clearer in your question, but I THINK what you are looking for is something like this:<?php echo "<form method='post' action='$PHP_SELF'>";?> Quote Link to comment https://forums.phpfreaks.com/topic/26025-forms-in-php/#findComment-119000 Share on other sites More sharing options...
tet3828 Posted November 3, 2006 Author Share Posted November 3, 2006 Thanks C.VI tried turning this block of code into PHP from HTML because I needed it to be a [color=green]case[/color] in a [color=green]switch[/color]im having a hard time converting it from html to php. I fix one line and the next give me a parse error.the times you are requiered to use piticular brackets and quotes in this language ( or any other isthrowing me off. I think the first line is okay but the rest I could really use some help. echo "<form method='post' action='$PHP_SELF}'>";echo "<input type=hidden name=edit value='$_POST['edit']'>";echo "<input type="hidden" name="id" value="{$_GET['id']}">";echo "<input type="radio" name="newName" value="yes"> Yes <br />";echo "<input type="radio" name="newName" value="no"> No <br />";echo "<input type="submit" name="submit" value="Submit" />"; Quote Link to comment https://forums.phpfreaks.com/topic/26025-forms-in-php/#findComment-119010 Share on other sites More sharing options...
.josh Posted November 3, 2006 Share Posted November 3, 2006 okay here is a quick and dirty rundown of using quotes. You have 2 quote options: single quotes and double quotes. If you are displaying plain old text and nothing else, for all intents and purposes, they do the same thing. The real difference comes in wanting to throw variables into it or use quotes inside of quotes. For instance, you can do this:echo "blah 'blah' blah"; but not this:echo "blah "blah" blah"; because the parser will think you are closing the brackets. You can avoid this by doing this:echo "blah \"blah\" blah"; using the backslash is called escaping the character. It tells the parser to parse it as regular text and not some key thing. The escape character also has other purposes too, like doing this:echo "blah \r\n blah"; this is (not the same) but for the most part, the same as doing this:[code]echo "blah <br> blah";[/code]Okay back to the quotes. When you have a simple variable, if you do this:$blah1 = "bob";$blah2 = 'joe';echo "hello $blah1 and $blah2"; // notice the double quotesyou get this:hello bob and joeas mentioned above, with simple text, for all intents and purposes, there is no difference between $blah1 and $blah2. but if you did this:echo 'hello $blah1 and $blah2'; // notice the single quotesthe parser will look at your variables and treat them like normal text, instead of replacing the variables with their values. it will literally output this:hello $blah1 and $blah2okay so now you know if you wanna do hello bob instead of hello $blah1 you need to use double quotes. okay moving along to more complex variables, like arrays:$blah1 = array('foobar' => 123);okay I can do this:echo $blah1['foobar']; and it outputs this:123but if I want to do this:echo "$blah1['foobar']";double quotesor even thisecho '$blah1['foobar']'; //single quotesthe parser gets confused, as to whwhere the string starts and ends, what part is the variable and what part is the string, and a whole other mess of things. Even if you used the nifty \ character, there would still be confusion as to what part is the variable and what part is some other something else. This is called ambiguity - that is, not being able to tell what from what. In order to avoid this, we have { } so in order for php to parse it right, it would look like this:echo "I can count to {$blah['foobar']} !";outputs:I can count to 123 !here is what your code should look like:[code]echo "<form method='post' action='{$_SERVER['PHP_SELF}'>";echo "<input type='hidden' name='edit' value='{$_POST['edit']}'>";echo "<input type='hidden' name='id' value="{$_GET['id']}'>";echo "<input type='radio' name='newName' value='yes'> Yes";echo "<input type='radio' name='newName' value='no'> No";echo "<input type='submit' name='submit' value='Submit' />";[/code]okay now, not to confuse you even more, but there are even more efficient ways of doing this, like using the [url=http://www.php.net/heredoc]heredoc[/url] method, but for now, this will work for you. Quote Link to comment https://forums.phpfreaks.com/topic/26025-forms-in-php/#findComment-119015 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.