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 7002723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:57:54+00:00 2026-05-27T20:57:54+00:00

I am trying to execute two sql statements in a row. EDIT:Only the first

  • 0

I am trying to execute two sql statements in a row. EDIT:Only the first textbox “boxes” posts correctly. It seems that the 3 other variables, bubbleWrap, studentAddress1, and studentAddress2 are all blank. Both SQL statements work in the mysql workbench.

The textboxes for studentAddress1 and studentAddress 2 are included in the same form as boxes and the bubblewrap (true/false) radio buttons. I can include the form if you would like, but it is pretty straightforward and basic.

AJAX:

$("#needEmptyBoxesForm").submit (function() {
    alert('click');
    boxes = $("#boxes").val();
    bubbleWrap = $("#bubbleWrap").val();
    studentAddress1 = $("#studentAddress1").val();
    studentAddress2 = $("#studentAddress2").val();

    $.post('needEmptyBoxesRequest.php', 'boxes=' + boxes + 'bubbleWrap=' + bubbleWrap + 'studentAddress1=' + studentAddress1 + 'studentAddress2=' + studentAddress2, function (response) {
    alert('post');
    $("#needEmptyBoxesRequestResults").html(response);
    alert (response);
    });
return false;
});

Processing page (php)

    else {
    $boxes = mysql_real_escape_string($_POST['boxes']);
    $bubbleWrap = mysql_real_escape_string($_POST['bubbleWrap']);
    $studentAddress1 = mysql_real_escape_string($_POST['studentAddress1']);
    $studentAddress2 = mysql_real_escape_string($_POST['studentAddress2']);

    $email = mysql_real_escape_string($_SESSION["email"]);
    $clientId = mysql_real_escape_string($_SESSION["clientId"]);

    $sql =  "INSERT INTO supplies (`clientId`, `boxesRequested`, `bubbleWrapRequested`)
                VALUES ('".$clientId."', '".$boxes."', '".$bubbleWrap."');";

    //set results to variables
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
        //in case query fails
        if (!$result) { 
            die("Database query failed: " . mysql_error()); 
        }

    $sql2 =     "UPDATE `clients` SET `studentAddress1`= '".$studentAddress1."',`studentAddress2`= '".$studentAddress2."' WHERE clientId = '".$clientId."';";

    //set results to variables
    $result2 = mysql_query($sql2);
    $row2 = mysql_fetch_array($result2);
        //in case query fails
        if (!$result2) { 
            die("Database query failed: " . mysql_error()); 
        }


    }

Form code:

echo
    '<form id = "needEmptyBoxesForm">
        <table class = "needEmptyBoxes1">
            <tr>
                <td>
                    <span class="buttonText">
                        Our free signature boxes are 24"x18"x16", and double-walled to protect your items.  How many boxes would you like delivered?
                    </span>
                </td>
            </tr>
            <tr>
                <td>
                    <input      type="text"
                                    class="boxRequestBlank"
                                    id="boxes"
                                    name="boxes">
                </td>
            </tr>
            <tr>
                <td>
                    <span class="buttonText">
                        Free tape will be delivered with the boxes.
                    </span>
                </td>
            </tr>
            <tr>
                <td>
                    <span class="buttonText">
                        Would you like to purchase bubble wrap for $5?
                    </span>
                </td>
            </tr>
            <tr>
                <td>
                    <input      type="radio"
                                    class="radioButton"
                                    name="bubbleWrap"
                                    value="1">
                        <span class="buttonText">
                            Yes
                        </span>
                    <input      type="radio"
                                    class="radioButton"
                                    name="bubbleWrap"
                                    value="0">
                        <span class="buttonText">
                            No
                        </span>
                </td>
                            </tr>
            <tr>
                <td>
                    <img        src="images/arrow.png"
                                    class="needEmptyBoxesFormForward1"
                                    id="needEmptyBoxesFormForward1">
                </td>
            </tr>
        </table>

        <table class = "needEmptyBoxes2">
            <tr>
                <td>
                    <span class="buttonText">
                        Please confirm  your address:
                    </span>
                </td>
            </tr>
            <tr>
                <td>';

                        $sql = "SELECT  A.studentAddress1, A.studentAddress2
                        FROM clients A
                        WHERE '".$_SESSION["email"]."' = A.studentEmail";

                include "databaseConnection.php";

                //Close connection 
                mysql_close($connection); 

                    echo
                    '<input
                                    type="text"
                                    class="needEmptyBoxesTextbox"
                                    name="studentAddress1"
                                    value="'.$row["studentAddress1"].'">
                    <input
                                    type="text"
                                    class="needEmptyBoxesTextbox"
                                    name="studentAddress2"
                                    value="'.$row["studentAddress2"].'">

                </td>
            </tr>
        </table>
  <input        type="submit"
                    src="images/arrow.png"
                    class="needEmptyBoxesFormForward2"
                    id="needEmptyBoxesFormForward2">
</form>';
  • 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-27T20:57:55+00:00Added an answer on May 27, 2026 at 8:57 pm

    Hmm… there’s a lot I’d do differently here, and it might make a difference.

    First, on your .post() command, I recommend using JSON:

    $.post('needEmptyBoxesRequest.php', 
        {'boxes': boxes, 'bubbleWrap': bubbleWrap, 
        'studentAddress1': studentAddress1, 'studentAddress2': studentAddress2}, 
        function (response) { ...
    

    Second, on your queries, I’d embed the strings:

     $sql =  "INSERT INTO supplies (`clientId`, `boxesRequested`, `bubbleWrapRequested`)
                VALUES ('$clientId', '$boxes', '$bubbleWrap');";
    

    I don’t think your form data is properly posting.

    UPDATE:
    After looking at your form code, I notice that you are refencing the inputs by ID in your jQuery, but by name in your form code. Please add id attributes to your inputs and see what happens.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to execute the following lines only the last two statements are displayed(Here
I have a query against two databases that I'm trying to execute. The first
I'm trying to execute two SQL statements in one mysql_query. $mySql = mysql_query(SELECT itemid,
I am trying to execute this SQL query prior to restoring a .BAK file
I am trying to execute this SQL command: SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page,
I'm trying to execute a asp.net webservice using jquery. When I pass only one
I'm trying to execute the following line: exit | sqlplus username/password@sid @test.sql Works great
I'm trying to execute a SQL command, but I just can't find out why
I have an application that needs to connect to a SQL database, and execute
I am using VS2005 and SQL Server 2005. I am trying to execute multiple

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.