Jump to content
Larry Ullman's Book Forums

olaoyesunday

Members
  • Posts

    47
  • Joined

  • Last visited

olaoyesunday's Achievements

Newbie

Newbie (1/14)

  • First Post Rare
  • Collaborator Rare
  • Week One Done Rare
  • One Month Later Rare
  • One Year In Rare

Recent Badges

0

Reputation

  1. Sir, You are right. what I don't know is how to insert values into the third table that is why I repeated what I did in the second table. I also want to make use of proudict_id in the third table. If you can assist with this explanation I will be glad.
  2. Dear larry, thanks very much for your reply. It did not give me any error on the screen it just said it was inserted successfully but when I check the PHPmyadmin, the first two queries inserted values to the product table and the product2size table which is the first cross reference table for a particular product which has many sizes in the sizes table, but the second cross-reference table which is product2pcat table which also supposed to get the insert product_id of the same product and many catecories_id which a product belong to. i know I should use the primary key of the last->insertid but since I also want it to insert the primary key of the product table the product2pcat table. My question is this what should I do for the third table that is product2pcat cross reference table to have values when I click the submit button on the page.
  3. Dear All, I was trying to insert records into multiple tables in one file. The first two queries ran very well but the third one did not run. The first table is normal table while the last 2 tables are cross-reference tables, which store primary keys of two tables each. Here is the code snippets for your help: // initialize prepared statement $stmt = $con->stmt_init(); $insert_product = "INSERT INTO products (cat_id, manufacturer_id,date,product_title,product_url,product_img1,product_img2,product_img3,product_price,product_keywords,product_desc,product_features,product_video,seo_keywords,product_label,product_sale ) VALUES(?, ?, NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // bind parameters and execute statement if ($stmt->prepare($insert_product)) { // bind parameters and execute statement $stmt->bind_param('iisssssisssssss', $cat, $manufacturer_id, $product_title, $product_url,$product_img1,$product_img2,$product_img3,$product_price,$product_keywords,$product_desc,$product_features,$product_video, $product_seo,$product_label,$product_sale ); $stmt->execute(); if ($stmt->affected_rows > 0) { echo "<script>alert('Product has been inserted sucessfully')</script>"; } } // if the product entry was inserted successfully, check for sizes if (($stmt->affected_rows > 0) && isset($_POST['size'])) { // get the product's primary key $product_id = $stmt->insert_id; foreach ($_POST['size'] as $size_id) { if (is_numeric($size_id)) { $values[] = "($product_id, " . (int) $size_id . ')'; } } if ($values) { $sql = 'INSERT INTO product2size (product_id, size_id) VALUES ' . implode(',', $values); // execute the query and get error message if it fails if (!$con->query($sql)) { $sizeError = $con->error; } } } // third query // if the product entry was inserted successfully, check for product categories if (!isset($sizeError) && isset($_POST['product_cat'])) { // get the product's primary key $product_id = $stmt->insert_id; foreach ($_POST['product_cat'] as $p_cat_id) { if (is_numeric($p_cat_id)) { $values[] = "($product_id, " . (int) $p_cat_id . ')'; } } if ($values) { $sql = 'INSERT INTO product2pcat (product_id, p_cat_id) VALUES ' . implode(',', $values); // execute the query and get error message if it fails if (!$con->query($sql)) { $pcatError = $con->error; } } } My problem is that I wouldn’t know what I did wrong that is preventing the third query to run.
  4. Dear all, Please can anyone help, I am writing a code for updating one or all the 3 images in my product page but the query was not running, The below is the code I am trying to work on and I think is the line one that is causing the issue but I don't know what to do. if(is_uploaded_file($_FILES['file']['tmp_name'])){ // work for upload / update image $product_img1 = $_FILES['product_img1']['name']; $product_img2 = $_FILES['product_img2']['name']; $product_img3 = $_FILES['product_img3']['name']; $temp_name1 = $_FILES['product_img1']['tmp_name']; $temp_name2 = $_FILES['product_img2']['tmp_name']; $temp_name3 = $_FILES['product_img3']['tmp_name']; move_uploaded_file($temp_name1,"product_images/$product_img1"); move_uploaded_file($temp_name2,"product_images/$product_img2"); move_uploaded_file($temp_name3,"product_images/$product_img3"); $update_product = "update products set p_cat_id='$product_cat',cat_id='$cat',manufacturer_id='$manufacturer_id',date=NOW(),product_title='$product_title',product_url='$product_url',product_img1='$product_img1',product_img2='$product_img2',product_img3='$product_img3',product_price='$product_price',product_keywords='$product_keywords',product_desc='$product_desc',product_sale='$product_sale',product_label='$product_label',product_features='$product_features',product_video='$product_video' where product_id='$p_id'"; $run_product = mysqli_query($con,$update_product); if($run_product){ echo "<script>alert('Your product has been updated Successfully')</script>"; echo "<script>window.open('index.php?view_products','_self')</script>"; } }else{
  5. okay thanks but I am trying to use foreach loop where I want to enter the $_Post['size'] into database but don't know how to assign the $i variable below back to the $size variable if(isset($_POST[‘submit’])){ $size = $_POST[‘size’]; foreach ($size as $i) { echo ("$i<br>"); } $insert_product = "insert into products (size) values (’$size’)
  6. Thanks very much sir, I still need your help. How do I allow size_id column in product table to store more than one size_id on a single record? I tried it directly in phpmyadmin to insert more than one size_id on the size_id column but it was given error
  7. Please, I want to convert this single select option to multiple choice select options. i,e to select more than one option in the select dropdown <?php $get_sizes = "select * from sizes"; $run_sizes = mysqli_query($con,$get_sizes); while ($row_sizes=mysqli_fetch_array($run_sizes)){ $size_id = $row_sizes['size_id']; $size_name = $row_sizes['size']; echo " <option value='$size_id'> $size_name </option> "; } ?> </select><!-- form-control Finish -->
  8. Thanks ,you have answered my question by executing the INSERT AND SELECT QUERY differently.
  9. Please can anybody help, I am trying to convert one Insert query and one select query to prepared statement but I was stuck on the way. No.1 below is the original code that I want to convert to prepared statement, No.2 is the one that I am working but get stucked No.1 $insert_customer = "insert into customers (customer_name,customer_email,customer_pass, customer_country,customer_city,customer_contact, customer_address,customer_image,customer_ip) values ('$c_name','$c_email','$c_pass','$c_country', '$c_city','$c_contact','$c_address', '$c_image','$c_ip')"; $run_customer = mysqli_query($dbc,$insert_customer); $sel_cart = "select * from cart where ip_add='$c_ip'"; $run_cart = mysqli_query($cdbc,$sel_cart); $check_cart = mysqli_num_rows($run_cart); if($check_cart>0){ /// If register have items in cart /// $_SESSION['customer_email']=$c_email; echo "<script>alert('You have been Registered Sucessfully')</script>"; echo "<script>window.open('checkout.php','_self')</script>"; }else{ /// If register without items in cart /// $_SESSION['customer_email']=$c_email; echo "<script>alert('You have been Registered Sucessfully')</script>"; echo "<script>window.open('index.php','_self')</script>"; } } ?> 2 here is the prepared statement I am working on but get stucked. I just want to know how to combine the two queries together . $insert_customer = "INSERT INTO customers (customer_name,customer_email,customer_pass, customer_country,customer_city,customer_contact, customer_address,customer_image,customer_ip) VALUES (?,?,?,?,?,?,?,?,?)"; // Prepare the statement: $stmt = mysqli_prepare($dbc, $insert_customer); // Bind the variables: mysqli_stmt_bind_param($stmt, 'ssssssssi', $c_name,$c_email,$c_pass, $c_country,$c_city,$c_contact, $c_address,$c_image,$c_ip); $sel_cart = "select * from cart where ip_add=?"; $stmt = mysqli_prepare($cdbc,$sel_cart); // Bind the variables: mysqli_stmt_bind_param($stmt,'i',$c_ip); // Execute the query: mysqli_stmt_execute($stmt); if (mysqli_stmt_affected_rows($stmt) == 1) { /// If register have items in cart /// $_SESSION['customer_email']=$c_email; echo "<script>alert('You have been Registered Sucessfully')</script>"; echo "<script>window.open('checkout.php','_self')</script>"; }else{ /// If register without items in cart /// $_SESSION['customer_email']=$c_email; echo "<script>alert('You have been Registered Sucessfully')</script>"; echo "<script>window.open('index.php','_self')</script>"; } } } ?>
  10. I have gotten the solution from stack overflow, the solution is below <form action="sizeresults.php" method="POST"><!-- use post method not must but safe --> <select name="size" onchange="this.form.submit()"> <option selected disabled>Select Your size:</option> <?php $get_sizes = "select * from sizes"; $run_sizes = mysqli_query($dbc,$get_sizes); while ($row_sizes=mysqli_fetch_array($run_sizes)){ $size_id = $row_sizes['size_id']; $size_name = $row_sizes['size']; echo "<option value='$size_name'> $size_name </option>"; } ?> </select> add the following line right above $run_products = mysqli_query(... in sizeresults.php file. $size_name=$_POST['size'];
  11. I want my site to search for any product that belonged to particular size when clicked any size option in the select input menu on mobile version like shop by size menu in www.brastop.com on mobile version. My problem is on how to extract size variable from option tag and put it in the select query in sizeresult.php. below are my codes: 1) for select menu <select class="" name="searchsizemobile" onchange="location = this.value;" id=""> <option selected disabled>Select Your size:</option> <?php $get_sizes = "select * from sizes"; $run_sizes = mysqli_query($dbc,$get_sizes); while ($row_sizes=mysqli_fetch_array($run_sizes)){ $size_id = $row_sizes['size_id']; $size_name = $row_sizes['size']; echo " <option value='sizeresults.php?$size_id'> $size_name </option> "; } ?> </select> my prolem is how to extract the $size_name from option tag and put it in between the two single quotes after the WHERE CLAUSE on the first line in the next code snipet where I wrote sizes.size = ='%$size_name%' for sizeresult.php <?php $run_products = mysqli_query($dbc,"SELECT * FROM products INNER JOIN SIZES USING (size_id) WHERE sizes.size ='%$size_name%'"); while($row_products=mysqli_fetch_array($run_products)){ $pro_id = $row_products['product_id']; $pro_title = $row_products['product_title']; $pro_price = $row_products['product_price']; $pro_sale_price = $row_products['product_sale']; $pro_url = $row_products['product_url']; $pro_img1 = $row_products['product_img1']; $pro_label = $row_products['product_label']; $manufacturer_id = $row_products['manufacturer_id']; $get_manufacturer = "select * from manufacturers where manufacturer_id='$manufacturer_id'"; $run_manufacturer = mysqli_query($dbc,$get_manufacturer); $row_manufacturer = mysqli_fetch_array($run_manufacturer); $manufacturer_title = $row_manufacturer['manufacturer_title']; if($pro_label == "sale"){ $product_price = " <del> NGN $pro_price </del> "; $product_sale_price = "/ NGN $pro_sale_price "; }else{ $product_price = " NGN $pro_price "; $product_sale_price = ""; } if($pro_label == ""){ }else{ $product_label = " <a href='#' class='label $pro_label'> <div class='theLabel'> $pro_label </div> <div class='labelBackground'> </div> </a> "; } echo " <div class='col-md-4 col-sm-6 center-responsive'> <div class='product'> <a href='$pro_url'> <img class='img-responsive' src='admin_area/product_images/$pro_img1'> </a> <div class='text'> <center> <p class='btn btn-primary'> $manufacturer_title </p> </center> <h3> <a href='$pro_url'> $pro_title </a> </h3> <p class='price'> $product_price &nbsp;$product_sale_price </p> <p class='button'> <a class='btn btn-default' href='$pro_url'> View Details </a> <a class='btn btn-primary' href='$pro_url'> <i class='fa fa-shopping-cart'></i> Add to Cart </a> </p> </div> $product_label </div> </div> "; } ?>
  12. Thanks sir, I wrote the code like below and it works <select class="form-control" name="prodoccat" onchange="location = this.value;" id="prodcat"> <option selected disabled>Product Categories</option> <?php $get_p_cats = "select * from product_categories"; $run_p_cats = mysqli_query($dbc,$get_p_cats); while($row_p_cats=mysqli_fetch_array($run_p_cats)){ $p_cat_id = $row_p_cats['p_cat_id']; $p_cat_title = $row_p_cats['p_cat_title']; echo " <option value='shop.php?p_cat=$p_cat_id'> $p_cat_title </option> "; } } ?>
  13. Thanks very much, What I actually wanted to do with #1 questions is to display the product categories that when customer select on categories it will show them all the products under that categories, I know how to do it using list link but because I want the select input to be in header section like the screenshot below. My problem now is I don't know how to use Javascript to manipulate it, here is the full code I want each option to take people to specific page when clicked <select class="form-control" name="" id="prodcat"> <option selected disabled>Product Categories</option> <?php $get_p_cats = "select * from product_categories"; $run_p_cats = mysqli_query($dbc,$get_p_cats); while($row_p_cats=mysqli_fetch_array($run_p_cats)){ $p_cat_id = $row_p_cats['p_cat_id']; $p_cat_title = $row_p_cats['p_cat_title']; echo " <option><a href='shop.php?p_cat=$p_cat_id'> $p_cat_title </a></option> "; } ?> </select>
  14. Dear All, Please, help me to resolve these two issues: 1) How can I change this list link to select link : echo " <li> <a href='shop.php?cat=$cat_id'> $cat_title </a> </li> "; I tried this echo " <option><a href='shop.php?p_cat=$p_cat_id'> $p_cat_title </a></option> "; but the link is not working 2) please, how can I perform FULLTEXT SEARCH WITH JOINS? I consulted php and Mysql for dynamic website 5th edition and use this select * from products where MATCH (product_keywords, product_desc, product_title, product_features) AGAINST ('%$search_query%' IN BOOLEAN MODE it works but anytime I added another table SELECT products.*,sizes.size FROM products LEFT JOIN sizes ON products.size_id = sizes.size_id where MATCH (product_keywords, product_desc, product_title, product_features, sizes.size) AGAINST ('%28FF%' IN BOOLEAN MODE) it was saying #1210 - Incorrect arguments to MATCH
  15. Thanks Necuima, but I can't find Jai's post I searched all through the six pages of this forum.
×
×
  • Create New...