Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:56:37+00:00 2026-05-26T17:56:37+00:00

I have a page that I use AJAX to save some data in a

  • 0

I have a page that I use AJAX to save some data in a DB. As below, when I click on the button, it posts data to add-to-db.php

My problem is that I used numbers instead of values for my testings and worked. Now that I have to make use of variables it does not.
I guess I have to post the values of $dealid and $myid but how can I do this?

Thank you.

in my product.php I have this

<script>
$(function(){
    $("#JqPostForm").submit(function(e){
       e.preventDefault();   

        $.post("add-to-db.php",
        function(data){

            $("#message_post").html("Thank you");


        });
    });

});
</script>

$dealid = (int)$_GET["id"];
$myid = $_SESSION['SESS_MEMBER_ID'];

and in the add-to-db.php I have this query but it does not save in DB

$query = "INSERT INTO reverse_relations (user_id, product_id, ip) VALUES ('$_SESSION['SESS_MEMBER_ID']', '$dealid', '$_SERVER[REMOTE_ADDR]')";

however when I added VALUES ('1', '2', '$_SERVER[REMOTE_ADDR]')"; it worked

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:56:37+00:00Added an answer on May 26, 2026 at 5:56 pm

    First, the variables in the form on product.php need to be sent to add-to-db.php. Right now, no variables are being sent, because none are specified in your $.post() call. To do this, you can:

    $.post("add-to-db.php", $("#myform").serialize(), function (data){
       $("#message_post").html("Thank you");
    });
    

    Once you send the variables off to add-to-db.php, you can read them by accessing the $_POST array, assuming you have register_globals OFF in php.ini, and your field is called dealid

    $query = "INSERT INTO reverse_relations (user_id, product_id, ip) VALUES ('$_SESSION['SESS_MEMBER_ID']', '".$_POST['dealid']."', '$_SERVER[REMOTE_ADDR]')";
    

    However – do not use this code. You must santize all POST and should sanitize SESSION and SERVER variables in your queries, or you risk the safety of your website.

    $dealid = mysql_real_escape_string($_POST['dealid']);
    $sessid = mysql_real_escape_string($_SESSION['SESS_MEMBER_ID']);
    

    Then use these variables instead in your SQL query:

    $query = "INSERT INTO reverse_relations (user_id, product_id, ip) VALUES ('{$sessid}', '{$dealid}', '$_SERVER[REMOTE_ADDR]')";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webforms page that makes quite extensive use of AJAX. There are
I have a web page that I use to update a fairly complex data
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity
I have a function that I use on index.php page and I would like
I have a form on a page that sends data to php file via
I have a page layout that I use in my SharePoint solution when I
Okay, my dilemma is this. I have an admin page that I use to
I have a timed page that I need to use to submit a form
I have a simple django page that has a counter on it. I use
I have an ASP.NET 3.5 page with some AJAX, some Validators and some business-rule

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.