0

I'm trying to do a seat booking system, and i need to check via MySQL if the seat X is available. If there is a name assigned to it, print "Not Avalible", else if there is no name assigned to it, print "available!".

I successfully wrote a code that works but now i need to update it to the new MySQLi library. This is the code with the old MySQL library that works:

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

$i=0;
$number = 1;
$letter = 'A';

while ($i<336){
 if($number > 14){
   $letter++;
   $number = 1;
 }
 $seat = $letter . $number;
 $result  = mysql_query("SELECT name FROM seats WHERE seat = '$seat'");
   if( $r = mysql_fetch_assoc($result) ){
     if( $r['name'] == '' ){
     print 'Avalible';
   }else{
     print 'Not Avalible';
   }
   }
 $i++;
 $numero++;
}


?>

This is me trying to use the new MySQLi library:

$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "V3";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$i=0;
$number = 1;
$letter = 'A';

while ($i<336){
if($number > 14){
$letter++;
$number = 1;
}
$seat = $letter . $number;
$result  = mysql_query("SELECT name FROM seats WHERE seat = '$seat'");
if( $r = mysql_fetch_assoc($result) ){
if( $r['name'] == '' ){
print 'Avalible';
}else{
print 'Not Avalible';
}
}
$i++;
$numero++;
}

And of course, it doesn't work. It prints nothing. Help?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
lipe0010
  • 41
  • 5

0 Answers0