/    Sign up×
Community /Pin to ProfileBookmark

[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>”;[/CODE]

worked. So im confused , is it “wrong” ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@evenstar7139Jul 25.2012 — You just want people to be able to click a button and then be taken to a PHP script?

[code=php]echo '
<div class='mainmenu'>
<form action='teams.php' method='post'>
<input type='submit' id='buttons' value='Click Here'>
</form>
</div>
';[/code]


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

[code=php]echo '
<div class="mainmenu">
<form action="teams.php" method="post">
<input type="submit" id="buttons" value="Click Here">
</form>
</div>
';[/code]


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

[code=php]$name='Bob';
echo "Hi $name";[/code]


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:

[code=php]$name='Bob';
echo 'Hi '.$name;[/code]


. joins 'Hi' and $name into one string.

[B]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[/B]
Copy linkTweet thisAlerts:
@NvenomJul 25.2012 — 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=php]echo "<div class="mainmenu">";
echo "<a href="teams.php"><input id="buttons" type="button" value="Teams"></a>";
echo "</div>";[/code]

worked. So im confused , is it "wrong" ?[/QUOTE]


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
    [code=html]
    <a href="google.com">Google</a>
    [/code]


    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

    [code=html]
    <!-- yourwebsite.com -->
    <a href="simple.php">Redirect to php page</a>
    [/code]


    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 ?
    Copy linkTweet thisAlerts:
    @StoborauthorJul 25.2012 — Thank you for the answers
    Copy linkTweet thisAlerts:
    @evenstar7139Jul 25.2012 — You're welcome. Also, in my post, I assumed that the code you showed me came from a .php file.
    ×

    Success!

    Help @Stobor spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...