Questions about repeated page refresh submission and isset

Source: Internet
Author: User
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;

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.