trilbyfish Posted April 18, 2008 Share Posted April 18, 2008 I am trying to do an if statement, so that if a table cell contains a '-' (which is retrieved from a mysql table), the page shows a drop down text box which the user can edit, and if it doesnt contain a '-', a readonly textbox is shown which contains the value retrieved from the mysql table. Ive tried quite a few things, but at the moment i have i got this: <?php if (($row['08:00 - 09:00']) == "-") { echo '<td align="left"><select name="eight"> <option value="blank">blank</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['08:00 - 09:00'] . '" selected="selected">' . $row['08:00 - 09:00'] . '</option> </select> </td>;' else { echo '<td align="left"><input type="text" name="08:00 - 09:00" size="12" maxlength="30" readonly="true" value="' . $row['08:00 - 09:00'] . '" /></td>;' } ?> For some reason this doesnt work I am givin an error on the else statment line: "Parse error: syntax error, unexpected T_ELSE, expecting ',' or ';' " Ive tried quite a few things, working with notepad++, but i cant figure it out Please help! Thanks in advance Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 18, 2008 Share Posted April 18, 2008 <?php if (($row['08:00 - 09:00']) == "-") { echo '<td align="left"><select name="eight"> <option value="blank">blank</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['08:00 - 09:00'] . '" selected="selected">' . $row['08:00 - 09:00'] . '</option> </select> </td>'; // This semi-colon was inside the string } // The ending brace was missing here else { echo '<td align="left"><input type="text" name="08:00 - 09:00" size="12" maxlength="30" readonly="true" value="' . $row['08:00 - 09:00'] . '" /></td>'; // The semicolon was inside the string again } ?> Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 18, 2008 Author Share Posted April 18, 2008 Thanks for the help its not working how i intended, so i better work on it some more ??? Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 18, 2008 Author Share Posted April 18, 2008 how can i place this within a table? Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 19, 2008 Author Share Posted April 19, 2008 Ok ive done all that, and all the if statements are working, but now the submit button doesnt show up. Ive been fiddling around with it for hours. <?php session_name('visit'); session_start(); //check for session value if(!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT']))){ // Redirect the user to the loggedin.php page. // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/members.php'; header("Location: $url"); exit(); // Quit the script. } // This script retrieves all the records from bookingtable where the id is the one that corresponds with what was clicked on the previous page $page_title = 'View the booking table'; require_once ('../project/connect.php'); // Connect to the db. // Make sure the id that was on the bookingtable page was set, and select the relevent bay record from the sql 'bookingtable' table // Check for $_GET id if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM bookingtable WHERE id = $id"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // echo '$_GET['id']; // Table header. echo '<table align="left" cellspacing="0" cellpadding="5" border ="1"> <tr> <td align="left"><b>Bay Number</b></td> <td align="left"><b>08:00 - 09:00 </b></td> <td align="left"><b>09:00 - 10:00 </b></td> <td align="left"><b>10:00 - 11:00 </b></td> <td align="left"><b>11:00 - 12:00 </b></td> <td align="left"><b>12:00 - 13:00 </b></td> <td align="left"><b>13:00 - 14:00 </b></td> <td align="left"><b>14:00 - 15:00 </b></td> <td align="left"><b>15:00 - 16:00 </b></td> <td align="left"><b>16:00 - 17:00 </b></td> </tr> '; echo '<table align="left" cellspacing="0" cellpadding="5" border ="1"> <tr > <td colspan="11" td align="middle"> <input type="submit" name="submit" value="Submit"></td> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </tr> '; // Fetch and print the record whice corresponds to the bay id from the 'edit' link that was clicked on the bookingtable page if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <tr> <form action="editbay.php?id=' . $row['id'] . '" method="post"> <td align="left">' . $row['baynumber'] . '</td> '; if (($row['08:00 - 09:00']) == "-") { echo '<td align="left"><select name="eight"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['08:00 - 09:00'] . '" selected="selected">' . $row['08:00 - 09:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="08:00 - 09:00" size="12" maxlength="30" readonly="true" value="' . $row['08:00 - 09:00'] . '" /></td>'; }' '; if (($row['09:00 - 10:00']) == "-") { echo '<td align="left"><select name="nine"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['09:00 - 10:00'] . '" selected="selected">' . $row['09:00 - 10:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="08:00 - 09:00" size="12" maxlength="30" readonly="true" value="' . $row['09:00 - 10:00'] . '" /></td>'; }' '; if (($row['10:00 - 11:00']) == "-") { echo '<td align="left"><select name="ten"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['10:00 - 11:00'] . '" selected="selected">' . $row['10:00 - 11:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="10:00 - 11:00" size="12" maxlength="30" readonly="true" value="' . $row['10:00 - 11:00'] . '" /></td>'; }' '; if (($row['11:00 - 12:00']) == "-") { echo '<td align="left"><select name="eleven"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['11:00 - 12:00'] . '" selected="selected">' . $row['11:00 - 12:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="11:00 - 12:00" size="12" maxlength="30" readonly="true" value="' . $row['11:00 - 12:00'] . '" /></td>'; }' '; if (($row['12:00 - 13:00']) == "-") { echo '<td align="left"><select name="twelve"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['12:00 - 13:00'] . '" selected="selected">' . $row['12:00 - 13:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="12:00 - 13:00" size="12" maxlength="30" readonly="true" value="' . $row['12:00 - 13:00'] . '" /></td>'; }' '; if (($row['13:00 - 14:00']) == "-") { echo '<td align="left"><select name="thirteen"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['13:00 - 14:00'] . '" selected="selected">' . $row['13:00 - 14:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="13:00 - 14:00" size="12" maxlength="30" readonly="true" value="' . $row['13:00 - 14:00'] . '" /></td>'; }' '; if (($row['14:00 - 15:00']) == "-") { echo '<td align="left"><select name="fourteen"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['14:00 - 15:00'] . '" selected="selected">' . $row['14:00 - 15:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="14:00 - 15:00" size="12" maxlength="30" readonly="true" value="' . $row['14:00 - 15:00'] . '" /></td>'; }' '; if (($row['15:00 - 16:00']) == "-") { echo '<td align="left"><select name="fifteen"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['15:00 - 16:00'] . '" selected="selected">' . $row['15:00 - 16:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="15:00 - 16:00" size="12" maxlength="30" readonly="true" value="' . $row['15:00 - 16:00'] . '" /></td>'; }' '; if (($row['16:00 - 17:00']) == "-") { echo '<td align="left"><select name="sixteen"> <option value="-">-</option> <option value="' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '">' .$_SESSION['firstname']. ' ' .$_SESSION['surname']. '</option> <option value="' . $row['16:00 - 17:00'] . '" selected="selected">' . $row['16:00 - 17:00'] . '</option> </select> </td>'; } else { echo '<td align="left"><input type="text" name="16:00 - 17:00" size="12" maxlength="30" readonly="true" value="' . $row['16:00 - 17:00'] . '" /></td>'; }' </tr> <tr > <td colspan="11" td align="middle"> <input type="submit" name="submit" value="Submit"></td> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </tr> </form> </table> '; } echo '</table>'; // Check if the form has been submitted. if ($_REQUEST['submit']) { $errors = array(); // Initialize error array. // Check for a 08:00 - 09:00 time slot. if (empty($_POST['eight'])) { $errors[] = 'You forgot to enter something in 08:00 - 09:00.'; } else { $eight = escape_data($_POST['eight']); } // Check for a 09:00 - 10:00 time slot. if (empty($_POST['nine'])) { $errors[] = 'You forgot to enter something in 09:00 - 10:00.'; } else { $nine = escape_data($_POST['nine']); } // Check for a 10:00 - 11:00 time slot. if (empty($_POST['ten'])) { $errors[] = 'You forgot to enter something in 10:00 - 11:00.'; } else { $ten = escape_data($_POST['ten']); } // Check for a 11:00 - 12:00 time slot. if (empty($_POST['eleven'])) { $errors[] = 'You forgot to enter something in 11:00 - 12:00.'; } else { $eleven = escape_data($_POST['eleven']); } // Check for a 12:00 - 13:00 time slot. if (empty($_POST['twelve'])) { $errors[] = 'You forgot to enter something in 12:00 - 13:00.'; } else { $twelve = escape_data($_POST['twelve']); } // Check for a 13:00 - 14:00 time slot. if (empty($_POST['thirteen'])) { $errors[] = 'You forgot to enter something in 13:00 - 14:00.'; } else { $thirteen = escape_data($_POST['thirteen']); } // Check for a 14:00 - 15:00 time slot. if (empty($_POST['fourteen'])) { $errors[] = 'You forgot to enter something in 14:00 - 15:00.'; } else { $fourteen = escape_data($_POST['fourteen']); } // Check for a 15:00 - 16:00 time slot. if (empty($_POST['fifteen'])) { $errors[] = 'You forgot to enter something in 15:00 - 16:00.'; } else { $fifteen = escape_data($_POST['fifteen']); } // Check for a 16:00 - 17:00 time slot. if (empty($_POST['sixteen'])) { $errors[] = 'You forgot to enter something in 16:00 - 17:00.'; } else { $sixteen = escape_data($_POST['sixteen']); } if (empty($errors)) { // If everything's OK. { // Make the query. $query = "UPDATE bookingtable SET `08:00 - 09:00` = '$eight', `09:00 - 10:00` = '$nine', `10:00 - 11:00` = '$ten', `11:00 - 12:00` = '$eleven', `12:00 - 13:00` = '$twelve', `13:00 - 14:00` = '$thirteen', `14:00 - 15:00` = '$fourteen', `15:00 - 16:00` = '$fifteen', `16:00 - 17:00` = '$sixteen' WHERE baynumber = '$id' "; $result = mysql_query ($query) or die(mysql_error(). " -- $query"); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<br><br><br><br><br><br><h1 id="mainhead">Edit a Bay</h1> <p>A time slot has been edited.</p><p><br /><br /></p>'; } else { // If it did not run OK. echo '<br><br><br><br><br><br><p><h2 id="mainhead" align="left">System Error</h1></p> <p class="error">The time slot could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. exit(); } mysql_free_result ($result); // Free up the resources. } } } } } } }else{ echo '<p>'. mysql_error() . '<br/> <br/>Query: ' . $query . '</p>'; } mysql_close(); // Close the database connection. echo "<br><br><br><br><br><br><p>If you wish to go back and view the bookingtable click <a href = bookingtable.php>here</a></p>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> </body> </html> This is the code i have at the moment, where the submit button <tr > <td colspan="11" td align="middle"> <input type="submit" name="submit" value="Submit"></td> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </tr> doesnt show up. It previously showed up before without all the if statement for each timeslot. The best i have got so far is a submit button on the far right of the page that when clicked doesnt do anything. Quote Link to comment Share on other sites More sharing options...
GameYin Posted April 19, 2008 Share Posted April 19, 2008 You must declare session_start(); before declaring anything. ANYTHING AT ALL. So.. <?php session_name('visit'); session_start(); Is wrong Do this. <?php session_start(); session_name('visit'); Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 19, 2008 Author Share Posted April 19, 2008 My sessions work fine. Doing that just keeps redirecting me to the login page whenever i login. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.