Questions about repeated page refresh submission and isset & lt; formaction & lt ;? Php $ _ SERVER [PHP_SELF]? & Gt; methodpost & gt; Picture: & lt; inputtype & quot; text & quot; id & quot; appimg & quot; name & quot; img & quot; & Questions about repeated page refresh submission and isset
If ($ _ SERVER ['request _ method'] = 'post '){
If (isset ($ _ POST ['IMG ']) & isset ($ _ POST ['URL'])
{
$ Img = $ _ POST ['IMG '];
$ Url = $ _ POST ['URL'];
$ Query = sprintf ('Insert INTO pic (pic, url )'.
'Values ("% s", "% s") ', $ img, $ url );
If (! $ Result = mysql_query ($ query ))
{
Die ('could not insert into the database: '. mysql_error ());
}
}
}
?>
If (isset ($ _ POST ['IMG ']) & isset ($ _ POST ['URL']) is this statement incorrect?
In addition, to prevent repeated refresh and submission, please help me change the code !!!!
------ Solution --------------------
Session_start ();
If ($ _ SERVER ['request _ method'] = 'post '){
If ($ _ POST ['token']! = $ _ SESSION ['token'])
{
Die ('token mismatch ');
}
Unset ($ _ SESSION ['token']);
If ($ _ POST ['IMG '] & $ _ POST ['URL'])
{
$ Img = $ _ POST ['IMG '];
$ Url = $ _ POST ['URL'];
$ Query = sprintf ('Insert INTO pic (pic, url )'.
'Values ("% s", "% s") ', $ img, $ url );
If (! $ Result = mysql_query ($ query ))
{
Die ('could not insert into the database: '. mysql_error ());
}
}
}
$ Token = md5 (mt_rand (0, 65535 ));
$ _ SESSION ['token'] = $ token;
?>