Jump to content

Archived

This topic is now archived and is closed to further replies.

christo

Image map HTML/PHP

Recommended Posts

Here we go again with another subject !

1 )I have an image map in html and i want to pass values to a php script...

exemple :
[code]<area shape="poly" coords="257,335,255,344,240,352,241,365,256,384,261,379,261,363,261,348" href="reg_map.php">[/code]
so this is a region called corsica and i want to send the 2 values, region and a name let's say corsica, to the reg_map.php knowing that region will be stable and the name will change corsica, texas,cafifornia etc...depends where the users click...They can click further and it will be perhaps region , montana
How do i do this???
will it work if i go [code]<area shape="poly" coords="257,335,255,344,240,352,241,365,256,384,261,379,261,363,261,348" href="reg_map.php"?region=Colorado> [/code]

2)At the reg_map.php i want to get the region, something and do a query the DB something like :
[code]$query=mysql_query("SELECT * FROM  object WHERE region='".$HTTP_POST_VARS['region']."'");
[/code] how does it look like?

christos

p.s it sounds ridiculous to ask if it will work but it's because i'm not done with the display results :)
p.s working under win xp and php 4.3

Share this post


Link to post
Share on other sites
You almost have it right.. Just move the ending double quote to include the parameter.
[code]href="reg_map.php?region=Colorado"[/code]

Ken

Share this post


Link to post
Share on other sites
1) sorted thanks :) the real problem remain though, that's where i have most difficulties...

2)At the reg_map.php i want to get the region, something and do a query the DB something like :
CODE
$query=mysql_query("SELECT * FROM object WHERE region='".$HTTP_POST_VARS['region']."'");
how does this look like?

christos

p.s it sounds ridiculous to ask if it will work but it's because i'm not done with the display results :)
p.s working under win xp and php 4.3

Share this post


Link to post
Share on other sites
When you want to retrieve a value that is passed in via the URL you will find it in the $_GET superglobal array, so you code should look something like:
[code]<?php
$query="SELECT * FROM object WHERE region='" . $_GET['region'] . "'";
$rs = mysql_query($query) or die('Problem with query: ' . $query . '<br>' . mysql_error());
?>[/code]

I always like to seperate the query string from then mysql_query() function call and add the "or die" clause. It makes debuginng much easier.

Ken

Share this post


Link to post
Share on other sites
hmm nope it gives errors...Could you take a look at my code please ?

<A quick sum : the html needs to pass region, something to php and this one will do a request at the DB to show any results> HTML :[code]<html>
    <head>
        <title>* Regions  *</title>
    </head>
<body>
<div style="position:absolute;top:40px;left:250px;width:100%;text-align:center;">
<a href="search.html">Retour </a></div>

<div style="position:absolute; top:30px;left:100px;">
<A name="map">
    <h3>Region map</h3>
      <div>
        <div align="center"><img src="regions.gif" width="400" height="395" vspace="10" border="3" usemap="#Map" >
          <map name="Map">
          <area shape="poly" coords="5,116,37,114,46,124,69,123,69,128,77,129,76,144,71,152,67,147,61,152,55,151,53,156,47,159,39,166,27,162,3,144,3,116" href="reg_map.php?[color=#FF0000]region=texas[/color]">
          <area shape="poly" coords="64,91,77,94,79,102,98,108,107,104,106,120,116,129,113,142,101,132,95,133,94,129,81,132,69,128,69,109" href="reg_map.php?[color=#FF0000]region=colorado[/color]">.......some more of those....</map>
        </div>
      </div>
</body>
</html>[/code]

PHP receiving the region, something :[code]<?
//to get the value from html
$region = $HTTP_POST_VARS['region'];  //At this point a get a Notice

echo"
<html>
        <title>* Offers / region *</title>
    <body>
        <table border=\"1\">
        <tr><td>Annonce # :</td><td>Region :</td><td>town :</td></td><td>Type :</td>
            <td>Transaction :</td><td>Price :</td><td>agency:</td><td>Date  :</td>
        </tr>";

