Jump to content


Photo

Image map HTML/PHP


  • Please log in to reply
10 replies to this topic

#1 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 01 May 2006 - 11:27 PM

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 :
<area shape="poly" coords="257,335,255,344,240,352,241,365,256,384,261,379,261,363,261,348" href="reg_map.php">
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
<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>

2)At the reg_map.php i want to get the region, something and do a query the DB something like :
$query=mysql_query("SELECT * FROM  object WHERE region='".$HTTP_POST_VARS['region']."'");
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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 01 May 2006 - 11:30 PM

You almost have it right.. Just move the ending double quote to include the parameter.
href="reg_map.php?region=Colorado"

Ken

#3 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 02 May 2006 - 09:05 AM

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

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 May 2006 - 11:49 AM

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:
<?php
$query="SELECT * FROM object WHERE region='" . $_GET['region'] . "'";
$rs = mysql_query($query) or die('Problem with query: ' . $query . '<br>' . mysql_error());
?>

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

#5 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 02 May 2006 - 03:12 PM

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 :
<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>

PHP receiving the region, something :
<?
//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>";
    }
}
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...

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 May 2006 - 03:17 PM

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.

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


#7 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 02 May 2006 - 05:22 PM

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
$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>";
    }
}
Why doesn't it understan the affectation?
Do you think the while will work in this place i have it?

#8 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 May 2006 - 06:06 PM

That error usually is an indication that you had a syntax problem with your query, change you query statement to these statements:
<?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);
?>

Ken

#9 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 02 May 2006 - 06:24 PM

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

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 May 2006 - 06:27 PM

You're missing the "where " keyword:
<?php $query="SELECT * FROM  object WHERE region='".$_GET['region']."'"; ?>

Ken

#11 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 02 May 2006 - 06:42 PM

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 kenrbnsn)
Thanks christos




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users