Tuesday, 15 March 2011

php - How to connect a HTML page to MySQL -



php - How to connect a HTML page to MySQL -

how connect html page mysql example, want utilize <?php echo $_post['username']; ?> in html file. how connect mysql. have tryed this:

<?php $con=mysql_connect("host", "username", "password"); mysql_select_db("database"); ?>

but did not work.

html markup languages, set of tags <html>, <body>, used nowadays website using css, , javascript whole. these, happen in clients scheme or user browsing website.

now, connecting database, happens on whole level. happens on server, website hosted.

so, in order connect database , perform various info related actions, have utilize server-side scripts, php, jsp, asp.net etc.

now, lets see snippet of connection using mysqli extension of php

$db = mysqli_connect('hostname','username','password','databasename');

this single line code, plenty started, can mix such code, combined html tags create html page, show info based pages. example:

<?php $db = mysqli_connect('hostname','username','password','databasename'); ?> <html> <body> <?php $query = "select * `mytable`;"; $result = mysqli_query($db, $query); while($row = mysqli_fetch_assoc($result)) { // display datas on page } ?> </body> </html>

in order insert new info database, can utilize phpmyadmin or write insert query , execute them.

php html mysql post

No comments:

Post a Comment