How to delete a row/entry in a table under Mysql with php.?
How to delete a row/entry in a table under Mysql with php.?
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.
and here is the insert.php script.
$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.
If anyone could help me that would be great!
Tags: Delete, mysql, php., row/entry, table, under
Under Forum

1 Comment for How to delete a row/entry in a table under Mysql with php.?
1. ?????? | February 15th, 2011 at 8:51 am
I’m a PHP newbie as well so this may not be a perfect one:
< ?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Tickets", $con);
mysql_query("DELETE FROM Tickets WHERE Ticket_Number='".$_POST["Ticket_Number"]."'");
//Tickets is your table name.
//Ticket_Number (the one before '=' sign) iis your row name in your table.
mysql_close($con)
?>
Leave a Comment for How to delete a row/entry in a table under Mysql with php.?
You must be logged in to post a comment.
Trackback this post | Subscribe to the comments via RSS Feed