php - Call to a member function query() WAMP -


this question has answer here:

here php code:

include ('dbconnect.php');    $sql = "select * products";    $result = $conn->query($sql);     if($result -> num_rows >0){      while($row = $result -> fetch_assoc()){ echo "$row[productid]"."$row[productname]";  }else { echo "0 results"; }     $conn -> close(); 

here dbconn.php code. don't know error is, if in dbconn.php or on other php page.

<?php  $conn = mysql_connect("localhost","root","") or die (mysql_error());  $conn = mysql_select_db("shoppingcart",$conn) or die (mysql_error());  ?> 

try this, avoid use of mysql instead of mysqli

include ('dbconnect.php');     $sql = "select * your_table";     $result = mysqli_query($conn, $sql);     $count = mysqli_num_rows($result);    if($count > 0) {         while($row = $result->fetch_assoc()){             echo $row['column1'] . $row['column2'] . "<br/>";         }    }  $conn -> close(); 

and connection code

$conn = mysqli_connect("localhost","root", "" ,"your_db"); if(!$conn) {     die() . mysqli_error(); } else {     //echo "connection successfull"; } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -