html - PHP not displaying anything in MAMP -


im new php , trying record information display on php page using mamp server environment.

the attributes productid, productname, productdescription , productprice.

i've been able basic php run fine every time open php file, nothing displays, wandering if might location placed php file. in htdocs. appreciate help.

thanks

<?php     //connection db     mysql_connect('localhost', 'root', 'root');      //choosing db     mysql_select_db(primrose);      $sql= "select * products";      $records mysql_query(sql); ?>  <html> <head>     <title>product data</title> </head> <body>     <table width="600" border="1" cellpadding="1" cellspacing="1">           <tr>             <th>name</th>             <th>description</th>         </tr>      <?php     //loops on each record , each new record set variable products     while(products=mysql_fetch_assoc($records)){         echo "<tr>";         echo "<td>".$products['productname']."</td>";         echo "<td>".$products['productdescription']."</td>";         echo "</tr>";      } //end while     ?>      </table> </body> </html> 

this because (i think) line bad:

mysql_select_db(primrose); 

add quotes around name of db:

mysql_select_db("primrose"); 

also line:

$records mysql_query(sql); 

change

$records = mysql_query($sql); 

and this:

while(products=mysql_fetch_assoc($records)){ 

to

while($products=mysql_fetch_assoc($records)){ 

note 1:

  • do not use mysql functions since, deprecatid. use mysqli or pdo instead.

note 2:

let's turn on error reporting these 2 rows in top of php file:

error_reporting(e_all); ini_set('display_errors', 1); 

you have lot of syntax errors. let's use ide identify them.

so final code this:

<?php error_reporting(e_all); ini_set('display_errors', 1);  //connection db mysql_connect('localhost', 'root', 'root'); //choosing db mysql_select_db("primrose"); $sql= "select * products"; $records = mysql_query($sql); ?> <html> <head>     <title>product data</title> </head> <body>     <table width="600" border="1" cellpadding="1" cellspacing="1">     <tr>         <th>name</th>         <th>description</th>     </tr>     <?php     //loops on each record , each new record set variable products     while($products=mysql_fetch_assoc($records)){         echo "<tr>";         echo "<td>".$products['productname']."</td>";         echo "<td>".$products['productdescription']."</td>";         echo "</tr>";     } //end while     ?>     </table> </body> </html> 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -