PHP - Differentiate Between Products For E-commerce Site From Database
I am building an e-commerce site and I am aiming to create a front end displaying my products with an option for customers to buy them, and have a content management system as a back end for an admin to edit product information.
Currently I am storing information about my products on a mysql database. I access and display the product info using a while loop. Below is a simplified version of what I am doing without any html to style it. This code will go through the database and each iteration will go the to the next row and display the info about the next product.
$query = mysql_query("SELECT * FROM truffleProducts"); while ($row = mysql_fetch_array($query)) { $id = $row['id']; $name = $row{'Name'}; $price = $row{'Price'}; $desc = $row{'Description'}; echo $id; echo $name; echo $price; echo $desc; }I have began to implement a 'buy' button so that customers are able to click on a button next to the product info and purchase it. However I have come across a problem which is where my program won't be able to tell which product you have selected as the number stored in the $id variable will just be the last product it has fetched from the database. I can't differentiate between all the product's buy buttons, so it will impossible to place an order for a customer with the current system I have. Can any one tell me how to get the id number of the specific product that a user has selected? I only started learning PHP a month or two ago so assume I know nothing Similar TutorialsI am relatively new to php but I have been learning since the end of 2011. At the moment, I am currently developing an E-Commerce website for a customer, using the Larry Ullman book "Effortless E-Commerce' as a guide. I am hitting many brick walls at the moment though. But before I state my long winded problem, I have attached all my work done thus far to this message. HERES THE PROBLEM... I have created a series of includes such as config.inc.php, form_functions.inc.php, login.inc.php and login_form.inc.php. They are included/required with most of my other files. However I have some major issues; 1. This is the code for my logout.php file; Code: [Select] <?php require ('./includes/config.inc.php'); // If the user isn't logged in, redirect them: redirect_invalid_user(); // Destroy the session: $_SESSION = array(); // Destroy the variables. session_destroy(); // Destroy the session itself. setcookie (session_name(), '', time()-300); // Destroy the cookie. // Include the header file: $page_title = 'Logout'; include ('includes/header.html'); // Print a customized message: include ('includes/main.html'); echo '<h3>Logged Out</h3><p>Thank you for visiting. You are now logged out. Please come back soon!</p>'; // Footer file needs the database connection: require (MYSQL); // Include the HTML footer: include ('includes/footer.html'); ?> At the moment, I cannot determine if a user is logged in/when they logout, I cannot determine if there is an active session and also, when I log into the site, I have a database with values yet it seems to let any Tom, Dick and Harry onto the site to log in even though they are not stored in the database. I apologise if this sounds confusing but I really need some major league help. Help would be greatly appreciated I am having an issue trying to get products that I am entering through my admin panel to go into my database. I am thinking that the programmer of the script might have forgot some code possibly, but everything else does get inserted into the database regarding categories, manufactures etc. Here is the insert product php script. My db and functions are set to go to my database with website name/password etc.
<?php if(!isset($_SESSION['customer_email'])){ echo "<script> window.open('../checkout.php','_self'); </script>"; } $customer_email = $_SESSION['customer_email']; $get_customer = "select * from customers where customer_email='$customer_email'"; $run_customer = mysqli_query($con,$get_customer); $row_customer = mysqli_fetch_array($run_customer); $customer_id = $row_customer['customer_id']; $select_general_settings = "select * from general_settings"; $run_general_settings = mysqli_query($con,$select_general_settings); $row_general_settings = mysqli_fetch_array($run_general_settings); $product_vendor_status = $row_general_settings["new_product_status"]; ?> <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> <script>tinymce.init({ selector:'#product_desc,#product_features' });</script> <div class="row"><!-- 2 row Starts --> <div class="col-lg-12"><!-- col-lg-12 Starts --> <div class="panel panel-default"><!-- panel panel-default Starts --> <div class="panel-heading"><!-- panel-heading Starts --> <h3 class="panel-title"> <i class="fa fa-money fa-fw"></i> Insert Product </h3> </div><!-- panel-heading Ends --> <div class="panel-body"><!-- panel-body Starts --> <form id="insert_product_form" method="post" enctype="multipart/form-data"><!-- form-horizontal Starts --> <div class="row"><!-- 2 row Starts --> <div class="col-md-9"><!-- col-md-9 Starts --> <div class="form-group" ><!-- form-group Starts --> <label> Product Title </label> <input type="text" name="product_title" class="form-control" required > </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Seo Description </label> <textarea name="product_seo_desc" class="form-control" maxlength="230" placeholder="Most search engines use a maximum of 230 chars for the description."></textarea> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Url </label> <input type="text" name="product_url" class="form-control" required > <br> <p style="font-size:15px; font-weight:bold;"> Product Url Example : navy-blue-t-shirt </p> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <label> Product Tabs </label> <ul class="nav nav-tabs"><!-- nav nav-tabs Starts --> <li class="active"> <a data-toggle="tab" href="#description"> Product Description </a> </li> <li> <a data-toggle="tab" href="#features"> Product Features </a> </li> <li> <a data-toggle="tab" href="#video"> Sounds And Videos </a> </li> </ul><!-- nav nav-tabs Ends --> <div class="tab-content"><!-- tab-content Starts --> <div id="description" class="tab-pane fade in active"><!-- description tab-pane fade in active Starts --> <br> <textarea name="product_desc" class="form-control" rows="15" id="product_desc"></textarea> </div><!-- description tab-pane fade in active Ends --> <div id="features" class="tab-pane fade in"><!-- features tab-pane fade in Starts --> <br> <textarea name="product_features" class="form-control" rows="15" id="product_features"></textarea> </div><!-- features tab-pane fade in Ends --> <div id="video" class="tab-pane fade in"><!-- video tab-pane fade in Starts --> <br> <textarea name="product_video" class="form-control" rows="15"></textarea> </div><!-- video tab-pane fade in Ends --> </div><!-- tab-content Ends --> </div><!-- form-group Ends --> <div class="form-group" id="product_weight"><!-- form-group Starts --> <label> Product Weight <small> (kg)</small> </label> <input type="text" name="product_weight" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" id="product_price"><!-- form-group Starts --> <label> Product Price </label> <input type="text" name="product_price" class="form-control" required> </div><!-- form-group Ends --> <div class="form-group" id="product_psp_price"><!-- form-group Starts --> <label> Product Sale Price </label> <input type="text" name="psp_price" class="form-control"> </div><!-- form-group Ends --> </div><!-- col-md-9 Ends --> <div class="col-md-3"><!-- col-md-3 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Select A Product Type </label> <select class="form-control" name="product_type"><!-- select manufacturer Starts --> <option value="physical_product"> (Physical Product) Simple Product </option> <option value="digital_product"> (Digital Product) Downloadable Product </option> <option value="variable_product"> (Variable Product) Advanced Product </option> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <label> Select A Manufacturer </label> <select class="form-control" name="manufacturer"><!-- select manufacturer Starts --> <option> Select A Manufacturer </option> <?php $get_manufacturer = "select * from manufacturers"; $run_manufacturer = mysqli_query($con,$get_manufacturer); while($row_manufacturer= mysqli_fetch_array($run_manufacturer)){ $manufacturer_id = $row_manufacturer['manufacturer_id']; $manufacturer_title = $row_manufacturer['manufacturer_title']; echo "<option value='$manufacturer_id'> $manufacturer_title </option>"; } ?> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <label> Product Category </label> <select name="product_cat" class="form-control" > <option> Select a Product Category </option> <?php $get_p_cats = "select * from product_categories"; $run_p_cats = mysqli_query($con,$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='$p_cat_id' >$p_cat_title</option>"; } ?> </select> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Category </label> <select name="cat" class="form-control" > <option> Select a Category </option> <?php $get_cat = "select * from categories"; $run_cat = mysqli_query($con,$get_cat); while ($row_cat=mysqli_fetch_array($run_cat)) { $cat_id = $row_cat['cat_id']; $cat_title = $row_cat['cat_title']; echo "<option value='$cat_id'>$cat_title</option>"; } ?> </select> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Image 1 </label> <input type="file" name="product_img1" class="form-control" required > </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Image 2 </label> <input type="file" name="product_img2" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Image 3 </label> <input type="file" name="product_img3" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Keywords </label> <input type="text" name="product_keywords" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Label </label> <input type="text" name="product_label" class="form-control"> </div><!-- form-group Ends --> </div><!-- col-md-3 Ends --> </div><!-- 2 row Ends --> <div class="form-group" id="product-stock-management"><!-- form-group Starts --> <label> Product Inventory Stock Management </label> <div class="panel panel-default"><!-- panel panel-default Starts --> <div class="panel-heading"><!-- panel-heading Starts --> <strong> Inventory - Stock Options </strong> </div><!-- panel-heading Ends --> <div class="panel-body"><!--panel-body Starts --> <div class="row"><!-- row Starts --> <div class="col-sm-6" id="stock-status"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Stock Status </label> <select class="form-control" name="stock_status" required><!-- select manufacturer Starts --> <option value="instock">In stock</option> <option value="outofstock">Out of stock</option> <option value="onbackorder">On backorder</option> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> <div class="col-sm-6"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Enable stock management at product level? </label> <div class="radio"> <label> <input type="radio" name="enable_stock" value="yes" required> Yes </label> <label> <input type="radio" name="enable_stock" value="no" checked required> No </label> </div> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> </div><!-- row Ends --> <div class="row" id="stock-management-row"><!-- row Starts --> <div class="col-sm-6"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Stock Quantity </label> <input type="number" name="stock_quantity" value="0" class="form-control" required> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> <div class="col-sm-6"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Allow backorders? </label> <select class="form-control" name="allow_backorders" required><!-- select manufacturer Starts --> <option value="no">Do not allow</option> <option value="notify">Allow, but notify customer</option> <option value="yes">Allow</option> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> </div><!-- row Ends --> </div><!--panel-body Ends --> </div><!-- panel panel-default Ends --> </div><!-- form-group Ends --> </form><!-- form-horizontal Ends --> <div class="form-group" id="variable_product_options"><!-- form-group Starts --> <label> Variable Product Options </label> <div class="panel panel-default"><!-- panel panel-default Starts --> <div class="panel-heading"><!-- panel-heading Starts --> <ul class="nav nav-tabs"><!-- nav nav-tabs Starts --> <li class="active"> <a data-toggle="tab" href="#product_attributes"> Product Attributes </a> </li> <li> <a data-toggle="tab" href="#product_variations"> Product Variations </a> </li> </ul><!-- nav nav-tabs Ends --> </div><!-- panel-heading Ends --> <div class="panel-body"><!--panel-body Starts --> <div class="tab-content"><!-- tab-content Starts --> <div id="product_attributes" class="tab-pane fade in active"><!-- product_attributes tab-pane fade in active Starts --> <form id="insert_attribute_form" method="post"><!-- form Starts --> <div class="row"><!-- row Starts --> <div class="col-sm-4"><!-- col-sm-4 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Name: </label> <input type="text" name="attribute_name" class="form-control" required> </div><!-- form-group Ends --> </div><!-- col-sm-4 Ends --> <div class="col-sm-8"><!-- col-sm-8 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Value(s): </label> <textarea name="attribute_values" class="form-control" placeholder="Enter some attributes by '|' separating values." required></textarea> </div><!-- form-group Ends --> </div><!-- col-sm-8 Ends --> </div><!-- row Ends --> <div class="form-group"><!-- form-group Starts --> <input type="submit" value="Insert Product Attribute" class="btn btn btn-primary"> </div><!-- form-group Ends --> </form><!-- form Ends --> <table class="table table-hover table-bordered table-striped"><!-- table table-hover table-bordered table-striped Starts --> <thead><!-- thead Starts --> <tr> <th>Attribute Name:</th> <th>Attribute Value(s):</th> <th>Actions:</th> </tr> </thead><!-- thead Ends --> <tbody><!-- tbody Starts --> <?php $random_id = 152; $select_product_attributes = "select * from product_attributes where product_id='$random_id'"; $run_product_attributes = mysqli_query($con,$select_product_attributes); while($row_product_attributes = mysqli_fetch_array($run_product_attributes)){ $attribute_id = $row_product_attributes["attribute_id"]; $attribute_name = $row_product_attributes["attribute_name"]; $attribute_values = $row_product_attributes["attribute_values"]; ?> <tr id="tr-attribute-<?php echo $attribute_id; ?>"> <td> <div class="edit" data-attribute="<?php echo $attribute_id; ?>"><?php echo $attribute_name; ?></div> <input type="text" id="attribute-name" class="input-edit form-control" data-attribute="<?php echo $attribute_id; ?>" value="<?php echo $attribute_name; ?>"> </td> <td> <div class="edit" data-attribute="<?php echo $attribute_id; ?>"><?php echo $attribute_values; ?></div> <input type="text" id="attribute-values" class="input-edit form-control" data-attribute="<?php echo $attribute_id; ?>" value="<?php echo $attribute_values; ?>"> </td> <td> <div class="btn-group"> <a href="#" class="edit-product-attribute btn btn-primary btn-sm" data-attribute="<?php echo $attribute_id; ?>"> <i class="fa fa-pencil"></i> Edit </a> <a href="#" class="save-product-attribute btn btn-success btn-sm" data-attribute="<?php echo $attribute_id; ?>"> <i class="fa fa-floppy-o"></i> Save </a> <a href="#" class="delete-product-attribute btn btn-danger btn-sm" data-attribute="<?php echo $attribute_id; ?>"> <i class="fa fa-trash-o"></i> Delete </a> </div> </td> </tr> <?php } ?> </tbody><!-- tbody Ends --> </table><!-- table table-hover table-bordered table-striped Ends --> </div><!-- product_attributes tab-pane fade in active Ends --> <div id="product_variations" class="tab-pane fade in"><!-- product_variations tab-pane fade in Starts --> <form id="product-variations-form" method="post" enctype="multipart/form-data"><!-- form Starts --> <div class="form-group row"><!-- form-group Starts --> <label class="col-sm-3 control-label"> Default Form Values: </label> <div class="col-sm-9"><!-- col-sm-10 Starts --> <div class="row" id="default_form_values"><!-- row default_form_values Starts --> </div><!-- row default_form_values Ends --> <span class="help-block"> These are the product attributes that will be pre-selected on the frontend. </span> </div><!-- col-sm-9 Ends --> </div><!-- form-group Ends --> <hr class="variation-hr"> <div class="form-group row"><!-- form-group Starts --> <label class="col-sm-1 control-label"> Actions: </label> <div class="col-sm-10"><!-- col-sm-10 Starts --> <select class="form-control" id="action_select"><!-- select manufacturer Starts --> <option value="add_variation"> Add A New Variation </option> <option value="create_variations_from_attributes"> Create New Variations From All Attributes </option> <option value="delete_all_variations"> Delete All Variations </option> </select><!-- select manufacturer Ends --> </div><!-- col-sm-10 Ends --> <div class="col-sm-1"><!-- col-sm-1 Starts --> <button type="button" id="go_button" class="btn btn-success form-control"> Go </button> </div><!-- col-sm-1 Ends --> </div><!-- form-group Ends --> <div class="product-variations-div"><!-- product-variations-div Starts --> </div><!-- product-variations-div Ends --> <hr class="variation-hr"> <div class="form-group"><!-- form-group Starts --> <input type="submit" value="Save Product Variations" class="btn btn btn-success"> </div><!-- form-group Ends --> </form><!-- form Ends --> <div class="ajax-response-div"></div> </div><!-- product_variations tab-pane fade in Ends --> </div><!-- tab-content Ends --> </div><!--panel-body Ends --> </div><!-- panel panel-default Ends --> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <input type="submit" name="submit" value="Insert Product" form="insert_product_form" class="btn btn-primary form-control"> </div><!-- form-group Ends --> </div><!-- panel-body Ends --> </div><!-- panel panel-default Ends --> </div><!-- col-lg-12 Ends --> </div><!-- 2 row Ends --> <script> $(document).ready(function(){ //Product Stock Management Code Starts $("#stock-management-row").hide(); $("input[name='enable_stock']").click(function(){ var radio_value = $(this).val(); if(radio_value == "yes"){ $("#stock-status").hide(); $("#stock-management-row").show(); }else if(radio_value == "no"){ $("#stock-status").show(); $("#stock-management-row").hide(); } }); //Product Stock Management Code Ends //Change Product Type Function Code Starts function change_product_type(){ var product_type = $("select[name='product_type']").val(); if(product_type == "physical_product"){ $("#product_weight").show(); $("#product_price").show(); $("#product_psp_price").show(); $('#product_weight input,#product_price input,#product_psp_price input').prop("disabled", false); $("#product-stock-management").show(); $('#product-stock-management input,#product-stock-management select').prop("disabled", false); $("#variable_product_options").hide(); }else if(product_type == "digital_product"){ $("#product_weight").hide(); $("#product_price").show(); $("#product_psp_price").show(); $('#product_weight input,#product_price input,#product_psp_price input').prop("disabled", false); $("#product-stock-management").show(); $('#product-stock-management input,#product-stock-management select').prop("disabled", false); $("#variable_product_options").hide(); }else if(product_type == "variable_product"){ $("#product_weight").hide(); $("#product_price").hide(); $("#product_psp_price").hide(); $('#product_weight input,#product_price input,#product_psp_price input').prop("disabled", true); $("#product-stock-management").hide(); $('#product-stock-management input,#product-stock-management select').prop("disabled", true); $("#variable_product_options").show(); } } //Change Product Type Function Code Ends change_product_type(); $("select[name='product_type']").change(function(){ change_product_type(); }); //Load Product Attributes Function Code Starts function load_product_attributes(){ $.ajax({ method: "POST", url: "variable_product/load_product_attributes.php", data: { random_id: <?php echo $random_id; ?> }, success:function(data){ $("table tbody").html(data); $("table").removeClass("wait-loader"); } }); } //Load Product Attributes Function Code Ends //Insert New Product Attribute Code Starts $("#insert_attribute_form").submit(function(event){ event.preventDefault(); $("table").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/insert_product_attribute.php", data: $('#insert_attribute_form').serialize() + "&random_id=<?php echo $random_id; ?>", success: function(){ $("#insert_attribute_form").find("input[type=text],textarea").val(""); load_product_attributes(); } }); }); //Insert New Product Attribute Code Ends //Edit Product Attribute Code Starts $(".input-edit").hide(); $(".save-product-attribute").hide(); $(".edit-product-attribute").on('click', function(event){ event.preventDefault(); var attribute_id = $(this).data("attribute"); $(".edit").show(); $(".input-edit").hide(); $(".edit[data-attribute='" + attribute_id +"']").hide(); $(".input-edit[data-attribute='" + attribute_id +"']").show().focus(); $(".edit-product-attribute[data-attribute='" + attribute_id +"']").hide(); $(".save-product-attribute[data-attribute='" + attribute_id +"']").show(); }); //Edit Product Attribute Code Ends //Update Save Product Attribute Code Starts $(".save-product-attribute").on('click', function(event){ event.preventDefault(); var attribute_id = $(this).data("attribute"); $(".edit[data-attribute='" + attribute_id +"']").show(); $(".input-edit[data-attribute='" + attribute_id +"']").hide(); $(".edit-product-attribute[data-attribute='" + attribute_id +"']").show(); $(".save-product-attribute[data-attribute='" + attribute_id +"']").hide(); var attribute_name = $("#attribute-name[data-attribute='" + attribute_id +"']").val(); var attribute_values = $("#attribute-values[data-attribute='" + attribute_id +"']").val(); $("#attribute-name[data-attribute='" + attribute_id +"']").prev(".edit").text(attribute_name); $("#attribute-values[data-attribute='" + attribute_id +"']").prev(".edit").text(attribute_values); var random_id = <?php echo $random_id; ?>; $.ajax({ method: "POST", url: "variable_product/update_product_attribute.php", data: { random_id: random_id, attribute_id: attribute_id, attribute_name: attribute_name, attribute_values: attribute_values } }); }); //Update Save Product Attribute Code Ends //Delete Product Attribute Code Starts $(".delete-product-attribute").on('click', function(event){ event.preventDefault(); var attribute_id = $(this).data("attribute"); $("#tr-attribute-" + attribute_id).remove(); var random_id = <?php echo $random_id; ?>; $.ajax({ method: "POST", url: "variable_product/delete_product_attribute.php", data: { random_id: random_id, attribute_id: attribute_id } }); }); //Delete Product Attribute Code Ends //Load Product Variations Default Form Values Function Code Starts function load_variations_default_form_values(){ $.ajax({ method: "POST", url: "variable_product/load_default_form_values.php", data: { random_id: <?php echo $random_id; ?> }, success:function(data){ $("#default_form_values").html(data); } }); } //Load Product Variations Default Form Values Function Code Ends //Load Product Variations Function Code Starts function load_product_variations(){ $.ajax({ method: "POST", url: "variable_product/load_product_variations.php", data: { random_id: <?php echo $random_id; ?> }, success:function(data){ $(".product-variations-div").html(data); $(".product-variations-div").removeClass("wait-loader"); } }); } //Load Product Variations Function Code Ends //Click Product Variations Tab Code Starts $("a[href='#product_variations']").click(function(){ $(".product-variations-div").addClass("wait-loader"); load_variations_default_form_values(); load_product_variations(); }); //Click Product Variations Tab Code Ends //Save Update Product Variations Function Code Starts function save_update_product_variations(){ var form = document.getElementById("product-variations-form"); var form_data = new FormData(form); form_data.append("random_id", <?php echo $random_id; ?>); $.ajax({ method: "POST", url: "variable_product/update_all_variations.php", data:form_data, contentType: false, cache: false, processData:false, success: function(data){ $(".ajax-response-div").html(data); $(".product-variations-div").removeClass("wait-loader"); } }); } //Save Update Product Variations Function Code Ends //Product Variations Actions Go Button Code Starts $("#go_button").click(function(){ var action_select = $("#action_select").val(); if(action_select == "add_variation"){ $(".product-variations-div").addClass("wait-loader"); save_update_product_variations(); $(".product-variations-div").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/insert_product_variation.php", data: { random_id: <?php echo $random_id; ?> }, success: function(){ load_product_variations(); } }); }else if(action_select == "create_variations_from_attributes"){ var confirm_action = confirm("Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max 50 per run)."); if(confirm_action == true){ $(".product-variations-div").addClass("wait-loader"); save_update_product_variations(); $(".product-variations-div").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/create_variations_from_attributes.php", data: { random_id: <?php echo $random_id; ?> }, success: function(data){ $(".ajax-response-div").html(data); load_product_variations(); load_variations_default_form_values(); } }); } }else if(action_select == "delete_all_variations"){ var confirm_action = confirm("Are you sure you want to delete all variations? This cannot be undone."); if(confirm_action == true){ $(".product-variations-div").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/delete_all_variations.php", data: { random_id: <?php echo $random_id; ?> }, success: function(){ load_product_variations(); load_variations_default_form_values(); } }); } } }); //Product Variations Actions Go Button Code Ends //Save Update Submit From Of Product Variations Code Starts $("#product-variations-form").submit(function(event){ event.preventDefault(); $(".product-variations-div").addClass("wait-loader"); save_update_product_variations(); load_variations_default_form_values(); }); //Save Update Submit From Of Product Variations Code Ends }); </script> <?php if(isset($_POST['submit'])){ $product_title = mysqli_real_escape_string($con, $_POST['product_title']); $product_seo_desc = mysqli_real_escape_string($con, $_POST['product_seo_desc']); $product_url = mysqli_real_escape_string($con, $_POST['product_url']); $product_cat = mysqli_real_escape_string($con, $_POST['product_cat']); $cat = mysqli_real_escape_string($con, $_POST['cat']); $manufacturer_id = mysqli_real_escape_string($con, $_POST['manufacturer']); $product_price = mysqli_real_escape_string($con, $_POST['product_price']); $product_desc = mysqli_real_escape_string($con, $_POST['product_desc']); $product_keywords = mysqli_real_escape_string($con, $_POST['product_keywords']); $psp_price = mysqli_real_escape_string($con, $_POST['psp_price']); $product_label = mysqli_real_escape_string($con, $_POST['product_label']); $product_type = mysqli_real_escape_string($con, $_POST['product_type']); $product_features = mysqli_real_escape_string($con, $_POST['product_features']); $product_video = mysqli_real_escape_string($con, $_POST['product_video']); $product_weight = mysqli_real_escape_string($con, $_POST['product_weight']); $stock_status = mysqli_real_escape_string($con, $_POST['stock_status']); $enable_stock = mysqli_real_escape_string($con, $_POST['enable_stock']); $stock_quantity = mysqli_real_escape_string($con, $_POST['stock_quantity']); $allow_backorders = mysqli_real_escape_string($con, $_POST['allow_backorders']); $status = "product"; $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']; $allowed = array('jpeg','jpg','gif','png'); $product_img1_extension = pathinfo($product_img1, PATHINFO_EXTENSION); $product_img2_extension = pathinfo($product_img2, PATHINFO_EXTENSION); $product_img3_extension = pathinfo($product_img3, PATHINFO_EXTENSION); if(!in_array($product_img1_extension,$allowed)){ echo "<script> alert('Your Product Image 1 File Extension Is Not Supported.'); </script>"; $product_img1 = ""; }else{ move_uploaded_file($temp_name1,"../admin_area/product_images/$product_img1"); } if(!empty($product_img2)){ if(!in_array($product_img2_extension,$allowed)){ echo "<script> alert('Your Product Image 2 File Extension Is Not Supported.'); </script>"; $product_img2 = ""; }else{ move_uploaded_file($temp_name2,"../admin_area/product_images/$product_img2"); } } if(!empty($product_img3)){ if(!in_array($product_img3_extension,$allowed)){ echo "<script> alert('Your Product Image 3 File Extension Is Not Supported.'); </script>"; $product_img3 = ""; }else{ move_uploaded_file($temp_name3,"../admin_area/product_images/$product_img3"); } } $insert_product = "insert into products (vendor_id,p_cat_id,cat_id,manufacturer_id,date,product_title,product_seo_desc,product_url,product_img1,product_img2,product_img3,product_price,product_psp_price,product_desc,product_features,product_video,product_keywords,product_label,product_type,product_weight,product_vendor_status,status) values ('$customer_id','$product_cat','$cat','$manufacturer_id',NOW(),'$product_title','$product_seo_desc','$product_url','$product_img1','$product_img2','$product_img3','$product_price','$psp_price','$product_desc','$product_features','$product_video','$product_keywords','$product_label','$product_type','$product_weight','$product_vendor_status','$status')"; $run_product = mysqli_query($con,$insert_product); $product_id = mysqli_insert_id($con); if($run_product){ if($product_type != "variable_product"){ if($enable_stock == "yes" and $stock_quantity > 0){ $stock_status = "instock"; }elseif($enable_stock == "yes" and $allow_backorders == "no" and $stock_quantity < 1){ $stock_status = "outofstock"; }elseif($enable_stock == "yes" and ($allow_backorders == "yes" or $allow_backorders == "notify") and $stock_quantity < 1){ $stock_status = "onbackorder"; } $insert_product_stock = "insert into products_stock (product_id,enable_stock,stock_status,stock_quantity,allow_backorders) values ('$product_id','$enable_stock','$stock_status','$stock_quantity','$allow_backorders')"; $run_insert_product_stock = mysqli_query($con,$insert_product_stock); } $update_product_stock = "update products_stock set product_id='$product_id' where product_id='$random_id'"; $run_update_product_stock = mysqli_query($con,$update_product_stock); $update_product_attributes = "update product_attributes set product_id='$product_id' where product_id='$random_id'"; $run_product_attributes = mysqli_query($con, $update_product_attributes); $update_product_variations = "update product_variations set product_id='$product_id' where product_id='$random_id'"; $run_product_variations = mysqli_query($con, $update_product_variations); echo " <script> alert(' Your Product Has Been Inserted Successfully. '); window.open('index.php?products','_self'); </script> "; } } ?>
Hello everyone, I've been working on this for about 2 days now, and I just can't seem to figure it out so I need some help from someone here. I have a database with three items (will be more, but for now there's three). The database keeps a record of the days that each item is reserved. I want to be able to select and generate a list of items that are available on a specific day. Here is what I have so far: Code: [Select] <?php $result = mysql_query("SELECT `prodid` FROM reservations WHERE `resdate` = '$resdate'") or die (mysql_error()); while ($row = mysql_fetch_row($result)) { $resprodid = $row[0]; $result2 = mysql_query("SELECT `prodid`,`prodname` FROM products"); $row2 = mysql_fetch_row($result2); $prodid = $row2[0]; $prodname= $row2[1]; if ($prodid != $resprodid) { echo $prodid; } } ?> The result that I'm getting are not correct. I either get only one unit listed, or none. Any help would be appreciated. Thanks! Login.php Code: [Select] <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("Regis") or die(mysql_error()); if (isset($_POST["sub"])) { $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); $_POST['pass'] = addslashes($_POST['pass']); } $usercheck = $_POST["username"]; $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('Sorry, the username" ." ".$usercheck." ". "is already in use.')</SCRIPT>"); echo ("<SCRIPT LANGUAGE='JavaScript'>setTimeOut(window.location = 'registration.php',1)</script>"); } else if($_POST['username'] && $_POST['pass'] && $_POST['pass2'] ) { $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('Registration had been succesfully added :)')</SCRIPT>"); } } ?> <html> <head> <script type="text/javascript"> function a() { var x = document.login.username.value; var y = document.login.pass.value; if(x==""&& y=="") { alert("Please insert all message!"); return false; } if(x=="") { alert("Please insert an username!"); return false; } if(y=="") { alert("Please insert an password!"); return false; } } </script> </head> <body> <table border="0"> <form name="login" method="post" action="form2.php" onsubmit="return a()"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td> <td><input type="text" name="username" maxlength="40"></td></tr> <tr><td>Password:</td> <td><input type="password" name="pass" maxlength="50"></td></tr> <tr><td><input type="submit" name="submit" value="Register"></a></td> <td><input type="submit" name="submit" value="Login"></td></tr> </form> </body></html> form2.php Code: [Select] <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $message=$_POST['message']; $n=$_POST['username']; if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)>1) { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$n','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <form name="smile" method="post" action="form2.php" onSubmit="return a()" > Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt=":)" onClick="addsmiley(':)')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt=":)" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type="hidden" name="username" value="<?php echo $n;?>"> <input type='submit' name='submit' value='Send' class='biasa' ></form> <br> <br> </body> </html> My problem is in login.php in form section, can one form can be used user or admin because just now im doing is for user if user login it goes to form2.php but im want also in the same form if admin the form post to form3.php any way to do that thank you Hi all, I'm a bit of a newbie to this type of website and would be extremely grateful for any help on this as it's causing considerable headaches! I've been working on an e-commerce (Online Shop) website based on the site found he http://www.phpwebcommerce.com/ I have been building it into a template from the original shop that was essentially a static website with links to paypal for the cart etc. Now I am trying to add an extra function to the site but cant get my head around the logic to making this work and I know it can be done! The shop is to sell mainly shoes with some accessories. So I understand that shoes obviously come in a variety of sizes, and each size needs to have its own product ID in the MySQL DB so I can show whether it is in stock etc. What I cant figure out is how to firstly make an easy way of adding the shoes different sizes (for eg 10 shoes of the same type in sizes 40-49) to the DB in one hit instead of filling in the same form 10 times but with different sizes. I have the simple form already made and working successfully. My thoughts are to add check box in the form to say I'm adding multiple shoes that tells the process to look for values in text areas for starting shoe size and last shoe size. The process then takes the start size from the end size giving the number of times to loop the process. It then loops the process for each size using the same information... Logically this works but I'm not sure how to code this on what I have. I have attached the files used directly in this. Secondly how do I group the shoes on the front end. Now each product on the front end currently will display a simple message instead of add to cart when the stock = 0, or the product has been made as available on request. I would like to group the shoes of the same type to have a drop down menu showing the available sizes. When a size is selected it needs to query the DB for available stock and either show the 'Add to cart' or 'Call to order' options. Anything else you might need to help with this let me know. I'm keen to get this bit done so I can get the site live! Thanks in advance Hey everyone. I am making a site for my brother's band and having some trouble with the checkout to paypal. Unfortunately in layout I missed a pretty important variable, the size on shirts. I am trying to add it in as a drop down option just before submitting to paypal but I can't get it to show up on paypal and thus will have no idea what size they are ordering. The site is pretty basic and primitive but I really need this info on the checkout. Here is a link to the temporary site where i'm trying to get this to work: http://www.theblack44s.com/t/index3.php and this is what is up and running now: http://www.theblack44s.com/Merchant%20pages/apparel/index3.php this is the code i'm working on in cart.php: Code: [Select] <?php require "dbconcart.php"; session_start(); //session_destroy(); $page = 'index.php'; $value2 = $_POST['size']; //add to cart function if (isset($_GET['add'])) { $quantity = mysql_query('SELECT id, quantity, imageurl FROM apparel WHERE id='.mysql_real_escape_string((int)$_GET['add'])); while ($quantity_row = mysql_fetch_assoc($quantity)) { if ($quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) { $_SESSION['cart_'.(int)$_GET['add']]+='1'; } } header('Location: '.$page); } //remove from cart if (isset($_GET['remove'])) { $_SESSION['cart_'.(int)$_GET['remove']]--; header('Location: '.$page); } //delete from cart if (isset($_GET['delete'])) { $_SESSION['cart_'.(int)$_GET['delete']]='0'; header('Location: '.$page); } // products function products() { $get = mysql_query('SELECT id, name, item_number, description, price, shipping FROM apparel WHERE quantity > 0 ORDER BY id DESC'); if (mysql_num_rows($get)==0) { echo "There are no products to display!"; } else { while ($get_row = mysql_fetch_assoc($get)) { echo $get_row['name'].'<br />'; echo $get_row['item_number'].'<br />'; echo $get_row['description'].'<br />'; echo 'Price: '.number_format($get_row['price'], 2).'<br />'; echo 'Shipping: '.number_format($get_row['shipping'], 2); echo '<a href="cart.php?add='.$get_row['id'].'">Add to cart</a></p>'; } } } //paypal function function paypal_items() { $num = 0; foreach($_SESSION as $name => $value) { if ($value!=0) { if (substr($name, 0, 5)=='cart_') { $id = substr($name, 5, strlen($name)-5); $get = mysql_query('SELECT id, name, item_number, price, shipping FROM apparel WHERE id='.mysql_real_escape_string((int)$id)); while ($get_row = mysql_fetch_assoc($get)) { $num++; echo '<input type="hidden" name="item_number_'.$num.'" value="'.$get_row['item_number'].'">'; echo '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'">'; echo '<input type="hidden" name="size_" value="$_POST'.$value2.']">'; echo '<input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'">'; echo '<input type="hidden" name="shipping_'.$num.'" value="'.$get_row['shipping'].'">'; echo '<input type="hidden" name="shipping2_'.$num.'" value="'.$get_row['shipping'].'">'; echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">'; } } } } } //cart function function cart() { foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5)=='cart_') { $id = substr($name, 5, (strlen($name)-5)); $get = mysql_query('SELECT id, name, price, imageurl FROM apparel WHERE id='.mysql_real_escape_string((int)$id)); while ($get_row = mysql_fetch_assoc($get)) { $sub = $get_row['price']*$value; echo $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2).'<br />'; ?> <html> <body> <form action="size.php" method="post" name="size"> <label>Size <select name="size"> <option selected="selected">Select</option> <option value="youth">Youth (for the brats)</option> <option value="small">Small (petite)</option> <option value="medium">Medium (average)</option> <option value="large">Large (healthy)</option> <option value="xlarge">X Large (large)</option> <option value="xxlarge">XX Large (full figured</option> <option value="xxxlarge">XXX Large (huge)</option> <option value="xxxxlarge">XXXXLarge (DAMN!!)</option> </select> <input type="hidden" name="size" value="selected" /> <input type="hidden" name="size" value="submit()" /> </label> </form> </body> </html> <?php echo '<a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[delete]</a><br />'; } } $total += $sub; } } //cart totals and paypal function if ($total==0) { echo "Your cart is empty."; } else { echo '<p><b>Total: $ '.number_format($total, 2).'</b></p>'; ?> <p> <form action="https://www.paypal.com/cgi-bin/webscr" target="_blank" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="webmaster@theblack44s.com"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="amount" value="<?php echo $total; ?>"> <input type="hidden" name="size" value="<?php echo $value2; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" target="_blank" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> </p> <?php } } ?> Hi, I got problems on my website http://www.tranceprofile.com/ When I want to go to my Storeadmin page (http://www.tranceprofile.com/storeadmin/) I get this: Warning: session_start() [function.session-start]: open(/public/tmp/sess_64fb1b28e78195d89731106458023ab4, O_RDWR) failed: No such file or directory (2) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 5 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /public/sites/www.tranceprofile.com/storeadmin/index.php:5) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 5 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /public/sites/www.tranceprofile.com/storeadmin/index.php:5) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 5 Warning: Cannot modify header information - headers already sent by (output started at /public/sites/www.tranceprofile.com/storeadmin/index.php:5) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 7 Warning: Unknown: open(/public/tmp/sess_64fb1b28e78195d89731106458023ab4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/public/tmp) in Unknown on line 0 Can someone help me? Here is my code Code: [Select] <?php session_start(); if (!isset($_SESSION["manager"])) { header("location: admin_login.php"); exit(); } // Be sure to check that this manager SESSION value is in fact in the database $managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters // Run mySQL query to be sure that this person is an admin and that their password session var equals the database information // Connect to the MySQL database include "../storescripts/connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person // ------- MAKE SURE PERSON EXISTS IN DATABASE --------- $existCount = mysql_num_rows($sql); // count the row nums if ($existCount == 0) { // evaluate the count echo "Your login session data is not on record in the database."; exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Admin Area</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <div id="pageContent"><br /> <div align="left" style="margin-left:24px;"> <h2>Hello store manager, what would you like to do today?</h2> <p><a href="inventory_list.php">Manage Inventory</a><br /> <a href="#">Manage Blah Blah </a></p> </div> <br /> <br /> <br /> </div> <?php include_once("../template_footer.php");?> </div> </body> </html> If the script is not uploaded onto the server you cant use $dbc = mysql_connect('localhost', 'username', 'pass'); so how could I connect in cli? this did not work $dbc = mysql_connect('http://123.456.789.10', 'username', 'pass'); So what can I do? Thanks Hey guys I had created a while ago a script for my friend where you can buy points and then redeem stuff with those points, i'm looking for ways to keep my site secu currently what i have done- - protected all mysql queries with mysql_real_escape_string, strip_tags, and addslashes - have a valid SSL certificate on my website - checked if emails are valid for account creation what else can I do? Thank you. Hey guys, I got a tough one. I've been researching for days, weeks even, to try and solve this. And I'm sure I'm going to kick myself if/when I get a solution. I've set up an ecommerce website from scratch (no prestashop, oscommerce, none of that), and I need to figure out how to decrease price on quantity. Ex; Umbrellas are $12.00 a piece. If you order 2 dozen (24) Umbrellas, they are only $10.00 a piece. I can't seem to figure out a way to make it work.. I have set up in my database the following columns. p - base price ($12) p1 - price after first increment ($10) q1 - quantity of first break (24) p2 q2 p3 q3 Hit me with your best shot. I have an array that needs to display all titles and allow for a user to view titles based on the category, title, etc . I tried using the print_r() function but it didn't display the titles in a clean list. The only tutorials I've found utilize sql and i need to complete this without using SQL. Code: [Select] $books = array(); array_push($books,array("category" => "Nonfiction","title" => "The Innocent Man","author" => "Grisham","publisher" => "McGraw-Hill","price" => "34.99","isbn" => "5985420166")); array_push($books,array("category" => "Business","title" => "How to Make Money","author" => "Richy","publisher" => "Prentice-Hall","price" => "49.99","isbn" => "8754739342")); array_push($books,array("category" => "Romance","title" => "Twice Kissed","author" => "Jackson","publisher" => "McGraw-Hill","price" => "14.99","isbn" => "5671230987")); Ok so I have this site where I'm posting a message to my Database. But when I go to pull the message from the MYSQL DB it's one long sentence. Any suggestions? this is on amensharma.co.uk/testing Code: [Select] <?php $db_link = mysql_connect("amensharma.co.uk","amenshar_admin","amen001"); if (!$db_link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('amenshar_calender', $db_link); if (!$db_selected) { die ('Can\'t use database : ' . mysql_error()); } ?> this is the error it returns Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'amenshar_admin'@'neptune.servers.rbl-mer.misp.co.uk' (using password: YES) in /home/amenshar/public_html/testing/functions/database.php on line 4 Could not connect: Access denied for user 'amenshar_admin'@'neptune.servers.rbl-mer.misp.co.uk' (using password: YES) bit stumped here any help would be great all the details are correct, just confused why im having these errors Hello and good day to all of you I have passed my midterms project(Online Shopping) with a score of 94 in PHP ( Click here to see file ) ( Sorry if the design is too ugly, I'm just new in programming XD ) Now our finals project will be a PHP site again but now with a database in it.. So instead of making a new project/design for a site, why not just add a database to my existing midterms? I would like to ask for some help here in helping me on connecting to the database, adding a database/tables and anything that would be of help like suggesting Databases would be like, - Users ( Admin and Members ) - Upper Clothing ( Shirts, Jackets, Long Sleeves, Raglan and etc ) - Lower Clothing ( Pants, Shorts, Boxers and etc ) - Stock on a current item - Single member's Transaction History - All user's Transaction History Is there a way that I could add those database named above to my project? Thank you in advance! Having a major problem connecting to a live site. I have set up the user and database on Cpanel like normal. Then proceeded to insert those details into my mysql connection script Code: [Select] <?php $db_link = mysql_connect("***","****","***"); if (!$db_link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('amenshar_calender', $db_link); if (!$db_selected) { die ('Can\'t use database : ' . mysql_error()); } ?> I am connecting to domain erban.co.uk, yet looking at the cpanel the master domain is amensharma.co.uk. Is this what the problem could be. This is the error messege it is throwing up Warning: mysql_connect(): Access denied for user '_admin'@'localhost' (using password: YES) in d:\Domains\erban.co.uk\wwwroot\functions\database.php on line 4 Could not connect: Access denied for user '_admin'@'localhost' (using password: YES) This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=276607.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=321270.0 hiii all, i want to show the database field (alise name) as the url after index.php when page or site loads first time. how i can achieve it? please help.... thanks in advance can someone help to add new products and increase the quantity of the product when pressing the + button, but it works for [-] Code: [Select] <?php include "./php/connection.php"; function products () { $query = "SELECT * FROM product"; if (@mysql_num_rows($query)==0) { echo "There are no products to display!"; } else { while ($query_row = mysql_fetch_array($query)) { "<div class='product'>" . "<img class='img' src=". $row["Image"]." alt='phone' width='100' height='150' />" . "<p class='name'>".$row["Name"]."</p>". "<p class='price'>£". $row["Price"] ."</p>". "<p><a href='./cart.php?ProductID=". $row["ProductID"]."' class='myButton'>More Info</a></p>". "</div>"; } } } if (isset($_GET['ProductID'])) { $quantity = mysql_query('SELECT * FROM product WHERE ProductID = ' .$_GET["ProductID"]); while ($quantity_row = mysql_fetch_array($quantity)) { if ($quantity_row["Quantity"]!=@$_SESSION["cart_".$_GET["ProductID"]]) { @$_SESSION["cart_".$_GET["ProductID"]]+="1"; } } } if (isset($_GET["remove"])) { $_SESSION["cart_".$_GET["remove"]]--; header("Location: ./cart.php"); # Go back to the login pages } if (isset($_GET["delete"])) { $_SESSION["cart_".$_GET["delete"]]="0"; header("Location: ./cart.php"); # Go back to the login pages } function paypal_items() { $num = 0; foreach($_SESSION as $name => $value) { if ($value!=0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT ProductID, Manufacturer, model, Price FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $num++; echo '<input type="hidden" name="item_number_'.$num.'" value="'.$productid.'">'; echo '<input type="hidden" name="item_name_'.$num.'" value="'.$query_row['Name'].'">'; echo '<input type="hidden" name="amount_'.$num.'" value="'.$query_row['Price'].'">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">'; } } } } } function cart () { "<table id='producttable' border='1'>". "<tr>". "<td class='td top'>Delete</td>". "<td class='td top'>Product Name</td>". "<td class='td top'>Quantity</td>". "<td class='td top'>Price</td>". "<td class='td top'>Sub Total</td>". "</tr>"; foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT * FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $sub = $query_row["Price"] * $value; "<tr>". "<td class='td'><a href='./cart.php?delete=".$productid."'> [Delete] </a></td>". "<td class='td'>".$query_row["Manufacturer"]."</td>". "<td class='td'>".$value."</td>". "<td class='td'><a href='./cart.php?ProductID=".$productid."'> [+] </a>£".$query_row["Price"]."<a href='./cart.php?remove=".$productid."'> [-] </a></td>". "<td class='td'>£".$sub."</td>". "</tr>"; } } @$total += $sub; } } if (@$total==0) { echo "<p>Your basket is empty</p>"; } else { echo @" Total: £" .$total; ?> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="kamran193@hotmail.co.uk"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<?php echo $total; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> <?php } echo "</table>"; } echo cart(); echo products(); ?> Hi, I'm trying to display the products for a certain tag in the email for new order in wooCommerce. For example, I want that when a client buys a product with a certain tag, all the products that have that tag to be added automatically to the order email too. For now I achieved to display the tag in the email but not the products that have that tag. I don't know how get the products that belongs to that tag and add them to the cart to so I can display them in the email. Any help as small as it may be, it is very welcomed, please. I'm a bit stuck. I'm not very skilled in php... Thank you very much function email_products_per_tag( $order, $item ) { $items = $order->get_items(); foreach ( $items as $item ) { $terms = wp_get_post_terms( $item['product_id'], 'product_tag' ); foreach($terms as $term){ $term_names[] = $term->name; // Product tag Name // $item2 = 'product_tag'=> ; // not very sure about this line... } } } add_action( 'woocommerce_email_after_order_table', 'email_products_per_tag', 10, 4 ); Edited September 15, 2020 by cimita |