3 Replies - 1782 Views - Last Post: 04 June 2013 - 02:11 PM Rate Topic: -----

#1 rimfaxe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-March 13

calling PHP from html

Posted 04 June 2013 - 06:12 AM

Hello Forum,
I really would like very much to separate structure, design an logic. That is what i preeched in many books and posts and that was why I started out cleaning up all my older scripts (mixture of PHP and html).
I now have a nice validated HTML5 template with nice validated css's working - flexible and without problems with floats or the like. Working from HTML, I have problems in population a form select with data from mysql.

HTML code
     <div id="primary"> <!-- div for left side -->
	 <article>
	    <form id="form4" action="#" method="post">
	        <fieldset>
            <legend></legend>
	        <p></p>
            <p><label for="owner_name">Fornavn</label><input id="owner_name" type="text" name="owner_name" /></p>
            <p><label for="owner_family_name">Efternavn</label><input id="owner_family_name" type="text" name="owner_family_name" /></p>
            <p><label for="owner_dsf_nr">DSF-nr</label><input id="owner_dsf_nr" type="text" placeholder="Fra dit medlemskort" name="owner_dsf_nr" /></p>
            <p><label for="club_name">Klub</label><select name="club_name"><option size="30"></option>

                  
                </select></p>
            <p><label for="owner_email">E-mail</label><input id="owner_email" type="text" name="owner_email" /></p>


Above code does of cause not work - as the populating part of the select is missing.
PHP code, which I used to populate form select(from a PHP script). This is the functionality I am looking for.'
            <?php
                include('includes/connection.php');
                $sql = "SELECT club_name FROM dive_club";
                echo "<select name=\"club_name\">";
                echo "<option size=30 ></option>";
                $result=$con->query($sql);
                while ($row = mysqli_fetch_array($result))
                    {
                    echo "<option value ='".$row['club_name']."'>".$row['club_name']."</option>";    
                    }
                ?>  



ASAIK, html cannot execute php - how do you guys separate - do I have to do it the other way around and make a html5 generator in PHP?
I really would like to make my codes as clean as possible, but cannot see a way out of this dilemma.
Please advise as I really need this to work - even if it takes to write a html5 generator.

Is This A Good Question/Topic? 0
  • +

Replies To: calling PHP from html

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12657
  • View blog
  • Posts: 45,830
  • Joined: 27-December 08

Re: calling PHP from html

Posted 04 June 2013 - 06:30 AM

Moved to PHP.

Check out CTphpnwb's tutorial on content-code separation. The way these technologies work is that your browser displays the website (HTML). You then make a request, and the browser (the client) sends that request to the server. The server (PHP) processes the request and sends back a response. The client then displays that response.

codeprada also has a templating tutorial you may find helpful.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4239
  • View blog
  • Posts: 13,441
  • Joined: 08-June 10

Re: calling PHP from html

Posted 04 June 2013 - 06:41 AM

and also a tutorial about creating dropdowns.


Spoiler

Was This Post Helpful? 2
  • +
  • -

#4 rimfaxe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-March 13

Re: calling PHP from html

Posted 04 June 2013 - 02:11 PM

View Postmacosxnerd101, on 04 June 2013 - 06:30 AM, said:

Moved to PHP.

Check out CTphpnwb's tutorial on content-code separation. The way these technologies work is that your browser displays the website (HTML). You then make a request, and the browser (the client) sends that request to the server. The server (PHP) processes the request and sends back a response. The client then displays that response.

codeprada also has a templating tutorial you may find helpful.


Thank you macosxnerd101,
The problem I have encountered is generation of the website (population the form), thus not being able to let the client send a request (submitting the form).
I now have the page done as a PHP page, which holds a HTML-file. I have had to break it a bit (to populate the form select field) and to include a standard html-doc, everything works
I am still aiming at a total separation and hope that I will develop the skills needed. - thank you again to you and Dormilich.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1