Forum Moderators: coopster

Message Too Old, No Replies

Isset problems

trying to use isset without submit btn in menu

         

Greywolf1964

10:55 am on May 31, 2009 (gmt 0)

10+ Year Member



Hi - I am trying to make a simple menu using if(isset($_POST['something'])){
It works fine if I use <form method="post" action="page.php">
<input type="submit" name="something" value="Something."></form>. But instead of using the submit button I would like to use a txtstring as I would do in: <a href="page.php">PAGE</a>.

Appreciate your help and time.

jkovar

2:33 pm on May 31, 2009 (gmt 0)

10+ Year Member



isset($_GET['something'])

<a href="page.php?something=1">

rocknbil

4:01 pm on May 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard Greywolf1964, the explanation of the above is that query strings and a form without an explicit method="post" are sent in the method GET.

<form action="somescript"> = GET
<a href="somescript"> = GET

In PHP you can access either, if you don't know what they will be, via $_REQUEST.

Google for get and post methods so you know them, as there are reasons to use both. Get has two peculiarities. One, there is a limitation in size that can be sent and received, and two, it will show up in the address bar as a query string.

somescript.php?var1=1&var2=2&var3=3

Greywolf1964

4:18 pm on May 31, 2009 (gmt 0)

10+ Year Member



Thank's both of you - but I still can't make it work.

In my menu I write:
<form action="main.php" method="get"><a href="main.php?mini7=1">miniputt: 8 &aring;r</a></form>

In main.php I write:
if isset($_GET['mini7']){
$result = mysql_query(" SELECT * FROM `undersider` WHERE `super_avdeling` = 'SMÅGUTT: 7 ÅR' LIMIT 0 , 30 ");
while($myrow = mysql_fetch_array($result))
{
echo '<p><span class=overskrift>'.$myrow['overskrift'] . '&nbsp;(' . $myrow['dato'] . ')';
echo '</span>';
echo '<p class=ingress>'. $myrow['ingress'];
echo '<p class=tekst><img src=' . $myrow['bilde'] . ' align=left vspace=10 hspace=5 width=300>' . $myrow['tekst'];
}
}else{
echo 'feil';
}

I'm trying to put together a web-page for our local soccerteam for kids.

rocknbil

5:55 pm on May 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In my menu I write:
<form action="main.php" method="get"><a href="main.php?mini7=1">miniputt: 8 &aring;r</a></form>

The form is not needed.
<a href="main.php?mini7=1">miniputt: 8 &aring;r</a>

if (isset($_GET['mini7']) and preg_match('/^\d+$/',$_GET['mini7'])){
// The preg_match insures it's nothing but a number.
// Other ways to do it ....
$result = mysql_query(" SELECT * FROM `undersider` WHERE `super_avdeling` = '$_GET['mini7']' LIMIT 0 , 30 ");
..........
}

if you're storing your data as plain text, this is going to be a never ending nightmare:

`super_avdeling` = 'SMÅGUTT: 7 ÅR'

This should be an integer field, like


table undersider
id....¦.........title........¦....super_avdeling....¦
1.....¦.miniputt: 8 &aring;r.¦...1..................¦

Previous for example only, but this is the idea. Searching on integer fields will always be faster and simplifies the task. It also simplifies security issues too, as in the simple preg_match above. That field will never accept anything but integer numbers as described. If it accepts textual input you have to take another more complex approach.

Greywolf1964

9:20 pm on May 31, 2009 (gmt 0)

10+ Year Member



Finally it worked :o)
Thank's a lot for help - thank's for the advise off using int in super_avdeling - much easier to controll it. Hope I soon get the time really start learning .php