0

I have simple ajax code:

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+",
});

i need to get '+data.data.link+' value and send to mysql db, but it sends data.data.link and not real link. How to get real value and send to db ? Here is 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");
?>

Thanks for any help :)

1
  • You'll need to show the response of sql.php Commented Oct 21, 2013 at 12:32

2 Answers 2

3

send data as object (clean and readable) and not string..

try this

 data: {'y':data.data.link},
Sign up to request clarification or add additional context in comments.

1 Comment

cool..welcome... glad it helped.. happy coding..looks like you haven't accepted answer from any of your question... please accetp as answer if it helped .. for your other questions too
0

You didn't reveal where "data.data.link" comes from, but the major problem is within the ajax code:

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

The reference to the variable (data.data.link) must not be in quotes to be evaluated.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.