I am new to php, and i am making a simple ticket validation system for my school in the theatre, So we scan all the purchased barcodes from the ticket into the form which then posts the barcode data into insert.php which uploads that number to the database (this process would be done before people get there tickets). So now we need to invalidate the ticket, so we scan the tickets that people bring in for the show and that goes into the deleteform.php which is just a text box and a submit button, and i need to post that to a delete script to take that number out of the database. can any one help!

More Info:

So here is my form for posting the ticket number/barcode to the insert.php script which uploads the number to mysql database.

<html>
<body>

<form action="insert.php" method="post">
Ticket Number: <input type="text" name="Ticket_Number" />
<input type="submit" />
</form>

</body>
</html>

and here is the insert.php script.

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

mysql_select_db("Tickets", $con);

$sql="INSERT INTO Tickets (Ticket_Number)
VALUES
('$_POST[Ticket_Number]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>

Now i need the same form i used above to enter a ticket number into and that number needs to be sent to a delete.php script or somthing to delete that number off mysql. and if that number is already deleted i need a error message like "No ticket with that number available."

I have something like this but i know its not right.

Delete_form.php

<html>

<body>


<form action="delete.php" method="post">

Ticket Number: <input type="text" name="Ticket_Number" />

<input type="submit" />

</form>


</body>

</html>

And here is the delete script to take the number off of the database.

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

mysql_select_db("Tickets", $con);

mysql_query("DELETE FROM Tickets (Ticket_Number)
VALUES 
('$_POST[Ticket_Number]')";

mysql_close($con);
?>

If anyone could help me that would be great!
Thanks in advance

nazmule27 commented: I want to delete a row from table using window in php +0

Recommended Answers

All 2 Replies

Firstly, for both scripts do

$ticket_number = intval($_POST['Ticket_Number']);

And use that instead of $_POST just in case someone enters in something that isn't a number.

Secondly use a SELECT statement to see if a ticket with that number exists and if it does execute the DELETE like so:

$query = 'DELETE FROM Tickets WHERE Ticket_Number = ' . $ticket_number;

Thanks for the quick reply, I am at work so i will try it when i get home.

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.