Jump to content

[SOLVED] Map hotspot


patrickking04

Recommended Posts

Hi all,

 

Right I have a map of the school I work at as the back ground picture and then loads of transparent boxes over certain areas. A student then would click the area (box) where they are being bullied and then it would add a +1 to mysql field to the correspondent area (box).

 

How would I set an image to add +1 to a mysql field?

 

any help would be great.

Link to comment
Share on other sites

<MAP NAME="map1">
<AREA
   HREF="processbully.php?id=1" ALT="Area 1" TITLE="Area1"
   SHAPE=RECT COORDS="6,116,97,184">
<AREA
   HREF="processbully.php?id=2" ALT="Area 2" TITLE="Area2"
   SHAPE=CIRCLE COORDS="251,143,47">
<AREA
   HREF="processbully.php?id=3" ALT="Area 3" TITLE="Area3"
   SHAPE=POLY COORDS="150,217, 190,257, 150,297,110,257">
</MAP>

 

if you post a bit of your image map code I will show you what I mean if you still not sure

Link to comment
Share on other sites

Heres the code so far. also im using Serif Webplus x2

 

<?php include 'connect.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>Home</title>
<style type="text/css">
<!--
body {margin: 0px; padding: 0px;}
a:link {color: #2c3651;}
a:visited {color: #1f5b8b;}
a:hover {color: #2c3651;}
a:active {color: #2c3651;}
-->
</style>
<script type="text/javascript"><!--
var blankSrc = "wpscripts/blank.gif";
--></script>
<script src="wpscripts/jspngfix.js" type="text/javascript"></script>
</head>

<body text="#000000" style="background: #ffffff; text-align:center; height:1000px;">
<div style="background: transparent; position:relative;width:750px;height:1000px;margin-left:auto;margin-right:auto;">
<div style="position:absolute; left:43px; top:21px; width:677px; height:967px;">
    <img src="wpimages/Map.jpg" width="677" height="967" border="0" id="Site_Map" name="Site_Map" title="" alt=""></div>
<div style="position:absolute; left:104px; top:203px; width:14px; height:152px;">
    <img src="wpimages/Math_corri.png" width="14" height="152" border="0" id="Math_corri" name="Math_corri" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:118px; top:310px; width:24px; height:210px;">
    <img src="wpimages/Science_corri.png" width="24" height="210" border="0" id="Science_corri" name="Science_corri" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:105px; top:520px; width:24px; height:139px;">
    <img src="wpimages/Human_corri.png" width="38" height="139" border="0" id="Human_corri" name="Human_corri" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:130px; top:634px; width:140px; height:27px;">
</div>

</body>
</html>

Link to comment
Share on other sites

<div style="background: transparent; position:relative;width:750px;height:1000px;margin-left:auto;margin-right:auto;">
<div style="position:absolute; left:43px; top:21px; width:677px; height:967px;">
    <a href="bullyprocess.php?id=1"><img src="wpimages/Map.jpg" width="677" height="967" border="0" id="Site_Map" name="Site_Map" title="" alt=""></a></div>
<div style="position:absolute; left:104px; top:203px; width:14px; height:152px;">
    <a href="bullyprocess.php?id=2"><img src="wpimages/Math_corri.png" width="14" height="152" border="0" id="Math_corri" name="Math_corri" title="" alt="" onload="OnLoadPngFix()"></a></div>
<div style="position:absolute; left:118px; top:310px; width:24px; height:210px;">
    <a href="bullyprocess.php?id=3"><img src="wpimages/Science_corri.png" width="24" height="210" border="0" id="Science_corri" name="Science_corri" title="" alt="" onload="OnLoadPngFix()"></a></div>
<div style="position:absolute; left:105px; top:520px; width:24px; height:139px;">
    <a href="bullyprocess.php?id=4"><img src="wpimages/Human_corri.png" width="38" height="139" border="0" id="Human_corri" name="Human_corri" title="" alt="" onload="OnLoadPngFix()"></a></div>
<div style="position:absolute; left:130px; top:634px; width:140px; height:27px;">
</div>

Link to comment
Share on other sites

processbully.php

 

<?php if (isset($id)) { 
$sql="SELECT * FROM table WHERE id='$id'";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
$name=$row[name];// this is the column name in your db for the name of the area
$value=$row[value];// this is the column name in your db for value of incidents
$newvalue=$value+1;
$sql="UPDATE table SET value='$newvalue' WHERE id='$id'";
$query=mysql_query($sql);
echo "$newvalue incidents in area $name";
} else { die("Error:$name not updated"); }

Link to comment
Share on other sites

processbully.php

 

<?php if (isset($id)) { 
$sql="SELECT * FROM table WHERE id='$id'";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
$name=$row[name];// this is the column name in your db for the name of the area
$value=$row[value];// this is the column name in your db for value of incidents
$newvalue=$value+1;
$sql="UPDATE table SET value='$newvalue' WHERE id='$id'";
$query=mysql_query($sql);
echo "$newvalue incidents in area $name";
} else { die("Error:$name not updated"); }

 

I Keep getting  Error: not updated    even tho its selecting the right database, table and it have the same named feilds.

Link to comment
Share on other sites

change

die("Error:$name not updated");

to

die("Error:$id not updated");

 

make sure that when you get the error it tells you the id you sent, also have you got an id column in your datasbase and is your database called table?

Also the id column numbers would need to match the id numbers you send to the script.

Link to comment
Share on other sites

Hi

 

Try this

 

<?php 
if (isset($id)) 
{ 
$sql="SELECT * FROM `table` WHERE id=id";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
$name=$row[name];// this is the column name in your db for the name of the area
$value=$row[value];// this is the column name in your db for value of incidents
$newvalue=$value+1;
$sql="UPDATE `table` SET value='$newvalue' WHERE id=$id";
$query=mysql_query($sql);
echo "$newvalue incidents in area $name";
} 
else 
{ 
die("Error:$id not updated"); 
}
?>

 

Suspect table is a reserved word in mysql which could cause issues if you name a table that, hence surrounding it in apostrophies.

 

Also not sure why you appear to have a $name field which isn't used.

 

All the best

 

Keith

Link to comment
Share on other sites

The $name feild is used above in the echo statement  ;D as a visual reference for which area was updated, this way the user knows they have updated the right area. id's are for databases to reference, names are for people to reference.

 

I wouldnt use the name table either as a tablename, I used that in my example so you could see I was referencing a table, you should call it something like schoolzones or zones or even areas its up to you.

Link to comment
Share on other sites

Still a no go

 

CREATE Table hotspot (
id int(11) NOT NULL,
zone varchar(30) NOT NULL,
bullcount varchar(1000) NOT NULL,
KEY (ID)
)";

 

<?php 
if (isset($id)) 
{ 
   $sql="SELECT * FROM `hotspot` WHERE id=$id"; //Select every thing from 'hotspot' table
   $query=mysql_query($sql);
   $row=mysql_fetch_array($query);
   $name=$row[zone];// Zone area
   $value=$row[bullcount];// counts of bullys
   $newvalue=$value+1;
   $sql="UPDATE `hotspot` SET value='$newvalue' WHERE id=$id"; //updates counts of bullys by +1
   $query=mysql_query($sql);
   echo "$newvalue incidents in area $name"; //Prints new total count and area name.
} 
else 
{ 
   die("Error:$id not updated"); //Prints error 
}
?>

 

Just prints

Error: not updated

Link to comment
Share on other sites

nope  :( not understand, no error are coming up.

 

<?php 
if (isset($id)) 
{ 
   $sql="SELECT * FROM 'hotspot' WHERE id=$id"; //Select every thing from 'hotspot' table
   $query=mysql_query($sql);
   $row=mysql_fetch_array($query);
   $name=$row['zone'];// Zone area
   $value=$row['bullcount'];// counts of bullys
   $newvalue=$value+1;
   $sql="UPDATE 'hotspot' SET bullcount='$newvalue' WHERE id=$id"; //updates counts of bullys by +1
   $query=mysql_query($sql);
   echo "$newvalue incidents in area $name"; //Prints new total count and area name.
} 
else 
{ 
   die("Error:$id not updated"); //Prints error 
}
?>

Link to comment
Share on other sites

do you have data in your database?

do the id numbers in the database match the id numbers you are sending from your hotspot?

also the bullcount feild in your database is not right, the number you set in the the brackets there, 1000 is way to big, that means it can be 1000 characters not the number 1000, you should set as int(10) for that column, which means an integer upto 10 characters long which would mean you can count upto 999999999 which i dont beleive you will ever reach.

Also take the ' away from the table name, this should only be hotspot not 'hotspot' in both of your sql queries, as $id in your queries is a variable I would also make it '$id" to prevent SQL injection attacks.

also you set key as ID when in fact it is id, check your variable for case sensitivity

 

also just above the if (isset($id)), add this

 

echo "ID is ($id).";

 

if you dont get a number at the top of your page between the brackets, then you are not sending the variable id right

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.