Web Hosting Talk







View Full Version : New to php/mysql.. how do i do this?


netmotiv8
04-22-2004, 12:23 PM
Hi,

I am trying to do this kind of thing:

http://www.prestige-car-leasing.co.uk/special-offers.asp


Whereby a visitor can click something they are interested in and those details are populated into a web form, with additional options to complete and then email to the sales dept or whatever.

How do I do this in php/mysql.

I have already created a database and populated it with data and shown it on web page etc but have come unstuck at doing something clever such is being done on the url above.

All help greatly received :-)


Neil

Loon
04-22-2004, 12:43 PM
well, once you have a unique ID to identify each car/product, there's many ways you can do it, but generally all you'd need to do is:

Call each of your items by the url such as http://domain.com/cars.php?carID=01

Then in "cars.php" you would just get the called ID from the url using $_GET

$carID = $_GET['carID'];

And then use that to select the needed row from your database:


$data = mysql_query("SELECT * FROM table_name WHERE carID = '$carID'");

You can then print out the value of each field for that row with a loop:


while($row = mysql_fetch_array($data)) {
#print each $row['item']; among your HTML
}

Obviously, there's a little more to it than that, you'll want to think about error checking, how you want to display your info and a number of other things, but mabye that'll get you going in the right direction. :)

netmotiv8
04-23-2004, 12:28 PM
thanks, I not sure if I 100% understand, but will give it go.

how for example can I pass that cars details e.g make and model into the make and model form fields in cars.php?

trukfixer
04-23-2004, 12:56 PM
Originally posted by netmotiv8
thanks, I not sure if I 100% understand, but will give it go.

how for example can I pass that cars details e.g make and model into the make and model form fields in cars.php?
build an html form, when they click submit on the form, cars.php gets the data as $_POST['form_field_name'];

(if you use form method = "post" )

with that in mind you should be able to find about everything you need at http://www.w3c.org and http://www.php.net

I've done about 25 custom scripts already getting values out of teh database to populate a form field as a select option, etc. etc... lots of ways to get what you want,

or you could simply let the user input their own data and use metaphone() function of php to compensate for spelling errors.. (it would see a value of "phord = fword=ford=vord so mispellings that are spelled sounding phonetically the same as the car model and make, etc could easily be used to find data).... it isnt 100% accurate though, so that's kind of over-coding when its a simple matter to make a form with select options.

netmotiv8
04-23-2004, 01:20 PM
Sorry guys, I am not getting head around this. Like I said I am very much a newbie to php/mysql. My level is be able to print and order mysql data on a php page and that about it.

http://www.prestige-car-leasing.co.uk/special-offers.asp

As it that example which I came across. In that page they are show a list of cars and when a user clicks on a car they are interested in they are taking to a form which has already had fields completed relating to the car they have selected and this is what I am trying to do

here is my very basic mock up (apologies for crudeness) http://www.netmotivated.co.uk/projects/mysql/index.php

this shows the data from the database. Now for each row I want to add a 'more info' link which when clicked takes them to a form like the first link above and passes this data to the appropriate form fields in that form ready for the customer to 'submit'.

Sorry but a need 'A Dummies guide...'

I kind of need to see the code required, to learn and understand it.

Neil :D