Reputation: 3
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- TemplateBeginEditable name="doctitle" -->
<title>REGISTRATION</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>
<body>
<?php
session_start();
$_SESSION["message"] = "";
$mysqli = new MySQLi("localhost","root","","accounts");
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$username = $mysqli->real_escape_string($_POST["username"]);
$email = $mysqli->real_escape_string($_POST["email"]);
$dday = ($_POST["day"]);
$indexno = ($_POST["indexno"]);
$_SESSION["username"] = $username;
$_SESSION["email"] = $email;
$sql = "INSERT INTO users (`indexno`, email, name, day) "."VALUES ('$indexno', '$email', '$username', '$dday');";
//check if mysql query is successful
if ($mysqli->query($sql) === true)
{
$_SESSION[ 'message' ] = "Registration succesful! Added $username to the database!";
//redirect the user to welcome.php
header( "location: welcome.php" );
}
else{
$_SESSION["message"] = "user could not be added to the database";
}
}
else{
$_SESSION["message"] = "could not initate seesion";
}
?>
<link href="//db.onlinewebfonts.com/c/a4e256ed67403c6ad5d43937ed48a77b?family=Core+Sans+N+W01+35+Light" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="form.css" type="text/css">
<div class="body-content">
<div class="module">
<h1>Create an account</h1>
<form class="form" action="form.php" method="post" enctype="multipart/form-data" autocomplete="off">
<div class="alert alert-error"></div>
<input type="text" placeholder="User Name" name="username" required />
<input type="email" placeholder="Email" name="email" required />
<br>
<input type="text" placeholder="index Number" name="indexno" required /><br>
<input type="submit" value="Register" name="register" class="btn btn-block btn-primary" />
<input type="radio" name="day" id="mond"
<?php
$result=mysqli_query("SELECT day=('monday'), COUNT(*) FROM users GROUP BY day");
$data=mysqli_fetch_assoc($result);
if(isset($dday) && $dday=='monday') echo 'checked';
if($data>=8) echo 'disabled';
?>
value="monday" required>Monday 08:30 AM - 10:30 AM <br>
<input type="radio" name="day" id="frid"
<?php if (isset($dday) && $dday=="friday") echo "checked";
?>
value="friday" required>Friday 02:00 PM - 04:30 PM <br>
<input type="radio" name="day"
<?php if (isset($dday) && $dday=="saturday") echo "checked";?>
value="saturday" required>Saturday 02:00 PM - 04:30 PM <br>
<input type="radio" name="day"
<?php if (isset($dday) && $dday=="sunday") echo "checked";?>
value="sunday" required>Sunday 08:30 AM - 10:30 AM <br>
</form>
</div>
</div>
</body>
</html>
-->
<input type="radio" name="day" id="mond"
<?php if (isset($dday) && $dday=="monday") echo "checked";
if($data>=8) echo("function disable() {
doccument.getElementById("mond").disabled = true;
}") ?>
value="monday" required>Monday 08:30 AM - 10:30 AM <br>
I want this radio button to be disabled if the data variable reaches 8.it says unexpected variable error in the doccument.get..... line please help ->update I added the full cod eon top because a user asked,
I have been struggling with this for quite a long time. the purpose of the code is to stop the radio button if it has been pressed eight time by referencing the data in the data base.so my idea was to put an if condition to disable the radio button in eight turns.
Upvotes: 0
Views: 788
Reputation: 408
Code this way
add space after checked
and use ternary for disabled
<?php
$dday="monday";
$data=9;
?>
<input type="radio" name="day" id="mond"
<?php if (isset($dday) && $dday=="monday") {echo "checked ";}
echo !empty($data)>=8?"disabled":''?> value="monday" required>Monday 08:30 AM - 10:30 AM <br>
Upvotes: 0
Reputation: 510
You are outputting javascrupt in the middle of an input tag.
You simply need to echo "disabled", like so:
<input type="radio" name="day" id="mond"
<?php
if(isset($dday) && $dday=='monday') echo 'checked';
if($data>=8) echo 'disabled';
?>
value="monday" required>Monday 08:30 AM - 10:30 AM <br>
Upvotes: 2