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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:19:55+00:00 2026-05-30T07:19:55+00:00

Please can anyone help me with this? I have 2 tables, location and tickets

  • 0

Please can anyone help me with this?

I have 2 tables, location and tickets and what I have built so far is a form in a div that users enter the name of the city or town where they would like to see a live music performance. This form is submitted and an SQL statement is passed querying the location table. In another div, the users search query appears in a box on the screen. What I would like to do next is to write an SQL statement that will lookup the user’s query and dynamically display the relevant ticket information from the ticket table based on the location ID.

For example, the user types in ‘Newcastle’ as their search query, the location table finds the city of Newcastle and displays the user’s result in a div called ‘tickets’..I would like to display all the fields that correspond with ‘Newcastle’ from the ticket table.

The locationID is the primary key in the location table and has 3 other column, city, town and postcode.
The ticket table consists of ticketID being the primary key, the locationID being the foreign Key and the other fields i.e venue, tPrice, date and time. I think the problem im having is im not passing through the variable from the users query so that the ticket table can look it up and display the relevant information.

Here is the code for the form:

<div id="search">

    <form name="searchForm" id="searchForm" class="searchForm"  method="post">

   <input type="text" name="citySearch" id="citySearch" class="citySearch"   placeholder="Enter name city/town..." autofocus="autofocus" />

        <input type="submit" name="ticketSearch" id="ticketSearch" class="ticketSearch" value="Search" />


    </form>

</div>

Here is the code to display the user’s query:

  <div id="locationResult">

<?php

  include( 'classes/database_connection.php' );

      $cSearch = $_POST['citySearch'];

              $sql = "SELECT DISTINCT city FROM location WHERE city = '$cSearch'";

              mysql_query($sql) or die (mysql_error());
          $queryresult = mysql_query($sql) or die(mysql_error());

         while ($row = mysql_fetch_assoc($queryresult)) {
         $city = $row['city'];

         echo $row["city"];

        }
                                       mysql_free_result($queryresult);
        mysql_free_result($qResult);

        mysql_close($conn);
    ?>

    </div>
 </div>

This is where I want to display the ticket results from the ticket table:

    <div id="ticketsResults">

    <table class="ticketResult" border="0" cellspacing="5">
    <tr>
       <td><b>Venue</b></td>
               <td><b>Price</b></td>
               <td><b>Date</b></td>
               <td><b>Time</b></td>
               <td><b>Street View</b></td>
    </tr>

        <?php
            include( 'classes/database_connection.php' );

        $locID = $_POST['locationID'];
        $citySearch = $_POST['citySearch'];

                    $sQL = "SELECT locationID FROM location";

                  //Here is where I want it to display dynamic information rather than manually type the location
        $ticketSQL = "SELECT * FROM ticket NATURAL JOIN location WHERE city = 'Newcastle' ";

        mysql_query($sQL) or die (mysql_error());
            $qResult = mysql_query($sQL) or die(mysql_error());

        mysql_query($ticketSQL) or die (mysql_error());
            $result = mysql_query($ticketSQL) or die(mysql_error());


        while ($row = mysql_fetch_assoc($result)) {

    //  $ticketID = $row['ticketID'];

        $venue = $row['venue'];
        $ticketPrice = $row['tPrice'];
        $date = $row['date'];
        $time= $row['time'];

        echo "<tr>\n";
        echo "<td>$venue</td>\n";
        echo "<td>&pound$ticketPrice</td>\n";
        echo "<td>$date</td>\n";
        echo "<td>$time</td>\n";
            echo "<td>Click to see</td>\n";
        echo "</tr>\n";

        }

           mysql_free_result($qResult);
           mysql_free_result($result);
           mysql_close($conn);


    ?>
       </table>
    </div>

So basically, I’m wanting an SQL statement that dynamically displays the tickets according to the user’s query. Sorry about the copious amount of code! Any help given is greatly appreciated.

  • 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-30T07:19:56+00:00Added an answer on May 30, 2026 at 7:19 am

    Before you do anything else I think you should work on your coding style, specifically your indentation. A quick google search should do the trick. Next look into mysql prepared statements because currently your code is unsafe. Like jordanm said, it is subject to SQL injection.

    For example, if someone entered blah’ OR ‘x’=’x as a city name. Your query would become

    SELECT DISTINCT city FROM location WHERE city = 'blah' OR 'x'='x';
    

    Basically it allows the user to do naughty things with your query, and you don’t want that.

    Below is a sample of how you can avoid this using mysql prepared statements:

    // basic quick raw example
    $mysqli = new mysqli('localhost', 'user', 'password', 'database');
    $stmt = $mysqli->prepare('SELECT DISTINCT city FROM location WHERE city = ?');
    $stmt->bind_param('s',$city_name);
    $stmt->execute();
    $stmt->bind_result($city);
    while ($stmt->fetch())
    {
        echo $city;
    }
    

    That’s all I’m going to leave you with because I feel like to answer the actual question (?) I will need to write the code for you. Goodluck

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

Sidebar

Related Questions

Can anyone please help me with this...I'm not very good with regular expressions and
Can anyone help me spot the problem on this PLEASE? I'm eternally grateful for
Can anyone please help. I'm following a tutorial found here as I have a
Can anyone please help me how to convert string to date I have 3
Can anyone give me some help with a design please? my users enter short
Can any one please help me solve this. I am resizing some flash object/embed
Can anyone please help me to know how to open an excel sheet in
Can anyone please help me to work out how to achieve the following? I
Can anyone please help me to add video controls (play, pause, forward, seekbar) to
Can anyone please help me to understand how should i access json data in

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.