简单的html按钮,用于从页面获取数据并同时将数据保存在数据库中

问题描述 投票:-1回答:2

我正在使用PHP_Storm,我正在建立一个网站,我需要在其中添加购物车选项。

我想要的是一个简单的按钮,以获取特定分类reference( reference ( $this->reference = bin2hex(openssl_random_pseudo_bytes(10)).time();)已经在网页中声明,我可以将其指定为按钮的值)并将该数据保存为实体cart中的字符串。 JS或AJAX或其他任何可能的方式。你们能帮助我吗?

php html
2个回答
0
投票

使用AJAX来做到这一点,

 $.ajax({
    url:'store-data-url',
    type:'post;
    data:{
    //data-to-store
    },
    success: function(response){
    //get response 
    console.log(response);
    },
    error:function(error){
    //get error
    console.log(error);
    }

这是如此简单,希望它有所帮助


0
投票

将PHP变量从浏览器发送到服务器的简单方法:

<form action="..." method="post">
  <input type="hidden" name="value" value="<?php echo $this->reference ?>" />
  <input type="submit">
</form>

在服务器上,您必须将$_REQUEST['value']的值存储到数据库中。

© www.soinside.com 2019 - 2024. All rights reserved.