/    Sign up×
Community /Pin to ProfileBookmark

Problem in retriving datasfromdatabase using link in image

Hi,

I am trying to retriving some datas from the database.using submit button i am getting result but i inserted one submit image and i gave link to that image and then i run that script but its not working now.Can any one tell me using link how to retrive the datas.

here i pasted my script

———————search.php————–

[COLOR=”Blue”]<form name=”form1″ method=”get”>
<table width=”200″ border=”1″>
<tr>
<td><input name=”event” type=”text”>&nbsp;</td>
<td><a href=”country,php”> <img src=”go.gif”></a></td>
</tr>
</table>
</form>[/COLOR]

—–coutry.php————————–

[COLOR=”Blue”]<form name=”form1″ method=”get”>
<?php
// error_reporting(E_ALL);
//ini_set(‘display_errors’, True);
include(‘connect.php’);

$sql=”SELECT subject FROM addevent WHERE event =’$_GET[event]'”;
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);

while($rows=mysql_fetch_assoc($result))
{
// Start looping table row
?>
<?PHP
echo “Details about ‘$_GET[event]'”;?>
<table width=”900″ border=”0″ align=”center”>
<div align=”center”><b>Search Details</b></div>
<tr bgcolor=”#E1E1E1″ >
<td width=”194″>Subject</td>
</tr></table>
<?php

print “<tr bgcolor=”#CCCCCC”>

<td bgcolor=”#FFFFFF”>” . $rows[‘subject’] . “</td>
</tr>”;

// Exit looping and close connection

}
mysql_close();
?>

</form>[/COLOR]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@chestertbJul 21.2007 — First, your search form script doesn't submit. The <a>..</a> tag doesn't submit a form, it simply links to another location. To submit a form, you need to either use a submit button or use javascript (which isn't necessary here).

It needs to be
[code=html]<form name="form1" action='country.php' method="get">
<table width="200" border="1">
<tr>
<td><input name="event" type="text">&nbsp;</td>
<td><button type='submit'><img src="go.gif"></button></td>
</tr>
</table>
</form>[/code]


And in country.php, your array index needs to be quote enclosed...

[code=php]$selected = $_GET['event'];
$sql="SELECT subject FROM addevent WHERE event ='$selected";[/code]


And is there a reason why you've created a form in country.php? In the code provided, this isn't needed.

CTB
Copy linkTweet thisAlerts:
@kavithadevanauthorJul 21.2007 — Hi,

i dont want to give link in action page because i have two links so if i gave action it goes to same page only so i feel in this script link is better compared to action.Actually my script was working with single(if i give action to single page) but i have two search conditions one is country.php and another one is state.php so if i click country name image it goes the contry.php and if i click state image then it goes to state.php actually link is working but code is not working wen i use link if i use submit its working now help me how i give link for this script

thanks


First, your search form script doesn't submit. The <a>..</a> tag doesn't submit a form, it simply links to another location. To submit a form, you need to either use a submit button or use javascript (which isn't necessary here).

It needs to be
[code=html]<form name="form1" action='country.php' method="get">
<table width="200" border="1">
<tr>
<td><input name="event" type="text">&nbsp;</td>
<td><button type='submit'><img src="go.gif"></button></td>
</tr>
</table>
</form>[/code]


And in country.php, your array index needs to be quote enclosed...

[code=php]$selected = $_GET['event'];
$sql="SELECT subject FROM addevent WHERE event ='$selected";[/code]


And is there a reason why you've created a form in country.php? In the code provided, this isn't needed.

CTB[/QUOTE]
Copy linkTweet thisAlerts:
@chestertbJul 22.2007 — a couple of solutions...

first, why differentiate at all? Are there states in the world that have the same name as a country? Just let your user enter a state or country, and have your php figure it out by first looking for the entry as a country, and, if not found, treating it as a state. (There are plentry of places on the web from where you can download a list of coutnries.)

if you want to differentiate and have two scripts handle the search, then you're stuck with either using two data entry boxes... one for country and one for state... with two different forms

or

you could have an intermediary script, which receives the data, decides whether it's country or state, then submits the data to country.php or state.php, or, better still, just includes country.php or state.php (which would be a very clean solution)

or

to achieve EXACTLY the effect you're looking for, you could use javascript, in which case, you'd have three forms... one visible into which your user enters data, and two hidden, with a javascript call determining which is submitted. something like this...

[code=html]<head>
<script language='javascript'>
function submitit(where)
{
what = document.getElementById('entry').value;
if(where=="s")
{
document.getElementById('state').value = what;
formstate.submit();
}
else
{
document.getElementById('country').value = what;
formcountry.submit();
}
}
</script>
</head>
<body>
<form>
<input type='text' name='what' id='what'>
<a href="javascript:submitit('s')"><img src='stateimage.jpg'></a>
<a href="javascript:submitit('c')"><img src='countryimage.jpg'></a>
</form>
<form action='state.php' name='formstate' id='formstate' method='post'>
<input type='hidden' name='state' id='state'>
</form>
<form action='country.php' name='formcountry' id='formcountry' method='post'>
<input type='hidden' name='country' id='country'>
</form>
</body>[/code]

CTB
×

Success!

Help @kavithadevan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...