www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] calling php from php/html

  1. #1
    Join Date
    Jul 2012
    Posts
    41

    resolved [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

    Code:
    echo "<div class=\"mainmenu\">";
    echo "<a href=\"teams.php\"><input id=\"buttons\" type=\"button\" value=\"Teams\"></a>";
    echo "</div>";
    worked. So im confused , is it "wrong" ?

  2. #2
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    You just want people to be able to click a button and then be taken to a PHP script?

    PHP Code:
    echo '
    <div class=\'mainmenu\'>
    <form action=\'teams.php\' method=\'post\'>
    <input type=\'submit\' id=\'buttons\' value=\'Click Here\'>
    </form>
    </div>
    '

    I personally prefer single quotes around my HTML attribute values but if you don't like them you can do it this way:

    PHP Code:
    echo '
    <div class="mainmenu">
    <form action="teams.php" method="post">
    <input type="submit" id="buttons" value="Click Here">
    </form>
    </div>
    '

    And you should use single quotes with echo (e.g. echo 'hello world'; ) unless you are echoing out a variable. Example:

    PHP Code:
    $name='Bob';
    echo 
    "Hi $name"
    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:

    PHP Code:
    $name='Bob';
    echo 
    'Hi '.$name
    . joins 'Hi' and $name into one string.

    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

  3. #3
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    Quote Originally Posted by Stobor View Post
    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

    PHP Code:
    echo "<div class=\"mainmenu\">";
    echo 
    "<a href=\"teams.php\"><input id=\"buttons\" type=\"button\" value=\"Teams\"></a>";
    echo 
    "</div>"
    worked. So im confused , is it "wrong" ?
    Thats just a link to a different page, that works perfectly fine in html, However your echoing means

    1. Your actually sitting inside a .php file not an .html file

    OR

    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

    For instance
    HTML Code:
    <a href="google.com">Google</a>
    That would redirect your current page to Google.com, So lets say your current URL is

    yourwebsite.com

    and on yourwebsite.com there is a link to a php file

    HTML Code:
    <!-- yourwebsite.com -->
    <a href="simple.php">Redirect to php page</a>
    When i click that <a> tag (called an Anchor) it will change my URL to

    yourwebsite.com/simple.php

    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 03:49 AM.

  4. #4
    Join Date
    Jul 2012
    Posts
    41
    Thank you for the answers

  5. #5
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    You're welcome. Also, in my post, I assumed that the code you showed me came from a .php file.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles