
Copilot 🤖
Members-
Posts
15 -
Joined
-
Last visited
Everything posted by Copilot 🤖
-
PHP code showing before echo (echo shows fine though)
dmfgkdg replied to dmfgkdg's topic in PHP Coding Help
sorry, the resulting page actually shows: 'customer@example.com', 'source' => $token )); $charge = \Stripe\Charge::create(array( 'customer' => $customer->id, 'amount' => 999, 'currency' => 'usd' )); echo ' Successfully charged $9.99 test amount!'; ?> -
I'm testing a payment transaction with Stripe and have followed instructions as indicated on the Stripe API reference manual and also from a youtube video. There are 3 file I am working with: single.html (this is the test product page) config.php charge.php when I try to run a test transaction, everything works but the resulting charge.php page displays the PHP code before the echo message. The echo message is properly displayed, but upon review of the API reference guide and youtube video, I dont know why on their examples, the code does not show. So instead of displaying only: Successfully charged $9.99 test amount! the charge.php (https://p10.secure.hostingprod.com/@the-jewelry-district.com/ssl/home/index.php?page=charge.php) page shows: <?php require_once('---the config file----'); $token = $_POST['stripeToken']; $customer = \Stripe\Customer::create(array( 'email' => 'customer@example.com', 'source' => $token )); $charge = \Stripe\Charge::create(array( 'customer' => $customer->id, 'amount' => 1, 'currency' => 'usd' )); echo '<h1>Successfully charged $9.99 test amount!</h1>'; ?> 'customer@example.com', 'source' => $token )); $charge = \Stripe\Charge::create(array( 'customer' => $customer->id, 'amount' => 1, 'currency' => 'usd' )); echo '[/size] Successfully charged $9.99 test amount! '; ?>[/size] this is only in test mode. It's bugging me a lot. I need to know why this is happening to avoid any mistakes down the line. [/size] The product page is at: https://p10.secure.hostingprod.com/@the-jewelry-district.com/ssl/home/index.php?page=single.html you can use 4242424242424242 as the cc number and any dummy info to test the transaction. Just cant figure it out.
-
Well, per the javascript, a nice little results list should pop up per the search criteria "text" typed into the search form. I also updated the javascript parts where it has A_name, etc... to A.name (My current error probably resides in the javascript syntax) but I'm not sure.
-
Okay, so I changed my search.php file to get rid of all the backticks. Now, when I search the form. Absolutely nothing happens. here is the new search.php file: <?php //Prepare an array to hold data we are going to send back to the jQuery $data = array( 'results' => array(), 'success' => false, 'error' => '' ); //Has the text been posted? if (isset($_POST['text'])) { //Connect to the database $dbhost = 'localhost'; //hostname $dbuser = 'root'; //database username $dbpass = 'runrun'; //database password $dbname = 'loodt'; //database name //Create the connection to the mySQL database or catch the exception if there is an error $db = new mysqli($dbhost, $dbuser, $dbpass); $db->select_db($dbname); if($db->connect_errno > 0){ die('ERROR! - COULD NOT CONNECT TO mySQL DATABASE: ' . $db->connect_error); } //Escape the text to prevent SQL injection $text = $db->real_escape_string($_POST['text']); //Run a LIKE query to search for titles that are like the entered text $q = "SELECT A.name, D.name, A.file_no, A.claim_no, A.adj_no, F.acronym, A.doi, A.opened, A.status, A.redwells, C.initials, B.name, E.firm_name FROM ee A INNER JOIN adjuster B ON A.adjuster_id = B.id INNER JOIN attorney C ON A.attorney_id = C.id INNER JOIN er D ON A.er_id = D.id INNER JOIN aa E ON A.aa_id = E.id INNER JOIN wcab F ON A.wcab_id = F.id WHERE A.name LIKE '%{$text}%' OR A.file_no LIKE '%{$text}%' OR A.claim_no LIKE '%{$text}%' OR A.adj_no LIKE '%{$text}%' OR A.doi LIKE '%{$text}%'"; $result = $db->query($q); //Did the query complete successfully? if (!$result) { //If not add an error to the data array $data['error'] = "Could not query database for search results, MYSQL ERROR: " . $db->error; } else { //Loop through the results and add to the results array while ($row = $result->fetch_assoc()) { $data['results'][] = array( 'A_name' => $row['A_name'], 'D_Name' => $row['D_name'], 'A_file_no' => $row['A_file_no'], 'A_claim_no' => $row['A_claim_no'], 'A_adj_no' => $row['A_adj_no'], 'F_acronym' => $row['F_acronym'], 'A_doi' => $row['A_doi'], 'A_opened' => $row['A_opened'], 'A_status' => $row['A_status'], 'A_redwells' => $row['A_redwells'], 'C_initials' => $row['C_initials'], 'B_name' => $row['B_name'], 'E_firmname' => $row['E_firmname'] ); } //Everything went to plan so set success to true $data['success'] = true; } } //Set the content type for a json object and ensure charset is UTF-8. NOt utf8 otherwise it will not work in IE (Darn IE! >.<) header("Content-Type: application/json; charset=UTF-8"); //json encode the data and cast to an object so we can reference items like this.id in the javascript instead of this['id'] etc. echo json_encode((object)$data); ?>
-
I am having the search form query a inner joined table from multiple other tables in MySQL. I am using a local intranet with Xampp/Apache with When I run the SQL in PHPMyAdmin, it runs Perfect and produces the results exactly as I want them to appear on my website. My database name is: loodt My tables are: ee, er, aa, adjuster and attorney. I have foreign keys on the ee table for the other tables (ee.er_id = er.id) etc... However, when I try to run a search on my website, it pops up an error saying "Could not query database for search results, MYSQL ERROR Table 'loodt.ee a" doesn't exist." So I tried taking away the shortcut letters [referenced below in code] (A, B, C, D< E, & F) and typing in ee.name, er.name, etc... instead of assigning these letters and it didnt work either. I was using the search engine already to query results from a single table before I started to modify it a few days ago, So I know it works and has to be an issue with the "temporary" table and my lack of knowledge of course. Here is the search engine javascript: $(function(){ //Hide the result list on load $('#results-list').hide(); //Click event when search button is pressed $('#search').click(function(){ doSearch(); }); //Keypress event to see if enter was pressed in text input $('#text').keydown(function(e){ if(e.keyCode == 13){ doSearch(); } }); }); > function doSearch() { var searchText = $('#text').val(); //Rehide the search results $('#results-list').hide(); $.ajax({ url: './search.php', type: 'POST', data: { 'text': searchText }, beforeSend: function(){ //Lets add a loading image $('#results-holder').addClass('loading'); }, success: function(data) { //Take the loading image away $('#results-holder').removeClass('loading'); //Was everything successful, no errors in the PHP script if (data.success) { //Clear the results list $('#results-list').empty(); //Display the results //Check to see if there are any results to display if(data.results.length > 0) { //Loop through each result and add it to the list $.each(data.results, function(){ //Give the list element a rel with the data results ID incase we want to act on this later, like selecting from the list $('#results-list').append( "<li rel='" + this.A_name + "'>" + this.D_name + " | " + this.A_file_no + " | " + this.A_claim_no + " | " + this.A_adj_no + " | " + this.F_acronym + " | " + this.A_doi + " | " + this.A_opened + " | " + this.A_status + " | " + this.A_redwells + " | " + this.E_firm_name + " | " + this.B_name + " | " + this.C_initials + " </li>"); }); } else { //If there are no results, inform the user - add 'no-results' class so we can style it differently $('#results-list').append("<li class='no-results'>Your search did not return any results</li>"); } //Show the results list $('#results-list').fadeIn(); } else { //Display the error message alert(data.error); } } }); } The javascript file above is called from my index page in the header, not sure if that is important. And this is the search.php file that is called inside the javascript code above. > <?php //Prepare an array to hold data we are going to send back to the jQuery $data = array( 'results' => array(), 'success' => false, 'error' => '' ); //Has the text been posted? if (isset($_POST['text'])) { //Connect to the database > $dbhost = 'localhost'; //hostname $dbuser = 'xxxx'; //database username $dbpass = 'xxxxx'; //database password $dbname = 'loodt'; //database name > //Create the connection to the mySQL database or catch the exception if there is an error $db = new mysqli($dbhost, $dbuser, $dbpass); > $db->select_db($dbname); > if($db->connect_errno > 0){ die('ERROR! - COULD NOT CONNECT TO mySQL DATABASE: ' . $db->connect_error); } > > //Escape the text to prevent SQL injection $text = $db->real_escape_string($_POST['text']); //Run a LIKE query to search for titles that are like the entered text > $q = "SELECT `A.name AS A_name`, `D.name AS D_name`, `A.file_no AS A_file_no`, `A.claim_no AS A_claim_no`, `A.adj_no AS A_adj_no`, `F.acronym AS F_acronym`, `A.doi AS A_doi`, `A.opened AS A_opened`, `A.status AS A_status`, `A.redwells AS A_redwells`, `C.initials AS C_initials`, `B.name AS B_name`, `E.firm_name AS E_firm_name` FROM `ee A` INNER JOIN `adjuster B` ON `A.adjuster_id` = `B.id` INNER JOIN `attorney C` ON `A.attorney_id` = `C.id` INNER JOIN `er D` ON `A.er_id` = `D.id` INNER JOIN `aa E` ON `A.aa_id` = `E.id` INNER JOIN `wcab F` ON `A.wcab_id` = `F.id` > WHERE `A_name` LIKE '%{$text}%' OR `A_file_no` LIKE '%{$text}%' OR `A_claim_no` LIKE '%{$text}%' OR `A_adj_no` LIKE '%{$text}%' OR `A_doi` LIKE '%{$text}%'";; $result = $db->query($q); //Did the query complete successfully? if (!$result) { //If not add an error to the data array $data['error'] = "Could not query database for search results, MYSQL ERROR: " . $db->error; } else { //Loop through the results and add to the results array while ($row = $result->fetch_assoc()) { $data['results'][] = array( 'A_name' => $row['A_name'], 'D_Name' => $row['D_name'], 'A_file_no' => $row['A_file_no'], 'A_claim_no' => $row['A_claim_no'], 'A_adj_no' => $row['A_adj_no'], 'F_acronym' => $row['F_acronym'], 'A_doi' => $row['A_doi'], 'A_opened' => $row['A_opened'], 'A_status' => $row['A_status'], 'A_redwells' => $row['A_redwells'], 'C_initials' => $row['C_initials'], 'B_name' => $row['B_name'], 'E_firmname' => $row['E_firmname'] ); } //Everything went to plan so set success to true $data['success'] = true; } } //Set the content type for a json object and ensure charset is UTF-8. NOt utf8 otherwise it will not work in IE (Darn IE! >.<) header("Content-Type: application/json; charset=UTF-8"); //json encode the data and cast to an object so we can reference items like this.id in the javascript instead of this['id'] etc. echo json_encode((object)$data); ?>
-
Local vs. Global variable - Example from W3schools
dmfgkdg replied to dmfgkdg's topic in PHP Coding Help
Thank you. I see where I made my mistake and feel dumb for asking now. Thanks again!- 5 replies
-
- local variable
- global variable
-
(and 1 more)
Tagged with:
-
I took the following code from http://www.w3schools...p_variables.asp <?php $a = 5; $b = 10; function myTest() { global $a, $b; $b = $a + $b; } myTest(); echo $b; (this outputs 15) ?> The echo of $b comes after the closing of the function. The output is 15. If you add another echo inside the function like below: <?php $a = 5; $b = 10; function myTest() { global $a, $b; $b = $a + $b; } echo $b; (this one outputs 10) myTest(); echo $b; (this one outputs 15) ?> then the output for that echo is 10. I understand that the function is calling the global variables, but shouldnt the echo inside the function equal 15 and the one outside equal 10?, since it only refers to the global "$b" and is outside the function? Or does the global call inside the function completely change $b for the rest of the script? Thanks guys (and gals)
- 5 replies
-
- local variable
- global variable
-
(and 1 more)
Tagged with:
-
Hi, I am fairly new to PHP too, but I can't find anything here that looks bad, except the path if it does not exist or is an another directory. Or if the include files have errors themselves. Sorry, maybe some more info would help.
-
Breadcrumbs displayed using table info from MySQL
dmfgkdg replied to dmfgkdg's topic in PHP Coding Help
I only did it this way to have the backend of my site have a page where an employee can easily fill out the fields through a simple add product page instead of having them go into MySQL. I will look into putting the categories in another table, It's just going to be a pain to redo that backend page because I dont know this stuff. All in a days work I guess. Thank you.- 11 replies
-
- php
- breadcrumbs
-
(and 2 more)
Tagged with:
-
Breadcrumbs displayed using table info from MySQL
dmfgkdg replied to dmfgkdg's topic in PHP Coding Help
Thanks for all of your help. This ended up working for me: $breadcrumbs = array($category, $subcategory, $sub_subcategory_1, $sub_subcategory_2, $sub_subcategory_3, $sub_subcategory_4, $sub_subcategory_5); echo implode(' | ', array_filter($breadcrumbs)); although echo join(' | ', array_filter($breadcrumbs)); works too. I forgot to ask about the hyperlinks. If I want to make these breadcrumbs clickable, how would I do that? Any suggestions would be greatly appreciated.- 11 replies
-
- php
- breadcrumbs
-
(and 2 more)
Tagged with:
-
Breadcrumbs displayed using table info from MySQL
dmfgkdg replied to dmfgkdg's topic in PHP Coding Help
Now we are getting somewhere. Thanks. So Both of these work, I would prefer to use the array. However, it still echos out the end "|" several times for the empty variables. How do I make the implode function only display the variables that are not empty? I did this: $breadcrumbs = array($category, $subcategory, $sub_subcategory_1, $sub_subcategory_2, $sub_subcategory_3, $sub_subcategory_4, $sub_subcategory_5); echo implode(' | ', $breadcrumbs);- 11 replies
-
- php
- breadcrumbs
-
(and 2 more)
Tagged with:
-
Breadcrumbs displayed using table info from MySQL
dmfgkdg replied to dmfgkdg's topic in PHP Coding Help
Thats the thing. I want to be able to leave "sub_subcategory_X" empty and not display the "|" after it. And you have to understand that the categories are not dynamically created. I will be hand typing in each category, subcategory, etc... in excel, uploading a csv file to MySQL. So I font need the MySQL structure changed. Thanks for trying to help!- 11 replies
-
- php
- breadcrumbs
-
(and 2 more)
Tagged with:
-
I have a crude eCommerce website i am building (the-jewelry-district.com/store) and i want to create a breadcrumbs script. here is my product.php page. im not sure if i need the script on my index.php as well. right now i have a simple echo of the categories and sub categories in the table from the database. 7 fields to be exact. Here they are as defined in the script below: $category = $row["category"]; $subcategory = $row["subcategory"]; $sub_subcategory_1 = $row["sub_subcategory_1"]; $sub_subcategory_2 = $row["sub_subcategory_2"]; $sub_subcategory_3 = $row["sub_subcategory_3"]; $sub_subcategory_4 = $row["sub_subcategory_4"]; $sub_subcategory_5 = $row["sub_subcategory_5"]; The problem is if the product only requires "category", "subcategoty" & "sub_subcategory_1" only then the end result is something like this: Category | Subcategory | Sub-Subcategory_1 | | | | | I use " | " as the heirachy separator so at the end, the echo still prints these. I based my site off of a 20 video ecommerce php & MySQL tutorial on youtube by a gentleman by the name of Adam Khoury in case you guys are wondering where I got this code from. Here is the entire product.php script I have. The while loop pretty much describes the table I use for my products. <?php include "storescripts/script_error_reporting.php"; /*Check to see the URL variable is set and that it exists in the database*/ if (isset($_GET['id'])) { // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $id = ($_GET["id"]); /*Use this var to check to see if this ID exists, if yes then get the product details, if no then exit this script and give message why*/ $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { /*get all the product details*/ while($row = mysql_fetch_array($sql)){ $product_name = $row["product_name"]; $browser_tab_title = $row["browser_tab_title"]; $url_name = $row["url_name"]; $price = $row["price"]; $details = $row["details"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $sub_subcategory_1 = $row["sub_subcategory_1"]; $sub_subcategory_2 = $row["sub_subcategory_2"]; $sub_subcategory_3 = $row["sub_subcategory_3"]; $sub_subcategory_4 = $row["sub_subcategory_4"]; $sub_subcategory_5 = $row["sub_subcategory_5"]; $image_a = $row["image_a"]; $image_b = $row["image_b"]; $image_c = $row["image_c"]; $image_d = $row["image_d"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "That item does not exist."; exit(); } } else { echo "Data to render this page is missing."; exit(); } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $browser_tab_title; ?></title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <?php include_once("template_header.php");?> <div id="breadcrumbs"> <p> <?php echo "$category | $subcategory | $sub_subcategory_1 | $sub_subcategory_2 | $sub_subcategory_3 | $sub_subcategory_4 | $sub_subcategory_5"; ?> <br /> </p> </div><!--breadcrumbs--> <!--PERMANENT ABOVE--> <div id="prodcont"> <div id="product"> <div id="productContent"> <div class="prodimgl"> <img src="inventory_images/<?php echo $image_a; ?>.jpg" width="300" height="300" > <img src="inventory_images/<?php echo $image_b; ?>.jpg" width="300" height="300" > <!--<img src="inventory_images/<?php echo $image_c; ?>.jpg" width="300" height="300" >--> <p>View Full Size Image</p> <a href="inventory_images/<?php echo $image_a; ?>.jpg" target="_blank">A</a> <a href="inventory_images/<?php echo $image_b; ?>.jpg" target="_blank">B</a> <!--<a href="inventory_images/<?php echo $image_c; ?>.jpg" target="_blank">C</a>--> </div><!--prodimg1--> <div class="proddesc"> <h1> <?php echo $product_name; ?> </h1> <div id="productDescription"> <?php echo $details; ?> <br /> <?php echo "$".$price; ?> <br /> <br /> <br /> </p> <form id="form1" name="form1" method="post" action="cart.php"> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> <input type="submit" name="button" id="button" value="Add to Shopping Cart" /> </form> </div><!--productDescription--> </div><!--proddesc--> </div><!--productContent--> </div><!--product--> </div><!--prodcont--> <?php include_once("template_footer.php");?> </body> </html>
- 11 replies
-
- php
- breadcrumbs
-
(and 2 more)
Tagged with: