Jump to content

PHP mysql connection


Louffeman

Recommended Posts

Hi,I have a problem of my shopping cart script,my server indicate the error in this line: $produit = $result->fetch_assoc();error: Fatal error: Call to a member function fetch_assoc() on a non-object in C:wampserver32wwwsaleajout_panier.php on line 7je d'ont know how to solve it,anyone can help me please ?<?phpsession_start();$mysql = new mysqli('localhost', 'root', '', 'testebase');$result = $mysql->query('SELECT * FROM trybase WHERE name= '.$_POST['name']);$produit = $result->fetch_assoc();require_once 'panier.php';$valeur = array('name'=>$produit['name'],'price'=>$produit['price'],'quantity'=>$_POST['quantity']);$panier->set($_POST['name'], $valeur);header('location: votre_panier.php');?>

Link to comment
Share on other sites

@JamesBthank you for your reply, I did as you said,but now, the error is in the line 5: $mysql = new mysqli('localhost', 'root', '', 'testebase');Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in C:wampserver32wwwsalepanier.php on line 5

Link to comment
Share on other sites

yes, as you see:$mysql = new mysqli('localhost', 'root', '', 'testebase');

When i said to escape the apostrophes, this excludes the first and last per string, as shown in my example:

 

'my'pass'word'

 

 

 

@Ingolmethe server has no any error indicate before the line 5

Sometimes the error line is off by 1 line, can you post your previous line of code.

Link to comment
Share on other sites

I have corrected my script ajout_panier.phpnow, it is OK, but the last script(votre_script) still has problem in the line 7:Undefined variable: listproduit in C:wampserver32wwwsalevotre_panier.php on line 7the line 7 is: <?php if(!$listproduit){?>the output is the cart is empty, which mean's it didn't receive anything ?it is votre_script.php<?phpsession_start();require_once 'panier.php';$panier = new Panier('produits');?><?php if(!$listproduit){?><p> The cart is empty </p><?php } else {?><table border="1" width="50%"><tr><td>Name</td><td>Price</td><td>Quantity</td></tr><?php foreach($listproduit as $produit) { ?><tr><td><?php print $produit['name'] ?></td><td><?php print $produit['price'] ?></td><td><?php print $produit['quantity'] ?></td></tr><?php } ?></table><?php } ?><p><a href="index.php">Home</a></p>

Link to comment
Share on other sites

$result = $mysql->query("SELECT * FROM trybase WHERE name= '".$_POST['name']."'");
This is terrible practice, this is no better than using the deprecated mysql extension. Use prepared statements so that you don't have problems like this.https://www.google.com/search?client=opera&q=mysqli+prepared+statements+tutorial&sourceid=opera&ie=UTF-8&oe=UTF-8
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...