search
HomeBackend DevelopmentPHP Tutorial这个页面总是出现这个问题怎么回事?

这个页面就是类似贴吧的从帖子列表点进去后某个帖子的主页  回复是提交到本页的   遇到下面两个问题了 大家帮我看看谢谢
form表单


    

     
     
      
      
  

  

下面是插入语句
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
 $stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");
 $stnt->execute($_POST);
这两个代码都是写在一个页面的  页面出现两个问题  我提交表单后这个输入框里面的东西可以插入到数据库中  然后表单就会清空 但是我点击刷新页面后总是有一个提示框   就是下面这个图片的内容  如果我点击继续后刚才已经提交的数据就会再插入一遍到数据库中  而且我换别的浏览器刷新页面也是提示这个框  这是第一个问题 
  

第二个问题是从帖子列表点击进这个帖子后就显示报错了 因为上面这个代码还没有往数据库里面插入数据呢 没有产生POST的值  如果插入数据后这个报错就消失了  但是每次点进帖子还是会报错啊  因为是提交到本页的回复所以没有写action  但是我还是试着这样写了一个if判断   但是不对啊  不报错了但是提交数据后也插入不到数据库里面了   这个问题该怎么解决呢
if(isset($_GET['reid'])
{
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
 $stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");
 $stnt->execute($_POST);
}


回复讨论(解决方案)

1.刷新页面的时候会把$_POST里面的内容也带上。所以刷新等于一次重复的表单提
2.判断应该是判断$_POST['reid'],而不是$_GET

1.刷新页面的时候会把$_POST里面的内容也带上。所以刷新等于一次重复的表单提
2.判断应该是判断$_POST['reid'],而不是$_GET


第二个问题我改了一下  已经没问题了    那么第一个问题怎么解决呢?

第一个问题可以通过这个方法解决:

将真正的处理数据部分放到一个单独的文件中进行,处理完毕redirect回显示页面。

第一个问题可以通过这个方法解决:

将真正的处理数据部分放到一个单独的文件中进行,处理完毕redirect回显示页面。



你是说把插入的数据的代码的那一段另写一个文件是吗 插入完成后再跳转回来  是这样的吧   但是跳转回来的那个地址了的POST值怎么办呢   你再看一下我昨天提问的另一个帖子 
http://bbs.csdn.net/topics/391903553   这个代码比较完整    我上面的代码这样就是为了省略那个提交的post值所以才提交到本页的   但是现在又要改回回去   那个post值怎么办呢?

“那个POST值”是什么意思?你需要在插入数据成功之后,回到的页面再次显示这些数值?如果是这样,我建议你回到先前页面的时候带一个该记录的ID,然后用数据库查询的方式把这个纪录拿回来,再把字段赋值给表单。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)