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.

<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>&nbsp;</td>
      <td><input name="updatebooking" type="submit" id="updatebooking" value="Update Booking"></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<p>&nbsp;</p>
</body>
</html>

Recommended Answers

All 2 Replies

Sometimes it's easier to tell php which html to send to the client, based on a condition. Simple example:

<?php
$show="invalid";
if($show=="valid"){
?>
<div>You get to see this content</div>
<?php
}else{
?>
<div>Error: Access Denied</div>
<?php
}
?>

In this example, the only thing outputted to the client would be "Error: Access Denied".
So you could do something like this:

$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>

Hi buddylee17
Thank you very much for your help, your code did work.
Regards
HB25

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.