0

i dont know whats wrong with my codes. kinda new to PHP

here is my html code

<html>
<body>
<form action="sample2.php" method="POST">
<input type="submit" value="occupied" id="occupied">
<input type="submit" value="reserved" id="reserved">

<a name="slot1" style="background-color: green; width:100px; height:100px; border-top-right-radius:0px; border: 2px 
            solid Black;float:left; position:absolute; top:400px; left:441px;">

</form>
</body>
</html>

PHP code is here

<?php

$con=mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("sample");




if(isset($_POST['occupied'])){
$query="UPDATE reservation SET status='occupied' where status='vacant'";
echo "<a style=background-color: red; width:100px; height:100px; border-top-right-radius:0px; border: 2px 
            solid Black;float:left; position:absolute; top:400px; left:441px;>";
}
?>

my problem is whenever i click the occupied button, the color of the box doesnt change from green to red, it only directs me to a blank page. help

6
  • 3
    As @jimp has pointed out, you need to put a name attribute on your HTML form elements. But hopefully you also know that when you click the button, the page redirects to sample2.php and all that exists on that page (based on your sample) is a link. No <html> tag, no <body> tag, no <form> element, no <input> elements...just a link, and that's it. Is that what you want? Commented Sep 17, 2012 at 15:50
  • The reason that the you see a blank page is that the Display Errors variable is set to 0. Set it to 1 using set_ini('display_errors', 1) , so you can track the error.! Commented Sep 17, 2012 at 15:52
  • @MiroMarkarian Or at least look at the PHP error log where the errors are likely already being reported. Commented Sep 17, 2012 at 15:54
  • @Travesty3 not exactly, my goal is whenever i clicked the occupied button, the box should turn red. in other words if the 'status' field in my reservation table is updated to occupied, the box should automatically turn into red. thanks. Commented Sep 17, 2012 at 16:10
  • 1
    @PauPauCaraan: Sounds like you should look into AJAX. Commented Sep 17, 2012 at 16:28

2 Answers 2

2

Try this:

<input type="submit" value="occupied" name="occupied">
<input type="submit" value="reserved" name="reserved">

Forms submit controls with a "name" and since those didn't have the name attribute, they aren't being submitted to your PHP script.

Read about Successful Controls to learn more.

Sign up to request clarification or add additional context in comments.

3 Comments

Older MS IE version do not transfer the nae of submit buttons…
I have never encountered that issue, that I'm aware of at least. How old do you mean?
I think it was MS IE 6 and 7; but on the other hand it's years ago, since I had this problem…
1

you have to set together the id and the name into the form like this:

<html>
<body>
<form action="sample2.php" method="POST">
<input type="submit" value="occupied" id="occupied" name="occupied">
<input type="submit" value="reserved" id="reserved" name="reserved">

<a name="slot1" style="background-color: green; width:100px; height:100px; border-top-right-radius:0px; border: 2px 
            solid Black;float:left; position:absolute; top:400px; left:441px;"></a>

</form>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.