Hi, I am a learner of PHP by myself. I just started to learn it! I am facing a problem in connectivity with database. Please check the given detail and tell me how to fetch data from database and where I am wrong. Database Name : dynamicsite Table Names : 1) meta 2) pg_layout conn.php <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'sumit'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'dynamicsite'; mysql_select_db($dbname, $conn); ?> phone.php <?php include "conn.php"; $pagename = $_GET["ph"]; $pagename = trim(str_replace("-", " ", $pagename)); $query = "select title, description, keyword from meta where pg_name=$pagename;"; $result = mysql_query($query); ?> <html> <head> <title><?php echo $pagename . $result['title']; ?></title> <meta name="description" content='<?php echo $result["description"]; ?>' /> <meta name="keywords" content='<?php echo $result["keyword"]; ?>' /> </head> Is this information enough??
Hi, you just run this script in your server. then if you get any error, write the error here. Hope we will be able to help you. thnaks
password should be empty, if your using root (mysql by default has no password, and if your developing your site by your localhost then password should be empty) fetching your records by executing mysql_fetch_array($youvariable); just replied to your pm, hope this helps.
Need to understand mysql_fetch_array. Please see my article: The Difference Between mysql_fetch_array() And mysql_fetch_assoc()
Your doing it wrong... You need to work with the function mysql_fetch_array, do the querry first and then the fetch array function. Example: $query = "SELECT * FROM meta pg_name=$pagename"; $do_query = mysql_query($query) or die(mysql_error()); $result = mysql_fetch_array($do_query) or die(mysql_error()); echo $result['title']." - ".$result['description']."-".$result['keyword']; PHP: