是否可以使用onsubmitJavaScript 从PHP调用函数?如果是这样,有人能给我一个如何做的例子吗?
function addOrder(){
$con = mysql_connect("localhost", "146687", "password");
if(!$con){
die('Could not connect: ' . mysql_error())
}
$sql = "INSERT INTO orders ((user, 1st row, 2nd row, 3rd row, 4th row)
VALUES ($session->username,1st variable, 2nd variable, 3rd variable, 4th variable))";
mysql_query($sql,$con)
if(mysql_query($sql,$con)){
echo "Your order has been added";
}else{
echo "There was an error adding your order to the databse: " . mysql_error();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我想要打电话的功能.它是一个订购系统,您输入您想要的每件商品的数量,点击提交,它应该将订单添加到表中.
我有一个带有以下js函数的index.php:
function returnImageString() {
return "<?php include 'inc/image.functions.php'; echo getRandomImages(7); ?>"; //This isn't dynamic; this will always return the same images. How do I fix this?
}
Run Code Online (Sandbox Code Playgroud)
但是,当页面加载时,调用php脚本并将结果添加到源代码中,如下所示:
function returnImageString() {
return "images/20.11.A1B9.jpg|images/8.14.47683.jpg|images/19.10.FBB9.jpg|images/21.12.9A.jpg|images/8.11.1474937909.jpg|images/8.15.99404.jpg|images/8.10.jpg|"; //This isn't dynamic; this will always return the same images. How do I fix this?
}
Run Code Online (Sandbox Code Playgroud)
我想要发生的是每当我调用js函数(returnImageString)时,我希望它每次调用php函数(因为php函数返回一串随机图像位置),而不是在js函数中对字符串进行硬编码.
有人能指出我正确的方向吗?谢谢!