Im trying to write some code for a raffle, when someone buys one ticket it works well but if someone buys ten tickets. i would like it to put each one on a new row, the last column is the ticket number which is got by another table called count and i want the new count in the last column of each row.
In the actual script there is more than two columns but this is an example just to try to let you know what im trying to do.
As you can see i want the ticket number to increment by one every time someone buys tickets. (the ticket number is in a simple table with just id and ticket number)
EXAMPLE someone buys 2 tickes
name | ticket number
John | 1
john | 2
then someone buys three tickets
jane | 3
jane | 4
jane | 5
This is what i have. (WORKING EXAMPLE of the code tha doesnt work.) as you can see the ticker number stays the same and not increment by one.
<?php
$num //is a number between 1 and 10
$tr //is the current count got from database (this needs to count up by one every entry)
include 'includes/connect.php';
$num = "3"; // number of tickets someone buys.
$count = "5"; // count of tickets already sold (so this is start count for this transaction).
$id = "1"; // this is the line the counter is on to keep count updated for the amount of tickets sold.
$name = 'john'; //example name
for($i=0;$i< $num;$i++){
$count="$count+1"; // increments count by 1
$sql123 = "UPDATE count SET count=$count WHERE id='$id'"; //should update database to new count
$sql = "INSERT INTO test (name, number) VALUES ('$name', '$count')";
if($result = mysqli_query($con, $sql)){
echo "<br>tickets bought and entered into database,<br>Thank you<br>";
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
}
?>
Not sure what im doing wrong?
Thank you in advance
Nook6