82 Replies - 3353 Views - Last Post: 23 March 2013 - 09:19 AM
#16
Re: Seating Reservation System - PHP + MYSQL
Posted 05 March 2013 - 03:36 AM
#17
Re: Seating Reservation System - PHP + MYSQL
Posted 05 March 2013 - 03:49 AM
#18
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 03:18 AM
Could do with some more advice though please?
Basically When the checkboxes are ticked and submitted it uses this code to change the status of the relevant seats(check boxes):
// Update Status Query
$statusB = $_POST['statusB'];
$statusA = $_POST['statusA'];
$changeStatus = "UPDATE seats set status=$statusB where( ";
$count = 0;
foreach($_POST['seats'] AS $seat)
{
if ($count > 0)
{
$changeStatus .= " || ";
}
$changeStatus .= " ( rowId = '" . substr($seat, 0, 1) . "'";
$changeStatus .= " and columnId = " . substr($seat, 1) . " ) ";
$count++;
}
$changeStatus .= " ) and status=$statusA";
if ($statusA == 1)
{
$changeStatus ;
}
Now i would like to do something similar for posting the names of people booking the seat once entered? How would i go about doing this, any advice will be greatly appreciated.
Thanks once again
#19
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 04:06 AM
$where = ' ( rowId = %s AND columnId = %d ) '; $sql = "UPDATE seats SET status=$statusB WHERE " . sprintf($where, substr($seat, 0, 1), substr($seat, 1));
second, you don’t need even that if you use Prepared Statements (using PDO as example)
$ps = $pdo->prepare("UPDATE seats SET status = 1 WHERE rowId = ? AND columnId = ?");
$ps->bindParam(1, $row, PDO::PARAM_STR);
$ps->bindParam(2, $col, PDO::PARAM_INT);
foreach ($_POST['seats'] as $seat)
{
$row = substr($seat, 0, 1);
$col = substr($seat, 1);
$ps->execute();
}
#20
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 04:27 AM
Quote
$ps = $pdo->prepare("UPDATE seats SET status = 1 WHERE rowId = ? AND columnId = ?");
$ps->bindParam(1, $row, PDO::PARAM_STR);
$ps->bindParam(2, $col, PDO::PARAM_INT);
foreach ($_POST['seats'] as $seat)
{
$row = substr($seat, 0, 1);
$col = substr($seat, 1);
$ps->execute();
}
I'm finding this very difficult to understand, i am by no means an experienced programmer. How would i go about implementing that code into what i already have ? :S
#21
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 04:51 AM
#22
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 05:02 AM
you could use the posted code nearly as is, you’d only need to initialize PDO.
#23
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 05:15 AM
Dormilich, on 06 March 2013 - 05:02 AM, said:
It will be in the same table.
What do you mean by assignment? iv tried creating another query similar to the first one but had no luck, the names will still not update.
I also tried adding it in :
$changeStatus = "UPDATE seats set status=$statusB, firstName=$fName, lastName=$lName where( ";
maybe my logic is wrong i don't know, but there seems to be a problem.
Quote
ahh guess i need to install PDO?
#24
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 05:35 AM
carmex, on 06 March 2013 - 01:15 PM, said:
What do you mean by assignment? iv tried creating another query similar to the first one but had no luck, the names will still not update.
I also tried adding it in :
$changeStatus = "UPDATE seats set status=$statusB, firstName=$fName, lastName=$lName where( ";
maybe my logic is wrong i don't know, but there seems to be a problem.
it seems you have no error handling. mysql[i]_error() should tell you what’s wrong.
carmex, on 06 March 2013 - 01:15 PM, said:
PDO is part of the default PHP installation. otherwise cf. http://www.php.net/m...stallation.php.
PS. phpinfo() tells you what’s installed.
carmex, on 06 March 2013 - 12:27 PM, said:
with added explanation
// create a Prepared Statement from the existing PDO connection
$ps = $pdo->prepare("UPDATE seats SET status = 1 WHERE rowId = ? AND columnId = ?");
// the first parameter is to be read from $row as string
$ps->bindParam(1, $row, PDO::PARAM_STR);
// the second parameter is to be read from $col as integer
$ps->bindParam(2, $col, PDO::PARAM_INT);
// loop over all seats
foreach ($_POST['seats'] as $seat)
{
// assign the first character (letter) to $row
$row = substr($seat, 0, 1);
// assign the second character (number) to $col
$col = substr($seat, 1);
// execute the Prepared Statement with the current set of values
$ps->execute();
}
#25
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 05:55 AM
[quote name='carmex' date='06 March 2013 - 01:15 PM' timestamp='1362572151' post='1814946']
Quote
Invalid query: Unknown column 'E' in 'field list'
That's when trying to enter 'E' as First name
Quote
PDO
PDO support
enabled
PDO drivers
mysql, sqlite, sqlite2
i guess that means its working right? ill give it a go then.
#26
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 05:58 AM
#27
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 06:06 AM
UPDATE seats set status=1, firstName=A, lastName=H where( ( rowId = 'A' and columnId = 1 )
Invalid query: Unknown column 'A' in 'field list'
is that what you meant?
This post has been edited by Dormilich: 06 March 2013 - 06:40 AM
#28
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 06:40 AM
#29
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 06:42 AM
Not quite sure what you mean?
#30
Re: Seating Reservation System - PHP + MYSQL
Posted 06 March 2013 - 06:49 AM
PS. another matter that doesn’t exist with prepared statements.
|
|

New Topic/Question
Reply




MultiQuote


|