bigdog704 Posted November 22, 2019 Share Posted November 22, 2019 i cant seem to find where my problem is with this function. Any help is greatly appreicated. function update_reservation($room_id, $reg_id, $reserve_date) { global $db; $query = 'UPDATE reservations SET room_id = :room_id, reserve_date = :reserve_date, WHERE reg_id =:reg_id'; try { $statement = $db->prepare($query); $statement->bindValue(':room_id', $room_id); $statement->bindValue(':reserve_date', $reserve_date); $statement->bindValue(':reg_id', $reg_id); $row_count = $statement->execute(); $statement->closeCursor(); return $row_count; } catch (PDOException $e) { $error_message = $e->getMessage(); display_db_error($error_message); } } <form action="." method="post" id="add_edit_reservation_form"> <?php if (isset($reg_id)) : ?> <input type="hidden" name="action" value="update_reservation" /> <label>Reservation ID:</label> <input type="text" name="reg_id" value="<?php echo $reg_id ?>" /> <?php else: ?> <input type="hidden" name="action" value="add_reservation" /> <label>User_ID</label> <input type="text" name="ms_user_id" value="<?php echo $user_info['ms_user_id']; ?>" /> <?php endif; ?> <label>Which room would you like?</label> <select name="room_id"> <?php foreach ($room_ids as $room_id) : if ($room_id['room_id'] == $reservation['room_id']) { $selected = 'selected'; } else { $selected = ''; } ?> <option value="<?php echo $room_id['room_id']; ?>" <?php echo $selected ?>> <?php echo $room_id['room_name']; ?> </option> <?php endforeach; ?> </select><br> <label>What date would you like to reserve your room?</label> <input type="date" name="reserve_date" value="<?php echo ($reservation['reserve_date']); ?>"><br> <label>Please submit form to reserve your room.</label> <input type="submit" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/309566-php-function-help/ Share on other sites More sharing options...
chhorn Posted November 22, 2019 Share Posted November 22, 2019 If YOU don't know the problem, how should WE? At least there are PHP-tags missing. Quote Link to comment https://forums.phpfreaks.com/topic/309566-php-function-help/#findComment-1571803 Share on other sites More sharing options...
Psycho Posted November 22, 2019 Share Posted November 22, 2019 (edited) Pleas explain what you expect that code to do and then describe what it is doing (or not doing) that is contrary to your expectations. Are there errors? FYI: there is nothing in that code that ever calls that function. So, kinda hard to say it isn't working, when it is not used. Edited November 22, 2019 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/309566-php-function-help/#findComment-1571805 Share on other sites More sharing options...
Barand Posted November 22, 2019 Share Posted November 22, 2019 I also you suggest you check the manual for PDOStatement::execute() to see what it returns. Quote Link to comment https://forums.phpfreaks.com/topic/309566-php-function-help/#findComment-1571806 Share on other sites More sharing options...
bigdog704 Posted November 22, 2019 Author Share Posted November 22, 2019 i am getting Parse error: syntax error, unexpected '<', expecting end of file on this line <form action="." method="post" id="add_edit_reservation_form"> Quote Link to comment https://forums.phpfreaks.com/topic/309566-php-function-help/#findComment-1571807 Share on other sites More sharing options...
Barand Posted November 22, 2019 Share Posted November 22, 2019 (edited) 1 hour ago, chhorn said: At least there are PHP-tags missing. "Unexpected end of file" errors occur when the php parser expects something but cannot find it. Usual causes are an opening { without a corresponding closing } or quots at the start of a string and then no closing quotes. You'll have to find it yourself as it's impossible from just the couple of isolated snippets that we can see. Edited November 22, 2019 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/309566-php-function-help/#findComment-1571808 Share on other sites More sharing options...
ginerjm Posted November 23, 2019 Share Posted November 23, 2019 (edited) Took an attempt to clean up your code. See if this reads better for you. Note the subtle changes I have made here to help you understand what you are doing better. echo "<form action='' method='post' id='add_edit_reservation_form'>"; if (isset($reg_id)) { echo "<input type='hidden' name='action' value='update_reservation' /> <label>Reservation ID:</label> <input type='text' name='reg_id' value='$reg_id'/>"; } else { echo "<input type='hidden' name='action' value='add_reservation'/> <label>User_ID</label> <input type='text' name='ms_user_id' value='" . $user_info['ms_user_id'] . "'>"; } echo "<label>Which room would you like?</label> <select name='room_id'>"; foreach ($room_ids as $room_id) { if ($room_id['room_id'] == $reservation['room_id']) $selected = 'selected'; else $selected = ''; echo "<option $selected value='" .$room_id['room_id'] . "'>" . $room_id['room_name'] . "</option>"; } echo " </select><br> <label>What date would you like to reserve your room?</label> <input type='date' name='reserve_date' value='" . $reservation['reserve_date'] . "'> <br> <label>Please submit form to reserve your room.</label> <input type='submit' value='Submit'> </form> "; //********************************** // Functions below //********************************** function update_reservation($room_id, $reg_id, $reserve_date) { global $db; $query = 'UPDATE reservations SET room_id = :room_id, reserve_date = :reserve_date, WHERE reg_id =:reg_id'; try { $statement = $db->prepare($query); $statement->bindValue(':room_id', $room_id); $statement->bindValue(':reserve_date', $reserve_date); $statement->bindValue(':reg_id', $reg_id); $row_count = $statement->execute(); $statement->closeCursor(); return $row_count; } catch (PDOException $e) { $error_message = $e->getMessage(); display_db_error($error_message); } } Now - what doesn't work? Edited November 23, 2019 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/309566-php-function-help/#findComment-1571822 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.