roomID is used to list all record of some room ID, all the record is associated with roomBookingID. When a user clicked "modify", a form is supposed to show. However, a error message shown after I added the red statement.

<?php require_once('../../config/conn.php');
$roomID=$_GET['roomID'];
$sql="SELECT * FROM roomBooking where roomID = '$roomID'";
$room_query_result=mysql_query($sql,$conn);
$row_rs = mysql_fetch_assoc($room_query_result);
$count=mysql_num_rows($room_query_result);
?>
...
     <form method="post" action="del_room.php">
     <table border="1">

  <?php do { ?>
  <tr>
    <td>
    <?php
    printf('<input type="checkbox" name="roomID[]" value="%s" />', $row_rs['roomID']);
    printf('<input type="hidden" name="roomBookingID" value="%s" />', $row_rs['roomBookingID']);
    ?>
    </td>
    <td> <?php echo $row_rs['bookingDate']; ?></td>
    <td><?php echo $row_rs['startTime']; ?></td>
    <td> <?php echo $row_rs['endTime']; ?></td>
    <td><?php echo $row_rs['numberOfPeople']; ?></td>
    [COLOR="Red"]<td><?php printf('<a href="roomDetail.php?roomBookingID=%s">modify</a>',$row_rs['roomBookingID']);
    ?></td>   [/COLOR]
  </tr>
   <?php } while($row_rs = mysql_fetch_assoc($room_query_result)) ?>
</table>
<p>
        <input type="submit" value="cancel" />
        <input type="reset" value="reset" />
      </p>   
    </form>
...

       <?php
  if (isset($_GET['roomID'])) {
     $SQL = sprintf("SELECT * FROM roomBooking WHERE roomID = '%s'", $_GET['roomID']);
     $rs = mysql_query($SQL, $conn) or die(mysql_error());
     $row_rs = mysql_fetch_assoc($rs);
// use heredoc syntax to quote a string and store it in variable $form
$form = <<<EOD
  <form method="post" action="updateRoom.php">
    <div>
    <br>
    <br>
      <p>
        <label>
          房間
          <input type="text" name="roomID" value="%s"/>
        </label>
      </p>
      <p>
        <label>
          日期
          <input type="text" name="bookingDate" value="%s"/>
          <input type="button" value="Cal" >
          (yyyy-mm-dd)
        </label>
      </p>
      <p>
        <label>
          開始時間
           <input type="text" name="startTime" value="00:00:00"/>(hh-mm-ss)
        </label>
      </p>
      <p>
        <label>
          結束時間
         <input type="text" name="endTime" value="00:00:00"/>(hh-mm-ss)
        </label>
      </p>
       <p>
        <label>
          使用房間的人數
          <input type="text" name="numberOfPeople" value="0"/>
        </label>
      </p>
      <input type="submit" value="確定"/>
      <input type="button" value="取消" />
    </div>
  </form>
EOD;
    // Substitute a string value into %s found in $form
    printf($form,
      $row_rs['roomID'],
      $row_rs['bookingDate'],
      $row_rs['startTime'],
      ($row_rs['endTime']),
      ($row_rs['numberOfPeople'])
    );
  } // end-if
?>
</body>
</html>
Member Avatar for diafol

use [ code ] tags

<?php require_once('../../config/conn.php');
$roomID=$_GET['roomID'];
$sql="SELECT * FROM roomBooking where roomID = '$roomID'";
$room_query_result=mysql_query($sql,$conn);
$row_rs = mysql_fetch_assoc($room_query_result);
$count=mysql_num_rows($room_query_result);
?>
...
<form method="post" action="del_room.php">
<table border="1">

<?php do { ?>
<tr>
<td>
<?php
printf('<input type="checkbox" name="roomID[]" value="%s" />', $row_rs['roomID']);
....
?>

The error say there is no $row_rs['roomID'] (last line)
this can be because your query returnd FALSE

change

$room_query_result=mysql_query($sql,$conn);

to

$room_query_result=mysql_query($sql,$conn) or die(mysql_error());

use code-tags

definitely agree with ardav,! please use code-tags so that we can spot the error(even though you mention it) and it's readable, by the way try using

<?php printf('<a href="roomDetail.php?roomBookingID=%s'">modify</a>',$row_rs['roomBookingID']);

i don't know if it's the same with printf in C and C#, mind me if i'm wrong but %s and %s' is not the same right? , well i guess your error is just parse error .. hope this helps cheers :)

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.