Seating Reservation System - PHP + MYSQL

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »

82 Replies - 17872 Views - Last Post: 23 March 2013 - 09:19 AM Rate Topic: -----

#16 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 05 March 2013 - 03:36 AM

not if you use two separate forms. you can only submit one form at a time (and when you submit one, youíre usually on the next page).
Was This Post Helpful? 1
  • +
  • -

#17 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 05 March 2013 - 03:49 AM

View PostDormilich, on 05 March 2013 - 03:30 AM, said:

OK, if both elements are in the same form, the button submits both values (a form submit always sends all concerned data).


Just got it ! thanks so much Dormilich for your on going help!
Was This Post Helpful? 0
  • +
  • -

#18 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 03:18 AM

Hey Dormilich! Thanks for the help yesterday finally understand the form submit() logic :)

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
Was This Post Helpful? 0
  • +
  • -

#19 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 04:06 AM

ok, first thing I noticed is the unreadability of the query. sprintf() can help a lot here:
$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();
}

Was This Post Helpful? 1
  • +
  • -

#20 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

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
Was This Post Helpful? 0
  • +
  • -

#21 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 04:51 AM

I mean my method is working and updating the status perfectly. It's just UPDATEing the name that i cant seem to get to work unfortunately.
Was This Post Helpful? 0
  • +
  • -

#22 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 05:02 AM

depends on where the name has to be saved in. if itís the same table, add another assignment. if itís another table, update that table as well.

you could use the posted code nearly as is, youíd only need to initialize PDO.
Was This Post Helpful? 0
  • +
  • -

#23 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 05:15 AM

View PostDormilich, on 06 March 2013 - 05:02 AM, said:

depends on where the name has to be saved in. if itís the same table, add another assignment. if itís another table, update that table as well.

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

you could use the posted code nearly as is, youíd only need to initialize PDO.

ahh guess i need to install PDO?
Was This Post Helpful? 0
  • +
  • -

#24 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 05:35 AM

View Postcarmex, on 06 March 2013 - 01:15 PM, 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.

it seems you have no error handling. mysql[i]_error() should tell you whatís wrong.


View Postcarmex, on 06 March 2013 - 01:15 PM, said:

ahh guess i need to install PDO?

PDO is part of the default PHP installation. otherwise cf. http://www.php.net/m...stallation.php.

PS. phpinfo() tells you whatís installed.

View Postcarmex, on 06 March 2013 - 12:27 PM, said:

I'm finding this very difficult to understand, i am by no means an experienced programmer.

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();
}

Was This Post Helpful? 1
  • +
  • -

#25 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 05:55 AM

[quote name='Dormilich' date='06 March 2013 - 05:35 AM' timestamp='1362573342' post='1814952']
[quote name='carmex' date='06 March 2013 - 01:15 PM' timestamp='1362572151' post='1814946']

Quote

it seems you have no error handling. mysql[i]_error() should tell you whatís wrong.

Invalid query: Unknown column 'E' in 'field list'

That's when trying to enter 'E' as First name

Quote

PS. phpinfo() tells you whatís installed.

PDO
PDO support
enabled
PDO drivers
mysql, sqlite, sqlite2

i guess that means its working right? ill give it a go then.
Was This Post Helpful? 0
  • +
  • -

#26 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 05:58 AM

View Postcarmex, on 06 March 2013 - 01:55 PM, said:

Invalid query: Unknown column 'E' in 'field list'

then echo out the used SQL query (with the variables substituted) then it should get clearer what the problem is.
Was This Post Helpful? 1
  • +
  • -

#27 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

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

Was This Post Helpful? 0
  • +
  • -

#28 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 06:40 AM

yepp. and what do you notice when you compare the assignments/comparisons in the SET part with the WHERE part?
Was This Post Helpful? 0
  • +
  • -

#29 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 06:42 AM

ermm is it the : '' ? :no:
Not quite sure what you mean?
Was This Post Helpful? 0
  • +
  • -

#30 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 06:49 AM

correct, itís the quotes. field names are not quoted by apostrophes (only by backticks), so if you write firstName = A SQL reads "assign the value of field A to field firstName". then why does it work with numbers? because numbers cannot be field names.

PS. another matter that doesnít exist with prepared statements.
Was This Post Helpful? 1
  • +
  • -

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »