How can I get this kind of a textbox created?

Hi!

I’m very new at this and the problem mostly is that I don’t have a clue what this action is called so I can google the help I need.

The page where I have found such a textbox which send a query to a database and prints out the price under it is here: http://omaguru.fi/tietokone/tietoturvan-asennus
And If you type postal code like 33200 it will print out a text which says the price of the visit after you push the submit button labeled “Tarkista”.

So If someone can just tell me what this is called or how can I find a tutorial to how to create this I would be so greatful. My native language is not english, so sorry for my bad grammar.

Thanks again and sorry if I posted this in a wrong place.

Chances are good that its either jquery or Ajax.

That still doesn’t answer my question on what is this action called, when you have a postcode that you write on the textbox and when you click submit, you get a price on that particular area.
example:

Database:
postcode(col1) Price(col 2)
12345 50€
23456 55€
34567 60€
45678 65€
56789 70€

When a person types the number 12345 on the textbox and presses submit the text on the price will be printed under the textbox. If the postcode is invalid or is out of the coverage area there will be a text which gives an error message ‘postcode unknown’.

Thanks again.

You’d have to store every single postcode in a database and then return the price. It’s just MySQL Queries. If you want it to do it as you type, you need jquery or ajax.

If I’m not mistaken, it would be similar to this.

[code]

TITLE OF PAGE Enter Postal Code [/code]

That would be the form page (form.php) and it redirects to form2.php, transferring what they entered as a postal code

Here is form2.php

[php]<?php
/*
Insert in here your
database settings
or if you want it,
session settings
which I assume
you know how to
do. I also assume
the database name
is form,but you can
change that to your
liking
*/
$code = $_POST[‘code’];
//That turns the code they entered into a variable
$sql = mysql_query(“SELECT * FROM form WHERE prices”);

$one = “SELECT * FROM form WHERE code=’$code’”;
$two = mysql_query($one);
$row = mysql_fetch_row($two);
$price = $row[1];
/*
You now know
the row that the
postal code is on.
Using that, you found
the corresponding
price in that what I
like to call, the one two
method. I made up that
name. If there is a column
between the postal code
and the price, then that
means that you have
to change it from row[1]
to row[2] etc. The code
would be row[0] then
as the columns move on
they ascend to 1, 2, 3, etc.
*/

/*
The following is a
validation method.
It’s very tedious, and
not recommended for
multiple rows
*/

$item1 = “whatever_price_here”;
$item2 = “whatever_price_here”;

//And so on

/*
Then you can run a
loop to check if $price
equals any of those
variables, which I don’t
know how to do. You can
change that process to
whatever other method
*/

echo "The price is " . $price “”;
?> [/php]

Thank you very much for this!!!

What I ended up was using ajax and jquery. I use localhost and MAMP to run the server.
The idea is the same but except for one price I ended up printing all the product prices. I only now have a problem to print out the error message when the query comes out as NULL. So if you guys could help me with this, I would really be happy. :slight_smile:

Here’s the html code
[php]

Tarkista palvelupakettien hinta ja saatavuus alueellasi

(Huom! Mikäli mitään hinnastoa ei ilmesty, ei palvelua ole valitettavasti tällä hetkellä aluellasi)

Kirjoita postinumerosi kenttään:
Hinta sisältää kaikki kustannukset (alv, matkat) ja pakettihinta on määritelty yhden (1) tunnin keston mukaisesti.
[/php]

and the PHP
[php]

<?php $q=$_GET["q"]; $con = mysql_connect('localhost', 'root', 'root'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Posti", $con); $sql="SELECT hinta FROM `hinnasto` WHERE `postinro` = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $a = $row['hinta']; $ohje = $a + 45; $tiet = $a + 35; $mode = $a + 40; $kayt = $a + 60; $viru = $a + 30; $lisa = $a + 30; $pika = $a + 70; echo ""; { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Ohjelmistohuolto " . $ohje . " euroa
Tietotunti " . $tiet . " euroa
Modeemipalvelu " . $mode . " euroa
Käyttöönottopaketti " . $kayt . " euroa
Virustenpoisto " . $viru . " euroa
Lisälaiteasennus " . $lisa . " euroa
Pikapalvelu (4h sis.) " . $pika . " euroa
"; } ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service