Jump to content

echosara

Members
  • Posts

    10
  • Joined

  • Last visited

echosara's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. this is my get_connected_db function function get_connected_db(){ try { $db = new PDO("mysql:host=localhost;dbname=test", "root", ""); $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $db->exec("SET NAMES 'utf8'"); } catch(Exception $e){ echo "could not connect to the database."; exit; } } And i took off the Try and Catch here to make it more cleaner function get_products_all() { $connect = get_connected_db(); $results = $connect->query(" SELECT id, product, description, price, picc FROM products ORDER BY id DESC "); $result = $results->fetchALL(PDO::FETCH_ASSOC); return $result; } still same error: Fatal error: Call to a member function query() on a non-object in
  2. your right it was supposed to be $connect. i changed that i still get the second error on the same line. Fatal error: Call to a member function query() on a non-object in function get_products_all() { $connect = get_connected_db(); try { $results = $connect->query(" SELECT id, product, description, price, picc FROM products ORDER BY id DESC "); } catch (Exception $e) { echo "Data could not be retrieved from the database."; exit; } $result = $results->fetchALL(PDO::FETCH_ASSOC); return $result; }
  3. Hi i have created a query where i want some columns to be retrieved. i get these 2 errors and i dont understand why. Notice: Undefined variable: db Fatal error: Call to a member function query() on a non-object in this is my query function get_products_all() { $connect = get_connected_db(); try { $results = $db->query(" ***** error on this line**** SELECT id, product, description, price, picc FROM products ORDER BY id DESC "); } catch (Exception $e) { echo "Data could not be retrieved from the database."; exit; } $result = $results->fetchALL(PDO::FETCH_ASSOC); return $result; } what am i doing wrong?
  4. i added error reporting to the script to make it like this <?php $db = new PDO("mysql:host=localhost;dbname=test", "root", ""); var_dump($db); error_reporting(E_ALL); i would like to turn on display_errors on in php.ini; however i am having a hard time locating that in my wamp server. can you provide any directory to guide me.
  5. Hi I am trying to connect to my database but i am having some problems where the server( WAMP) crashes and does not load this page. here is the php coding <?php $db = new PDO("mysql:host=localhost;dbname=test;port=80", "root", ""); var_dump($db); when i run this no error comes the page doesnt load. anyone know why? when using PDO do i have to do some sort of configuration changes to wamp? i have even changed the directory of the file and still same issue. any suggestions would be wonderful.
  6. Ok, i added that and i still get a error on a few lines. if (isset($_GET["id"])) { $proda_id =(int)$_GET["id"]; $product = get_product_id($proda_id); //if (isset($result[$id])) { //$product = $result[$id]; //} } if (!isset($product)) { header("Location: inventory.php"); exit(); } <div id="singleproduct"> <div id="singprod"> <img src="<?php echo $product["picc"];?>" > </div> <div id="productid"> <?php echo "id"."$space" .":". $product["id"]; ?></div> <div id="productname"> <?php echo "info" ."$space" .":". $product["product"];?></div> <div id="productinfo"><?php echo "Description". "$space". "Description" .":". $product["description"];?></div> <div id="productprice"><?php echo "Product Price" ."$space".":". $product["price"];?></div> </div> i pretty much get an "undefined index error on each div... singprod,productid, productname, productinfo, productprice..(above) (below) is the function which does the query function get_product_id($proda_id) { $connect = mysql_connect("localhost","root","") or die ("couldn't connect!"); mysql_select_db("test") or die("couldn't find db"); $query = mysql_query('SELECT * FROM products WHERE id = "$proda_id"'); while($product[]=mysql_fetch_array($query)); return $product; } anyone know why i get those errors?
  7. Ok, i tried this and it now doesn't display any variables on the second page. this is the coding First page inventory.php <div id="viewdetails"><a href="<?php echo BASE_URL .'view/singleproda.php?id='. $info["id"];?>"> View Details</a></div> second page singleproda.php function get_product_id($proda_id) { $connect = mysql_connect("localhost","root","") or die ("couldn't connect!"); mysql_select_db("test") or die("couldn't find db"); $product = mysql_query('SELECT * FROM products WHERE id = "$proda_id"'); return $product; } if (isset($_GET["id"])) { $proda_id =(int)$_GET["id"]; $product = get_product_id($proda_id); //if (isset($result[$id])) { //$product = $result[$id]; //} } if (!isset($product)) { header("Location: inventory.php"); exit(); } <div id="singleproduct"> <div id="singprod"> <img src="<?php echo $product["picc"];?>" > </div> <div id="productid"> <?php echo "id"."$space" .":". $product["id"]; ?></div> <div id="productname"> <?php echo "info" ."$space" .":". $product["product"];?></div> <div id="productinfo"><?php echo "Description". "$space". "Description" .":". $product["description"];?></div> <div id="productprice"><?php echo "Product Price" ."$space".":". $product["price"];?></div> </div> what am i doing wrong?
  8. Hi, I am currently working on a inventory page and a page which gets into the details of that particular product. Basically on one page i have a list of products and when i click on one of the products it takes me to another page when has more detail about the product (retrieved from the database). The problem which i am currently stuck on is when i click on say the first product (id=1) it will take me to the second page and show me product 2 (id=2) instead of the first product. here is what i have so far if anyone can assist it would be great. this is in my first inventory page.-- <div id="viewdetails"><a href="<?php echo BASE_URL .'view/singleproda.php?id='. $info["id"];?>"> View Details</a></div> this is how my second page looks--.: include(ROOT_PATH ."controller/mainfunction.php"); $result = get_products_all(); if (isset($_GET["id"])) { $proda_id = $_GET["id"]; if (isset($result[$proda_id])) { $product = $result[$proda_id]; } } if (!isset($product)) { header("Location: inventory.php"); exit(); } <div id="singprod"> <img src="<?php echo $product["picc"];?>" > </div> <div id="productid"> <?php echo "id"."$space" .":". $product["id"]; ?></div> <div id="productname"> <?php echo "info" ."$space" .":". $product["product"];?></div> <div id="productinfo"><?php echo "Description". "$space". "Description" .":". $product["description"];?></div> <div id="productprice"><?php echo "Product Price" ."$space".":". $product["price"];?></div> -------------------------------------------------------------- on the url on the second page it shows the correct ID however when i look at the information from the page ( the last 5 lines , pic, id, product, description...etc) it shows the information for id=2. This same thing happens when i click on any product ( eg id=4 or id=5) it would always give me the product information for the ID after that id i have clicked on. Any idea whats wrong with this?
  9. Hi, can anyone tell me what im doing wrong. below is a rewrite rule saved as .htaccess. the page loads and i dont get a 500 error but the url didnt change like it should have in the rewrite rule. The .htaccess is located in the root folder. Any idea what i'm doing wrong guys? <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^products/$ view/inventory.php </IfModule>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.