News:

Wondering if this will always be free?  See why free is better.

Main Menu

passing form variables to a function

Started by jami, August 28, 2003, 06:14:44 PM

Previous topic - Next topic

jami

having this piece of crap code in a function:
echo '<table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor="#6394bd">
                 <tr><td class="titlebg"><strong>&middot; Inserimento Quiz</strong>
                 </td>
                 </tr>
                 <tr>
                   <td valign="top" class="windowbg2"> <form method="post" action="'.$boardurl.'?action=quizc">
                       <p align="center"><b>Nome del Quiz</b></p>
                       <p align="center">
                         <input name="name" type="text" size="70" />
                    </p>
                     <p align="center"><b>Autore</b></p><input type="hidden" name="creator" value="'.$username.'" />
                     <p align="center"><a href="$boardurl/index.php?action=quizd;nome='.$username.'">'.$username.'</a></p>
                    <p align="center"><b>Aggiunto il</b></p><input type="hidden" name="inserimento" value="'.gmstrftime("%d %B  %Y, %I:%M:%S", time()+$timeoffset*3600).'" />
                   <p align="center">'.gmstrftime("%d %B  %Y, %I:%M:%S", time()+$timeoffset*3600).'</p>
                   <p align="center"><b>Descrizione del Quiz</b></p>
                   <p align="center">
                        <textarea name="description" cols="70" rows="8"></textarea>
                     </p>
                      <p align="center">
                            <input type="submit" name="Submit" value="Inserisci" />
                    </p>
                     </form></td>
                 </tr>
                 <tr>
                   <td bgcolor="#DEE7EF">
                   <img src="'.$imagesdir.'/quiz.gif" align="absmiddle">&nbsp<a href="'.$boardurl.'/index.php?action=quiz">Pagina Principale dei Quiz</a>
                   </td>
                 </tr>
              </table>';


how to pass the variables name, creator, inserimento and description ?

$title=$_GET['name']; or $title=$_POST['name']; or $_GLOBALS

I can't get it to work ... che somaro.

Aquilo

function something(){
global $name, $creator, $inserimento, $description;

echo $name.$creator.$inserimento.$description;
}

make them global. declare them as global

Haase

You should be able to get it to work just by using $_POST['name'], etc. in the code on the next page.  I'm not sure why it's not working though...

But on another note (probably not related), you should probably give your form a name.<form method="post" name="the_form_name" action="'.$boardurl.'?action=quizc">
Particulary if there is more than one form on the page.
Find out about Enigma, the portal built exclusively for YaBB SE will be continuing it's work towards SMF

jami

#3
I've resolved the problem writing 2 function:

in the the first function there's the form with input name="namevar" and as action the second function

in the second function there's no global var declared, only $_POST[namevar] passed to the insert query.

and it works  ;).

add: I think code fontsize can be greater ( 9px?)

chris

Quote from: jami on August 29, 2003, 12:54:45 PM
in the second function there's no global var declared, only $_POST[namevar] passed to the insert query.

You're meaning addslashes($_POST[namevar]) is passed to the insert-query, right? Passing Variables without escaping ' and " would be stupid....

jami

#5
mysql_query("INSERT INTO {$db_prefix}quizz_sets (name,description,creator,inserimento) VALUES ('".$_POST[titolo]."', '".$_POST[descrizione]."', '".$_POST[creatore]."', '".$_POST[inserimento]."')");

:o

works.

:o

Aquilo

$HTTP_ ***_VARS or any $_POST $_GET $_REQUEST   these are already global in normal php environment??

I use $_REQUEST allot and have never made a function that would automatically bring $HTTP_ ***_VARS into a function :-\
even YaBBSE declares "global $HTTP_POST_VARS" in functions.

how are you getting this to insert anything other then empty variables??

function RealFunction() {
mysql_query("INSERT INTO {$db_prefix}quizz_sets (name,description,creator,inserimento) VALUES ('".$_POST[titolo]."', '".$_POST[descrizione]."', '".$_POST[creatore]."', '".$_POST[inserimento]."')");
}


I'm missing something!

[Unknown]

$_POST is a super global.  It is always there, in any function.

$HTTP_POST_VARS is *not* a super global, and is NOT supposed to eb used anymore :P.

-[Unknown]

Aquilo

so $_POST $_GET and $_REQUEST are all super globals?

[Unknown]

Pretty much all the builtin ones that start with $_ are.  Those and $GLOBALS.

-[Unknown]

Advertisement: