[RESOLVED] calling php from php/html
I'm new to web programing, and so i spent almost 4 hours trying to open one php file from the button click event. in that time i red many posts that you cant call php file from html file and you need to use js to use ajax to call php and other confusing things but in the end
worked. So im confused , is it "wrong" ?
echo "<div class=\"mainmenu\">";
echo "<a href=\"teams.php\"><input id=\"buttons\" type=\"button\" value=\"Teams\"></a>";
You just want people to be able to click a button and then be taken to a PHP script?
I personally prefer single quotes around my HTML attribute values but if you don't like them you can do it this way:
<form action=\'teams.php\' method=\'post\'>
<input type=\'submit\' id=\'buttons\' value=\'Click Here\'>
And you should use single quotes with echo (e.g. echo 'hello world'; ) unless you are echoing out a variable. Example:
<form action="teams.php" method="post">
<input type="submit" id="buttons" value="Click Here">
Though to be honest, I never see anybody do that. Everybody seems to separate the variables from the rest of the data when they're echoing something:
echo "Hi $name";
. joins 'Hi' and $name into one string.
echo 'Hi '.$name;
This is one of the first questions I've ever tried to answer on this forum. I usually just ask questions. This one seemed so easy, though, I thought I'd give it a try. I hope I did good :3
Thats just a link to a different page, that works perfectly fine in html, However your echoing means
Originally Posted by Stobor
1. Your actually sitting inside a .php file not an .html file
2. You have a .htaccess file with AddType application/x-httpd-php .html/.htm
in it which allows php to be ran through an html/htm page.
And im just basing that all off the fact you are using Echo's, and those have no place in html
That would redirect your current page to Google.com, So lets say your current URL is
and on yourwebsite.com there is a link to a php file
When i click that <a> tag (called an Anchor) it will change my URL to
<!-- yourwebsite.com -->
<a href="simple.php">Redirect to php page</a>
When you sit on the main domain of a website for instance google.com
your actually on a sub page but the browser hides the default file name from you.
So when you go to yourwebsite.com you are actually on yourwebsite.com/index.html or yourwebsite.com/index.php (even though .html has more priority in terms of structure over .php file extensions)
I know its confusing just do some googling and reading of the anchor tag and you will get it
Last edited by Nvenom; 07-25-2012 at 02:49 AM.
Thank you for the answers
You're welcome. Also, in my post, I assumed that the code you showed me came from a .php file.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)