Home > Backend Development > PHP Tutorial > 如何在php中模拟点击按钮

如何在php中模拟点击按钮

不言
Release: 2023-02-28 17:24:02
Original
5785 people have browsed it

本篇文章主要给大家介绍关于如何在PHP中模拟点击提交按钮。下面我们通过具体例子来介绍。

一段代码如下:

<?php  
 session_start();  
  
 require("config.php");  
  
 $db = mysql_connect($dbhost, $dbuser, $dbpassword);  
 mysql_select_db($dbdatabase, $db);  
  
 if($_POST[&#39;submit&#39;]!=""){  
 $username=$_SESSION[username];  
 $city=$_POST[city];  
 $attraction=$_POST[attraction];  
 $imageNum=$_POST[number];  
 $relevance=$_POST[relevance];  
 $sql = "Insert Into vote (username,city,attraction,imageNum,relevance,dateposted) Values(&#39;$username&#39;,&#39;$city&#39;,&#39;$attraction&#39;,&#39;$imageNum&#39;,&#39;$relevance&#39;,NOW())"; 
 $result=mysql_query($sql);  
 echo "";  
 echo "";  
 }  
 ?>
Copy after login

如果我们在上述代码的基础下,想要实现每次评价成功后自动跳到下一张图片的功能即模拟点击下“addButton ”(addButton的功能就是跳到下一张图片)

这种功能该如何实现呢?解决办法如下两点:

1、弹出提示框,然后自动跳转到指定页面,即重定向:

function alertInfor($infor = false, $href = false) {echo <<SCRIPT;}alertInfor("评价成功","next.html");
Copy after login

2、弹出提示框,然后执行js脚本更换图片:将你的addButton函数内容替换掉alert的下一句就行了。不过这段代码必须和你的页面js在同一页面。

本篇文章具有一定的参考价值,希望对有需要的朋友有所帮助。

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template