| | |
Show and Hide form from user
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 74
Reputation:
Solved Threads: 0
Hi
I explain what I have: user will visit the site to change booking detail using their client and booking ID, once thy typed their ID they will be directed to another page where they will be welcomed and they will be presented with a form to enter the booking ID they need to change and type their new booking details.
My question is what is the if statement which only show the second part of the (Form) to the user only if they have typed correct client ID. i.e if there is no record of them they should get an error message saying that we don’t have a record for you please try again.
Hope I have managed to explain my question well. Below is the code which I am using in my page.
I explain what I have: user will visit the site to change booking detail using their client and booking ID, once thy typed their ID they will be directed to another page where they will be welcomed and they will be presented with a form to enter the booking ID they need to change and type their new booking details.
My question is what is the if statement which only show the second part of the (Form) to the user only if they have typed correct client ID. i.e if there is no record of them they should get an error message saying that we don’t have a record for you please try again.
Hope I have managed to explain my question well. Below is the code which I am using in my page.
PHP Syntax (Toggle Plain Text)
<html> <head> <title>change Booking Details</title> </head> <body> <?php // Have they entered a ClientID? if(empty($_POST['clientID'])) { die("Please enter your correct BookingID number."); } $con = mysql_connect("xxxxxxxx","xxxxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxxxx", $con); $result = mysql_query("SELECT * FROM clients WHERE clientID=$_POST[clientID]"); // if statment should start here // if statment should here while($row = mysql_fetch_array($result)) { print "Hi"; echo(" "); echo $row['firstname'] . " " . $row['surname']; echo(" "); echo("welcome back you can change your booking using the form below "); echo "<br />"; } mysql_close($con) ?> <p> hi </p> <form name="form1" method="post" action="../actions/booking_updated.php"> <table width="75%" border="1"> <tr> <td>Bookin ID</td> <td><input type="text" name="bookingID"></td> </tr> <tr> <td width="34%">Arrival Date</td> <td width="66%"> <input name="startdate" type="text" id="startdate" maxlength="10"> (yyyy-mm-dd) </td> </tr> <tr> <td>Departure Date</td> <td><input name="enddate" type="text" id="enddate" maxlength="10"> (yyyy-mm-dd) </td> </tr> <tr> <td>Room Type</td> <td><select name="roomtype" id="roomtype"> <option value="Single">Single</option> <option value="Double">Double</option> <option value="Suite" selected>Suite</option> </select></td> </tr> <tr> <td>Number of Adults:</td> <td><select name="adults" id="adults"> <option value="1">1</option> <option value="2">2</option> </select></td> </tr> <tr> <td>Number of Children:</td> <td><select name="children" id="children"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select></td> </tr> <tr> <td>Special Requirments</td> <td><textarea name="requirements" cols="30" id="requirements"></textarea></td> </tr> <tr> <td> </td> <td><input name="updatebooking" type="submit" id="updatebooking" value="Update Booking"></td> </tr> </table> <p> </p> </form> <p> </p> </body> </html>
Sometimes it's easier to tell php which html to send to the client, based on a condition. Simple example:
In this example, the only thing outputted to the client would be "Error: Access Denied".
So you could do something like this:
php Syntax (Toggle Plain Text)
<?php $show="invalid"; if($show=="valid"){ ?> <div>You get to see this content</div> <?php }else{ ?> <div>Error: Access Denied</div> <?php } ?>
So you could do something like this:
php Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM clients WHERE clientID=$_POST[clientID]"); $num_rows = mysql_num_rows($result); if($num_rows>0){ while($row = mysql_fetch_array($result)) { print "Hi"; echo(" "); echo $row['firstname'] . " " . $row['surname']; echo(" "); echo("welcome back you can change your booking using the form below "); echo "<br />"; } ?> <form> <table> <tr><td>Form stuff here</td></tr> </table> </form> <?php }else{ ?> Error: The client ID is invalid. Please click back button and try again. <?php } ?> </body> </html>
Last edited by buddylee17; Mar 3rd, 2009 at 10:27 am.
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
![]() |
Similar Threads
- ComboBox Text Field cleared in Custom User Control When Form Show is called (VB.NET)
- Retrieving Form Variable (Visual Basic 4 / 5 / 6)
- Jump from code in one form to another. VB6 (Visual Basic 4 / 5 / 6)
- log in form (VB.NET)
- hide/show part of form using client side code for ASP.NET (ASP.NET)
- multiple user authentication.. (C#)
- show/hide element by name (JavaScript / DHTML / AJAX)
- problem with opening form (Visual Basic 4 / 5 / 6)
- Make a form unable(or get expired) after particular duration (Visual Basic 4 / 5 / 6)
- How to load multiple images on the form? (C#)
Other Threads in the PHP Forum
- Previous Thread: Extract URL
- Next Thread: WHERE ( SELECT COUNT(*) FROM table2 WHERE fbid = *current_row_primary_key*) > 150
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl data database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link links login loop mail md5 menu mlm mod_rewrite multiple mysql mysql_real_escape_string oop parse paypal pdf php problem query radio random recursion regex remote replace script search searchbox server session sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video votedown web website xml youtube





