tags:

views:

61

answers:

6

I wrote this statements but it is not work :( ... can you tell me why?

HTML:

<form action="join.php" method="post">
<label name="RoomName">Room1</label>
</form>

PHP:

$roomName = $_POST['RoomName'];
$roomID = "SELECT RoomID FROM rooms WHERE RoomName = $roomName";

EDIT:

thanks but in my work the user does not have the ability to edit the room name

so i need to display the room name in a label (on any thing else) instead of text box

+3  A: 

You need an <input> element as well.

<input type="text" name="RoomName">

This way the value is available by $_POST['RoomName']. You likely also need a submit button:

<input type="submit" value="Submit">

The label just associates the label with an input element, usually with the for attribute pointing to the input element's id:

<label for="RoomName">Room1</label>
<input type="text" id="RoomName" name="RoomName">

The benefit of this is mainly in accessibility (screen readers, clicking label, etc).

To learn more about HTML forms, go through this quick guide: http://www.w3schools.com/html/html_forms.asp

As to the SQL query, read the comments others posted to your question. You need to quote strings and escape the values from SQL injections as well.

Update: as per your edit, just set the readonly attribute to avoid the field being edited:

<input type="text" id="RoomName" name="RoomName" value="somevalue" readonly>

or make use of a hidden input element:

<input type="hidden" name="RoomName" value="somevalue">
BalusC
As per the OPs edit, have `<input type="text" id="RoomName" name="RoomName" disabled>` to prevent the users from editing the room names.
Blair McMillan
No, use `readonly` instead of `disabled`.
BalusC
+1  A: 

Your code should look like this instead:

<form action="join.php" method="post">
<label name="RoomName">Room Name:</label>
<input type="text" name="RoomName" value="Room 1" />
<input type="submit" value="Submit Room" />
</form>
mattbasta
A: 
RoomName = $roomName"

to

RoomName = '$roomName'"

In SQL, strings must be quoted. Also, be safe by doing mysql_real_escape_string() on $roomName.

Coronatus
A: 

(moved response to EDIT section above in question)

Shahd
A: 

hmmm, and where is your submit button?:)

Syom
A: 

Also, you can't just set the value to the SQL query. You need to use the mysql_fetch_assoc() function. So it would be more like:

$sqlQuery = "SELECT RoomID FROM rooms WHERE RoomName = '".mysql_real_escape_string($roomName)."'";
$result = mysql_query($sqlQuery);
while ($row == mysql_fetch_assoc($result)) {
   $roomID = $row['rooms'];
   //do stuff with the current roomID
}
JGB146