im working on final year project of my deg its complete finaly i want to show a ticket to be appear after payment which has name and so on.

and a ticket number i want to generate a random ticket number for a user which will appear on the ticket also i have another problem.

which is when ever im resulting number from table its not showing why?

Dani AI

Generated

@mir-hrt raised two separate issues (generation and display), and asked for code — here are focused, practical fixes.

Generate-and-store, do not pick later
Generate a ticket number at the moment of payment and insert it into a tickets table with a UNIQUE index. Picking a random existing value (ORDER BY RAND()) or grabbing the “last” row (ORDER BY id DESC) is fragile: RAND() is slow and returns existing values, and DESC/LAST approaches break under concurrency. Enforce uniqueness at the DB level (for example: ALTER TABLE tickets ADD UNIQUE (ticket)), then return the inserted ticket to the user.

Quick debugging checklist

  1. Turn on errors and check the query result (display_errors/error_reporting or catch PDOException).
  2. Verify the table actually contains rows and that column names match.
  3. Don’t rely on selecting recent rows to identify the current user’s ticket; use the inserted ticket id or a session/order id instead.

Minimal, modern example (safe randomness + retry on duplicate)

// $pdo is a PDO connection with exceptions enabled
function createTicket(PDO $pdo, $userId) {
    for ($i = 0; $i < 5; $i++) {
        $ticket = 'TKT-' . strtoupper(bin2hex(random_bytes(4))); // secure, short token
        try {
            $stmt = $pdo->prepare('INSERT INTO tickets (ticket, user_id, created_at) VALUES (?, ?, NOW())');
            $stmt->execute([$ticket, $userId]);
            return $ticket;
        } catch (PDOException $e) {
            if ($e->getCode() === '23000') continue; // duplicate key, retry
            throw $e;
        }
    }
    throw new RuntimeException('Unable to create unique ticket');
}

Presentation and printing
Instead of many little tables, wrap ticket data in a single container and style it with CSS (flex/grid, print stylesheet, borders/shadow for “ticket” look). Move away from deprecated mysql_* functions to PDO or mysqli for security and stability (PDO manual, random_bytes).

Recommended Answers

All 2 Replies

Can you post your code for generating the ticket number and displaying it please? This might help us figure out where you are going wrong...

i have done this to achive result but tables are mess? i want this to show a ticket look like a ticket havent worked with php styling and tables?

[IMG][/IMG]

i want this to look like a ticket? what should i do?

<?php
$con = mysql_connect("localhost","root","autodeskmaya");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("online_bus_project", $con);



echo "<table border='1' cellpadding='5' cellspacing='3' align='center' bgcolor='#ececec'>
<tr>

<th>Online Bus Ticket Reservation System - Traveling Ticket</th> 

</tr>";

echo "</table>";



$result3 = mysql_query("SELECT ticket FROM ticket_number ORDER BY RAND() LIMIT 1");


echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
<tr>

<th>Ticket Number</th> 

</tr>";

while($row3 = mysql_fetch_array($result3))
  {
  echo "<tr>";
  echo "<td>" . $row3['ticket'] . "</td>";
  echo "</tr>";
  }
echo "</table>";







//SELECT * FROM table ORDER BY RAND() LIMIT 1




$result2 = mysql_query("SELECT first_name, last_name FROM user_information ORDER BY `id` DESC LIMIT 1");  


echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
<tr>

<th>Name</th> 
<th>Last Name</th>




</tr>";

while($row2 = mysql_fetch_array($result2))
  {
  echo "<tr>";
  echo "<td>" . $row2['first_name'] . "</td>";
  echo "<td>" . $row2['last_name'] . "</td>";
  echo "</tr>";
  }
echo "</table>";






$result = mysql_query("SELECT * FROM trip ORDER BY `id` DESC LIMIT 1");  


echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
<tr>\n
<th>From</th>
<th>To</th>
<th>Date</th>
<th>Paid Amount</th>



</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['gender'] . "</td>";
  echo "<td>" . $row['country'] . "</td>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['fare'] . "</td>";
  echo "</tr>";
  }
echo "</table>";


$result1 = mysql_query("SELECT * FROM seat ORDER BY `id` DESC LIMIT 1");  


echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
<tr>\n
<th>Seat</th>

</tr>";

while($row1 = mysql_fetch_array($result1))
  {
  echo "<tr>";
  echo "<td>" . $row1['seat'] . "</td>";
  echo "</tr>";
  }
echo "</table>";








mysql_close($con);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.