dynamic form problem???

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

dynamic form problem???

Post by vin_akleh »

every time i click on any of the 5 images or submit button from
<input type="hidden" name="select" value="'.$url["link"].'" >
gives me the value of select the same value, which is the last value which is the fifth

Code: Select all

<?php
    $qu=mysql_query("select * from lnk order by link desc limit 5");
    while ($url=mysql_fetch_array($qu))
    {
        if ($url['im']=='') 
            $url['im']='images/default.jpg';
        echo '<td><table class=media><tr><td>
            <input type="image" src="'.$url['im'].'" width=150 height= 200/>
            <input type="hidden" name="select" value="'.$url["link"].'" >
            </a></td></tr><tr>';
        if (strlen($url["tit"])>16)
            $url["tit"]=substr($url["tit"],0,16).'...';
    echo '<td><input type="submit" value="'.$url["tit"].'" class="trans2"></td></tr></table></td>';
    }//end while
?>
example: if the last $url["link"] value was 30 then by clicking on any of the images or the submits it will give me the value of

Code: Select all

extract($_POST);
echo ".$select.";
is 30 and not the one i clicked on
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: dynamic form problem???

Post by AbraCadaver »

Image inputs are submit buttons so they submit the entire form. If you have 10 hidden inputs with the same name "select" then only the last one is populated in the $_POST array. I think I see the direction you're going and it's the wrong direction. You would probably be better off not using a form, but using a regular image and wrapping it in an anchor:

Code: Select all

'<a href="your_script.php?select="'.$url["link"].'">
    <img src="'.$url['im'].'" width="150" height="200" />
</a>' 
Then in your_script.php use the $_GET['select']
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

Re: dynamic form problem???

Post by vin_akleh »

thanks ill try that
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

Re: dynamic form problem???

Post by vin_akleh »

i did try it, this

Code: Select all

<a href="selection.php?select=abc"><img src="'.$url['im'].'" width="150" height="200" /></a>';
worked but these didnt

Code: Select all

<a href="selection.php?select="'.$url['link'].'"><img src="'.$url['im'].'" width="150" height="200" /></a>';
<a href="selection.php?select="'.$url['link'].'""><img src="'.$url['im'].'" width="150" height="200" /></a>';
<a href="selection.php?select='.$url['link'].'"><img src="'.$url['im'].'" width="150" height="200" /></a>';
and others
!!!!?????? :?: :!:
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

Re: dynamic form problem???

Post by vin_akleh »

any other sudgestions
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: dynamic form problem???

Post by jackpf »

Can you elaborate on "didn't work".
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

Re: dynamic form problem???

Post by vin_akleh »

jackpf wrote:Can you elaborate on "didn't work".
when i tried to echo select when it was abc, it did echo it
but the other three and more i have tried, didnt echo anything
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: dynamic form problem???

Post by jackpf »

What is the displayed url of the link?

And what does

Code: Select all

print_r($_GET);
display?
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

Re: dynamic form problem???

Post by vin_akleh »

jackpf wrote:What is the displayed url of the link?

And what does

Code: Select all

print_r($_GET);
display?
this:

Code: Select all

<a href="selection.php?select="'.$maxurl['image'].'"">
outs:
Array ( [select] => )
this:

Code: Select all

<a href="selection.php?select='.$maxurl['image'].'">
outs:
Array ( [select] => images/default.jpg )
i am guessing that the second one doesn't have any problem, if not
is this any wrong:

Code: Select all

$qu = mysql_query("select * from lin where link like '".$_GET["select"]."'");
?? :?: :?:
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: dynamic form problem???

Post by AbraCadaver »

Why don't you post your entire code again since it bears no resemblance in var names or anything else to what you posted earlier.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

Re: dynamic form problem???

Post by vin_akleh »

assume that the variable names are right, is the syntax right??
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: dynamic form problem???

Post by AbraCadaver »

vin_akleh wrote:assume that the variable names are right, is the syntax right??
I suppose. Just that if $maxurl['image'] in the link doesn't contain a value, then $_GET['select'] on the next page won't either.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: dynamic form problem???

Post by jackpf »

I meant what is generated, not the code generating it.

Just wondering why on one of the links you have two double quotes at the end.
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

Re: dynamic form problem???

Post by vin_akleh »

jackpf wrote:I meant what is generated, not the code generating it.

Just wondering why on one of the links you have two double quotes at the end.
this one:

Code: Select all

1.<a href="selection.php?select="'.$maxurl['image'].'"">
one for the href and the other is for the "'.$maxurl['image'].'"
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: dynamic form problem???

Post by jackpf »

That's not the generated url. That's not what shows up in the browser.
Post Reply