$host = "???";
$user = "???";
$pass = "???";
$base = "???";
//DB connection
$db_conx = mysql_connect($host,$user,$pass) or print("error connection mysql");
mysql_select_db($base, $db_conx) or print("error connection base");

$query=mysql_query("SELECT * FROM  object region='".$_GET['region']."'");
//if...error else show result
$check_reg = mysql_num_rows($query);  // at this point i get Warning
if($check_reg == 0) {
    echo "no offers for '$region'.<br>
        <a href=\"reg_map.html\">back</a><br><br>";
    }
    else {
        while(($data=mysql_fetch_array($query))!==false) {

        echo "<tr>
        <td><a href=\"full_obj.php\">".$data['objid']."</a></td>
        <td>".$data['region']."</td>
        <td>".$data['city']."</td>
        <td>".$data['accomodation']."</td>
        <td>".$data['transaction']."</td>
        <td>".$data['price']."</td>
        <td>".$data['age_par']."</td>
        <td>".$data['date_aj']."</td>
        </tr>";
    }
} [/code]
But it produces those faults
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Notice: Undefined index: region in c:\foreign\easyphp1-8\www\agence\test\reg_map.php on line 2

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\foreign\easyphp1-8\www\agence\test\reg_map.php on line 23 [/quote]

since i'm under php 4.3 maybe i should use $HTTP_POST_VARS instead of $_GET no?
i'm not sure i'm a bit comfuzed...

Share this post


Link to post
Share on other sites
The superglobal arrays were introduced in ver 4.1

Please read [a href=\"http://www.php.net/manual/en/language.variables.external.php\" target=\"_blank\"]this section[/a] in the fine manual.

In your code, use the $_GET array for values gotten from the URL.

[code]<?php $region = $_GET['region']; ?>[/code]

Share this post


Link to post
Share on other sites
True truei was dumb not to see, it wouldn't work because sinmple there is no post, submit thing on the html form...i also noticed that $_REQUEST works also ;)

The problem with the DB is till there though...[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\foreign\easyphp1-8\www\agence\test\reg_map.php on line 23[/quote] which is[code]$query=mysql_query("SELECT * FROM  object region='".$_GET['region']."'");
//if...error else show result
$check_reg = mysql_num_rows($query);  // at this point i get Warning
if($check_reg == 0) {
    echo "no offers for '$region'.<br>
        <a href=\"reg_map.html\">back</a><br><br>";
    }
    else {
        while(($data=mysql_fetch_array($query))!==false) {

        echo "<tr>
        <td><a href=\"full_obj.php\">".$data['objid']."</a></td>
        <td>".$data['region']."</td>
        <td>".$data['city']."</td>
        <td>".$data['accomodation']."</td>
        <td>".$data['transaction']."</td>
        <td>".$data['price']."</td>
        <td>".$data['age_par']."</td>
        <td>".$data['date_aj']."</td>
        </tr>";
    }
}[/code] Why doesn't it understan the affectation?
Do you think the while will work in this place i have it?

Share this post


Link to post
Share on other sites
That error usually is an indication that you had a syntax problem with your query, change you query statement to these statements:
[code]<?php
$query="SELECT * FROM  object region='".$_GET['region']."'";
$rs = mysql_query($query) or die('Problem with query: ' . $query . '<br>' . mysql_error());
$check_reg = mysql_num_rows($rs);
?>[/code]

Ken

Share this post


Link to post
Share on other sites
I like the precisions of mysql_error, thanks for the tip ;)
This is the new (same) error but it's strainge because it's not a complicated request...
so idon't see where could the error be...hmmmm

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Problem with query: SELECT * FROM object region='colorado'
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '='colorado'' at line 1 [/quote]

christos

Share this post


Link to post
Share on other sites
You're missing the "where " keyword:
[code]<?php $query="SELECT * FROM  object WHERE region='".$_GET['region']."'"; ?>[/code]

Ken

Share this post


Link to post
Share on other sites
damnnn i'm bad lol...
I must be tired, i will take a break...yeah he he he

Well that's it sorted (well a big part is yours [b]kenrbnsn[/b])
Thanks christos

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.