gpt4 book ai didi

php - 从ajax获取数据并发送到mysql

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:57 24 4
gpt4 key购买 nike

我有简单的ajax代码:

function showMe(data) {
$("body").append();
if(data.success == true) {
$("body").append("<img src="+data.data.link+" height=180 /><br /><a href="+data.data.link+">"+data.data.link+"</a>");

$.ajax ({
type: "POST",
url: "sql.php",
data: "y=+data.data.link+",
});

我需要获取“+data.data.link+”值并发送到 mysql 数据库,但它发送的是 data.data.link 而不是真正的链接。如何获得真正的值(value)并发送到数据库?这是 sql.php:

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include("$phpbb_root_path/includes/functions_user.php");
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewtopic');

include "forum/config.php";
$link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd");
$db_selected = mysql_select_db("$dbname", $link);

$y = @$_POST['y'];

$date = date('d.m.y');
$name = $user->data['username'];

mysql_query("INSERT INTO `gallery` (name, createdate, piclink) VALUES('$name', '$date', '".$y."')");

unlink("gallery/$imagename");
?>

感谢您的帮助:)

最佳答案

将数据作为对象(干净且可读)而不是字符串发送..

试试这个

 data: {'y':data.data.link},

关于php - 从ajax获取数据并发送到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19494601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com