这个页面总是出现这个问题怎么回事?
这个页面就是类似贴吧的从帖子列表点进去后某个帖子的主页 回复是提交到本页的 遇到下面两个问题了 大家帮我看看谢谢
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,然后用数据库查询的方式把这个纪录拿回来,再把字段赋值给表单。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
