Jump to content
Science Forums

PHP and Forms


Recommended Posts

I cannot get this to work. I adapted a working script that used radio buttons or checkboxes to output data. I used the radio buttons on the same table and was able to output the data.

 

When I converted to a textbox on the form to search for specific birds is where I began to run into issues. I do not know what I am doing wrong.

 

//connection stuff

$tag_id = $_GET['tag_id'];
if (isset($_GET['tag_id']))
{
$tag_a=htmlentities($tag_id, ENT_QUOTES);
{
$query = "SELECT * 
FROM swanLocationTable
WHERE (`tag_id` LIKE '%tag_a%')
ORDER BY org_site,loc_id";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$num=mysql_numrows($result);

?>

<table border="0" cellspacing="2" cellpadding="0">
<h4> <? echo "$org_site"; ?> </h4>
<tr> <th width="10">Swan</th>  <th width="10">Born</th><th width="15">Date</th><th width="10">Year</th><th width="30">Location</th><th width="10">Lat</th><th width="10">Lon</th><th width="10">Loc ID</th><th width="10"> </th>
</tr>

<?
$i=0;
while ($i < $num) {
$Swan=mysql_result($result,$i,"tag_id");
$Date=mysql_result($result,$i,"date");
$Year=mysql_result($result,$i,"year");
$Locate=mysql_result($result,$i,"loc");
$Latitude=mysql_result($result,$i,"lat");
$Longitude=mysql_result($result,$i,"lon");
$LocationID=mysql_result($result,$i,"loc_id");
?>
<tr>
<td width="10"><? echo "$Swan"; ?></td>
<td width="15"><? echo "$Date"; ?></td>
<td width="10"><? echo "$Year"; ?></td>
<td width="30"><? echo "$Location"; ?></td>
<td width="10"><? echo "$Latitude"; ?></td>
<td width="10"><? echo "$Longitude"; ?></td>
<td width="10"><? echo "$LocationID"; ?></td>
</tr>
<?
++$i;
}
echo "</table>";
}
}

mysql_close();
?>
<center><form name="swanLoc" method="_GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
<p>Choose Swan Location</p>

<input type="text" name="tag_id" size="4"> 
<input class="Swan" type="submit" name="submit" value="Swan Search">

</form> </center>

 

The foreach in the original form thru an invalid argument error.

 

As the above is now, it runs thru ok but returns no results when I know the entry in the form exists, with several entries.

 

Oh, as a note, the working radio button form version also worked correctly with a join.

 

So why wont the text input work? It has to be that issue and the number of swans is too large for a drop down option.

 

Any suggestions?

 

Thanks in advance.

Link to comment
Share on other sites

why exactly would tag id be an array?

 

Well, its for the swan ID. The ones we are most interested in are the release birds. Its their ID point and for this table they can have multiple entries for location sightings.

 

As far as whether it really needed to be there, I havent a clue. The query worked after I added it (the []) and increased the text box size (which didnt make sense either as each swan tag is a max of 4 places).

 

:)

 

I am still struggling with it, as it wont let me do any input. I am gonna read some more and try to puzzle over it and see if I can figure it out.

 

Go ahead and laugh at my sloppy (but hey it works) 1st post. I am a beginner and it does show.

Link to comment
Share on other sites

  • 2 weeks later...

OK this is based on the same thing as post one, but edited down to where I think the problem lies:

 

if (isset($_GET['swan'])) 
{
foreach ($_GET['swan'] as $bird)
{
$swan_id=htmlentities($bird);
//100
{
$query = "SELECT * 
FROM SwanLoc JOIN SwanID ON SwanLoc.tag_id=SwanID.tag_i WHERE (`tag_id` LIKE '$swan_id') ORDER BY org_site, loc_id";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$num=mysql_numrows($result);
?>
<h4> <? echo "$swan_id"; ?> </h4>
<h3><? echo "$born"; ?> </h3>
<h3><? echo "$mate"; ?></h3>
<table border="0" cellspacing="2" cellpadding="0">

 

I know the join works because the table output displays the born and mate info in the table in each row even though there is only one entry for born and mate in Swan ID.

 

What I want to do (and cannot) is get the individual swan info to display outside of the incrementing table. The above h4 tag works but the swan ID is also the query input and is brought to this via the submit.

 

the h3 data does not display but it does display in the incrementing table (from post 1). I dont need or want it to display more than once, its not needed.

 

What am I doing wrong or how do I fix this to isolate single entry data from incrementing data?

 

Thanks!

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...