0

I would like to create a radio button that will have a unique roomCode as a selecter based on each row. So if the roomCode = 1, the unique identifier within that row will be 1. This is so I can then submit a radio button to bring up a timetable based upon the roomCode selected.

Here is my PHP code:

$numeroOption = $_POST['numero'];
$roomtype = $_POST['roomtype'];
$selectOption = $_POST['parkname'];
$query = "SELECT * FROM `ROOMS` WHERE `Capacity` < '$numeroOption' AND `Park` LIKE '$selectOption%' AND `dataProjector` LIKE '$proj_check%' AND `Whiteboard` LIKE '$white_check%' AND `OHP` LIKE '$ohp_check%' AND `WheelchairAccess` LIKE '$wheel_check%' AND `lectureCapture` LIKE '$cap_check%' AND `Style` LIKE '$roomtype%'"; 
$result = mysql_query($query);

if ($result == FALSE) 
    die ("could not execute statement $query<br />");

echo "<table>"; 
while($row = mysql_fetch_array($result))
{   
    echo "<tr><td>" . $row['roomCode'] . "</td><td>" . $row['Park'] . "</td><td>" . $row['Capacity'] . "</td><td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td><td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td><td>" . $row['wheelchairAccess'] . "</td><td>" . $row['lectureCapture'] . "</td></tr>";
}
echo "</table>"; 
mysql_close(); 
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
James
  • 63
  • 6
  • 3
    [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Dec 02 '15 at 17:10
  • 3
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Dec 02 '15 at 17:11
  • Add another table cell with a form and a radio button with hidden values from your data. – Jay Blanchard Dec 02 '15 at 17:11
  • @JayBlanchard Unfortunately, my University requires me to carry out these functions – James Dec 02 '15 at 17:28

1 Answers1

0

For starters, you should be using mysqli or PDO. PDO is best if you will be using multiple databases (mysql and sql, etc) but if not, I prefer mysqli because i feel its more efficient.

To solve your problem...

    <form>
      while($row = mysql_fetch_array($result))
      { 
          echo "<tr><td><input type="radio" name="radioSelect" value= "" checked="" /></td><td>" . $row['roomCode'] . "</td><td>" . $row['Park'] . "</td><td>" . $row['Capacity'] . "</td><td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td><td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td><td>" . $row['wheelchairAccess'] . "</td><td>" . $row['lectureCapture'] . "</td></tr>";
    }
     }
    <input type="submit"/>
    </form>
BKCOHEN
  • 114
  • 2
  • 14