Issues with a script?

I have a script that is installed here. xgarage.org

  1. When it first loads it will not work unless you fiddle with it. Once it does work you can delete your browser cache and retest.
  2. It also leaks the data if you go to this URL https://xgarage.org/ which should not happen.
  3. It also leaks the data if you go here. https://xgarage.org/
  4. I’m not sure how to pass the data to a multi-step form.
    Can you can grab the selected data if you’re using jQuery like.

$("#year :selected")
$("#make :selected")
$("#model :selected")

  1. I would like it to work something like these examples.

  2. Here is all the code

Thanks in advance.
Bill

BTW the site is running php 7.3

i don’t know why you want to use query strings and get requests in place of a form post. i can’t help with that because i only use post methods. i think it is valid to use select without a form tag but simply why? i dont get it. i would prefer to use a post and validate the data while restricting it to numbers of four digits. anyway…

where are you storing your database connection details? i see a constant in a class file with data that isn’t useful for connecting to a database.

public const DB_SERVER = 'DB_HOST';
public const DB_USERNAME = 'DB_USERNAME';
public const DB_PASSWORD = 'DB_PASSWORD';
public const DB_DATABASE_NAME = 'DB_NAME';
public const DB_PORT = '3306';

where do you pass the actual username and password, for example?

$year = (ISSET($_GET['year']) && $_GET['year']!=='') ? $_GET['year'] : "2013";

i suggest that you rethink this concept of $year variable usage.

Here is the original script as written which i purchased. It would not work on newer php versions. So i had it upgraded here. However it did not work like this older version which ran on php 5.6 anyway here it is. https://xgarage.org/

Also here is this new connection.php in the specific area you inquired about.


    public const DB_SERVER = 'localhost';
    public const DB_USERNAME = 'xgarage_jk(osFN*';
    public const DB_PASSWORD = 'usk8w038hsf';
    public const DB_DATABASE_NAME = 'xgarage_kL*Vh6(';
    public const DB_PORT = '3306';

This is the only config above needed to make it work. Also those certainly are not the correct login details to my database.

Also here is the thread where i requested help. I have no idea how to properly code any of this. So i have started this new thread to get my project back on track. It’s unimportant to me who upgraded this script. I just know it still needs some work because it’s certainly not correct so to speak.

Thanks for your time.
Bill

I also have my son looking at this thread. Maybe he might be able to help with answering your questions a lot better than i can.

My son just pointed out to me that this script also needs to be accessible to mobile user as well. So there’s that too.

well i will look at the new zip after i eat my dinner. i am in Berlin and it is after six pm here.
anyway, i am often very busy. too busy to even tweak someones code but a simple post script is easy enough. i can help you out with a better form process when i get some free time.

nice to know that you have the common sense to not post your real db password. you would be surprised at people that do this sort of thing. so very good. :slight_smile:

again, i can help you with a simple form and form processing script when i have free time. maybe even later today. i will have to see. otherwise, sometime soon.

but bear in mind that i strongly suggest that you learn pdo. for goodness sake. pdo is easy and much safer to use.

Yea i posted that i wanted it to be PDO. However this is what i got back from the dev here. So there’s that. Btw i don’t expect anything for free. I really appreciate all of the dev’s here and the most important thing is their time.

Best Bill

well i will help you with a script to replace this stuff but i prefer that you donate ten bucks or so to a charity or donate blood to a blood drive or something thoughtful. i’m not interested in petty cash for a simple script. i certainly don’t want to take away from anyone here that needs the money. if someone wants to freelance then speak now or keep your peace.

Oh the “website examples” i provided are much better than the select boxes because of mobile users.

Ah you slipped that post in on me. I would gladly donate $50.00 to the charity of your choice kind sir!

You would need to be more specific about what ‘will not work’ and ‘fiddle with it’ means.

You would need to detect if the request was via an ajax request and only run the .php code if it is. The following line produces a defined constant that can be tested anywhere in the rest of the php code on the page -

// determine if the request was an ajax request
define('IS_AJAX_REQUEST', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

Usage -

if(IS_AJAX_REQUEST){
	// the following code is only ran if there's an ajax request

}

To submit the selected values using a form, you would add a form, with a submit button, around the three select menus.

If you want to use the selected values on the current page, you would reference them using the three jquery statements you posted.

Note: The code you have is not how this process is normally done. It has a hard-coded list of years, when you select a year it returns ALL the make and model data for that year to the browser, finds the unique make information for the make menu, triggers a change event for the make menu to populate the model menu, which leaves you with the first make/mode information pre-selected.

How this is normally done is - query to get a list of the unique years that exist in the data and use this to produce the year menu. When a year is selected, get a unique list of makes for that year. When a make is selected, get the models for that year and make.

1 Like

Ok let me chew on what your saying here a bit as i’m not versed in PHP code. I will need to get my son to translate what you just said.

I know that were are going to be using this API in order to update this script for all US data.

I also know that the selects in those combo boxes are not needed as they are not mobile friendly.

Now let me review this thread so i can be more helpful than i have been. Again i’m going to need my son. As i live on the East Coast and he on the West. So three hour time difference.

Thanks for all the great posts!

phdr did a fine job pointing you in the right direction. stick with his suggestions for cleaning up your code. noo need for a rewrite if you follow his lead.

Okay if you load the site with no cache. You need to select a YEAR to get started. However on my end i need to select a YEAR multiple times in order to get any MAKE to load. Once the MAKE does load it seems to work fine from then on out.

So i guess you can say once the cache is loaded properly in my chrome browser the script will work. However if i dump the cache and try it again. I have to load different YEARS multiple times again to get the MAKE to work.

Here is my point though i don’t want select boxes. I want the first step to load with the years like this so mobile user don’t have such a hard time.

I hope that makes sense for the first question.

Okay i will have him look at all this ASAP. Thank you!

If the year you are initially selecting is 2010 (which is what I picked too), there’s no data in your database that matches that year. If it is the first year you pick, you don’t get any choices for the next two select menus. If you pick some other year first, that does have data, then pick 2010, you get the choices from whatever year you picked before. The code isn’t correctly dealing with empty data.

The last paragraph in my reply above, which lists what the work-flow should be, just mentions menu. You can present the data that the query returns any way you want. If you want to display it as rows and columns of links, you can do so, and in fact the existing code, which dynamically produces the make/model select menu markup using javascript, is not general purpose. If using ajax to just display the user interface, you might as well produce the html markup on the server, return it, and just have the ajax code output it at the correct place on the page.

Lastly, the hollander parts site you linked to does NOT use AJAX to accomplish this. It is using just html/php, with links for navigation. The reason you would want to do it this way is so that if someone finds information on your site that they want to return to or share with others, they can bookmark the page. When you use ajax to select/find/display content, you cannot directly do this, making it harder for the user to return to the same place on your site (you can modify the url in the address bar to match what the ajax is doing, but this is more work and doesn’t work if someone has disabled javascript.)

I also notice that the hollander parts site displays make information (Fiat for example) for which no model information exists in a year. You would want to avoid this so as to not cause visitors to waste time clicking on links that don’t have any data. You would either not display the make at all or display it as a non-link.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service