Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Reservation system working halfway

    Hello there,
    I am creating a webpage for a friend where people come to get little jobs, so he want a simple reservation webpage where people can choose a date and hours to work. And when they register a day the request goes to a mysql table, and it disables the drop down menu of the hour selected. When I have just one hours for the person to choose from it works. but then when I add a second drop down menu it doesn't work like it should. When I have two drop down menus, the only way to make it work is by choosing one option by drop down menu, which isn't what I want. On the page there will maybe be about 30 drop down menus so I don't what that the people have to chooses a total of 30 jobs, it the want 10 they choose 10 and they get 10.

    this is the code for the choosing page:
    PHP Code:
    <?php>
    <
    html>
    <
    head>
        <
    title>Rechercher un poste.</title>
        <
    style>
            * {
                
    font-size11px;
                
    font-familyarial;
            }
    option {
        
    background-color#0F6;
    }
    option:disabled {
        
    background-color#930;
    }
        </
    style>
        <
    script>

            function 
    reserveSeats() {
                
                var 
    selectedList getSelectedList('Reserve Seats');
                
                
                    if (
    confirm('Vous avez choisi les postes  ' selectedList '?')) {
                        
    document.forms[0].oldStatusCode.value=0;
                        
    document.forms[0].newStatusCode.value=2;
                        
    document.forms[0].action='bookseats.php';
                        
    document.forms[0].submit();
                    } else {
                        
    clearSelection();
                    }
                
            }


            function 
    getSelectedList(actionSelected) {
                
                
    // get selected list
                
    var obj document.forms[0].elements;
                var 
    selectedList '';
                for (var 
    1obj.lengthi++) {
                    if (
    obj[i].selectedIndex  && obj[i].name == 'seats[]') {
                        
    selectedList += obj[i].value ', ';
                    }
                }
                
                
                
    // no selection error
                
    if (selectedList == '') {
                    
    alert('Please select a seat before clicking ' actionSelected);
                    return 
    false;
                } else {
                    return 
    selectedList;
                }

            }
            
            


            function 
    refreshView() {
                
    clearSelection();
                
    document.forms[0].action='<?php echo $_SERVER['PHP_SELF']; ?>';
                
    document.forms[0].submit();
            }

        
    </script>
    </head>
    <body>
    <table>
    <tr><td width="100%" align="center">
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

    <input type="hidden" name="oldStatusCode" value=""/>
    <input type="hidden" name="newStatusCode" value=""/>
      
    <table width='100%' border='0'>
        <tr><td align='center'>
            <input type='button' value='Refresh View' onclick='refreshView();'/>
        </td></tr>
    </table>
    </td></tr>
    <tr><td width="100%" align="center">
    <table width='100%' border='0'>
        <tr><td align='center'>
            <input type='button' value='Reserve Seats' onclick='reserveSeats()'/>
        </td></tr>
    </table>
    </td></tr>

    <table>
    <?php 
    $linkID 
    = @ mysql_connect("......""....."".......") or die("Could not connect to MySQL server"); 
    mysql_select_db(".......") or die("Could not select database"); 
    /* Create and execute query. */ 
    $query "SELECT * from seats order by rowId ,columnId"
    $result mysql_query($query); 
    $seatColor null;
    $tableRow false
    while (list(
    $rowId$columnId$status$updatedby$text$date) = mysql_fetch_row($result)) 

    if (
    $prevDate != $date) {
            if (
    $prevDate != '') {
                echo 
    "</select></tr></td>";
                echo 
    "\n</tr>";
            }
            
    $prevDate $date;
            echo 
    "\n<tr><td ><tr><select name='seats[]'><option></option>";
        } else {
            
    $tableRow false;
        }
        if (
    $status == 0) { 
            
    $seatColor ""
        } else { 
            
    $seatColor "disabled='disabled'"
        }
            echo 
    "<option $seatColor value='$rowId$columnId'>$text</option>"
       

    mysql_close(); 
    ?> 
    </table>
        </table>
        </td>
    </tr>
    </table>


    and this is the page that is supposed to send every think:
    PHP Code:
    <html>
    <head>
        <title>Tickets</title>
        <style>
            * {
                font-size: 14px;
                font-family: arial;
            }
        </style>
    </head>
    <body>
    <?php include("login.php"); ?>
    <center>
    <br/>
    <br/>
    <br/>
    <?php
    /*
     * Created on Mar 13, 2007
     * Author: dayg
     */
        
    if (isset($_POST['seats']))
        {
            
    $user $_SERVER['PHP_AUTH_USER'];
        
            
    $newStatusCode $_POST['newStatusCode'];
            
    $oldStatusCode $_POST['oldStatusCode'];

            
    // open database connection
            
    $linkID = @ mysql_connect("...."".....""......") or die("Could not connect to MySQL server");
            @ 
    mysql_select_db("......") or die("Could not select database");

            
    // prepare select statement
            
    $selectQuery "SELECT rowId, columnId from seats where (";
            
    $count 0;
            foreach(
    $_POST['seats'] AS $seat) {
                if (
    $count 0) {
                    
    $selectQuery .= " || ";
                }
                
    $selectQuery .= " ( rowId = '" substr($seat01) . "'";
                
    $selectQuery .= " and columnId = " substr($seat1) . " ) ";
                
    $count++;
            }
            
    $selectQuery .= " ) and status = $oldStatusCode";
            if (
    $oldStatusCode == 1) {
                
    $selectQuery .= " and updatedby = '$user'";
            }
            
            
    //echo $selectQuery;
            
            // execute select statement
            
    $result mysql_query($selectQuery);
            
    //echo $result;
            
            
    $selectedSeats mysql_num_rows($result);
            
    //echo "<br/>" . $selectedSeats;
            
            
    if ($selectedSeats != $count) {
                
    $problem "<h3>Il y a eu un problème avec votre envoie. Aucun poste n'as été réservé.</h3>";
                
    $problem .= "Les problèmes possibles sont:";
                
    $problem .= "<ul>";
                
    $problem .= "<li>Quelqu'un d'autre a eu le poste losque vous etiez entrain de faire votre choix.</li>";
                
    $problem .= "<li>il y a eu un problème de connection.</li>";
                
    $problem .= "</ul>";
                
    $problem .= "<a href='seats.php'>Retour à la selection de postes.</a>";
                die (
    $problem);
            }
            
            
    // prepare update statement
            
    $newStatusCode $_POST['newStatusCode'];
            
    $oldStatusCode $_POST['oldStatusCode'];
            
            
    $updateQuery "UPDATE seats set status=$newStatusCode, updatedby='$user' where ( ";
            
    $count 0;
            foreach(
    $_POST['seats'] AS $seat) {
                if (
    $count 0) {
                    
    $updateQuery .= " || ";
                }
                
    $updateQuery .= " ( rowId = '" substr($seat01) . "'";
                
    $updateQuery .= " and columnId = " substr($seat1) . " ) ";
                
    $count++;
            }
            
    $updateQuery .= " ) and status = $oldStatusCode";
            if (
    $oldStatusCode == 1) {
                
    $updateQuery .= " and updatedby = '$user'";
            }
            
            
    // perform update
            
    $result mysql_query($updateQuery);
            
    $updatedSeats mysql_affected_rows();

            if (
    $result && $updatedSeats == $count) {
                
    //$mysql->commit();
                
    echo "<h3>";
                echo 
    "Vous avez choisi les postes $updatedSeats : ";
                echo 
    "[";
                foreach(
    $_POST['seats'] AS $seat) {
                    
    $rowId substr($seat01);
                    
    $columnId substr($seat1);
                    echo 
    $rowId $columnId ", ";    
                }
                echo 
    "]";
                echo 
    "...</h3>";
            } else {
                
    //$mysql->rollback();
                
    echo "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
                echo 
    "Possible problems are:";
                echo 
    "<ul>";
                echo 
    "<li>Another process was able to book the same seat while you were still browsing.</li>";
                echo 
    "<li>You were trying to Confirm an unreserved Seat.</li>";
                echo 
    "<li>You were trying to Cancel an unreserved Seat.</li>";
                echo 
    "<li>You were trying to Reserve a reserved Seat.</li>";
                echo 
    "<li>There was a problem connecting to the database.</li>";
                echo 
    "</ul>";
            }
            
            echo 
    "<a href='seats.php'>View Seat Plan</a>";
            
            
    // Enable the autocommit feature
            //$mysqldb->autocommit(TRUE);
            
            // Recuperate the query resources
            //$result->free();
            
            
    mysql_close();
        }
    ?>
    </center>
    </body>
    </html>
    If you need there is an attachment with the MYSQL database.
    hope someone can help,
    Thanks Joris
    Attached Thumbnails Attached Thumbnails Reservation system working halfway-capture.png  


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •