Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2013
    Location
    Kentucky
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Passing PHP variables into html tags

    I have a php script that gets a string from my MySQL database and puts certain elements into variables.

    PHP Code:
    <?php
    $connection 
    mysqli_connect('database','user','pw','the_sleeper');
    $audiopath mysqli_query($connection,"select * from the_sleeper");
    $row mysqli_fetch_array($audiopath);
    $audio=$row['audiopath'];
    $title$row['title'];
    ?>
    Now I want these two variables on to my main page. I want the audiopath to be passed to an audio embed tag and title to be passed into a heading tag. How can I do this?
    Here is the link to the page I will be passing them to:http://www.j10thesleeper.net84.net/J...rhomepage.html
    Thank you all for your time!
    Last edited by torsaur; 03-16-2013 at 10:33 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    PHP Code:
    <audio controls>
      <source src="<?php echo $audio?>" type="audio/mpeg"/>
    </audio>
    Code:
    <h2> <?php echo $title; ?></h2>
    Do you mean this?

  • #3
    New Coder
    Join Date
    Mar 2013
    Location
    Kentucky
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    First I need to call the php file itself. I have the file stored so I want to link it in and have it run without putting the code itself directly on the html page.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,642
    Thanks
    6
    Thanked 1,004 Times in 977 Posts
    That’s not possible, you have to somehow insert PHP code into your current HTML page, otherwise the page wouldn’t know what to display.

  • #5
    New Coder
    Join Date
    Mar 2013
    Location
    Kentucky
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Isn't it a security concern to have my MySQL database, username, and password out there for everyone to see?

  • #6
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Quote Originally Posted by torsaur View Post
    Isn't it a security concern to have my MySQL database, username, and password out there for everyone to see?
    The file is .php it can't be read by going to the url www.example.com/connect.php

  • #7
    New Coder
    Join Date
    Mar 2013
    Location
    Kentucky
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you all! I didn't realize that if you coded php directly onto a page it couldn't be seen through view source!

  • #8
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Quote Originally Posted by torsaur View Post
    Thank you all! I didn't realize that if you coded php directly onto a page it couldn't be seen through view source!
    You must make sure the extension is dot php else users can view php code because it will display as text.


  •  

    Tags for this Thread

    Posting Permissions

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