Hi everyone i dont know how to get the already filled value of radio buttons from sql using html/php here is my code but its giving error

<?php include("../includes/config.php"); ?>
 if ($_SESSION["isadmin"])

if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db($dbname, $con);
$result = mysql_query("SELECT * FROM accounts WHERE (id='".$accountid."')");

    while($row = mysql_fetch_array($result))
       $firstname = $row['firstname'];
       $lastname = $row['lastname'];
<title>Edit User</title>
<link rel="StyleSheet" href="../admin/css/style.css" type="text/css" media="screen">

<?php include("../admin/includes/header.php"); ?>
<?php include("../admin/includes/nav.php"); ?>
<?php include("../admin/includes/aside.php"); ?>
<div id="maincontent">

    <div id="breadcrumbs">
        <a href="">Home</a> >
         <a href="">Manage Users</a> >
         <a href="">List Users</a> >
         Edit User
    <h2>Edit User</h2>

    <form method="post" action="users-edit-action.php">
    <input type="hidden" value="<?php echo $accountid; ?>" name="id" />
    <label>Email/Username:</label><input type="text" name="email" value="<?php echo $email; ?>" /><br /><br />
    <label>Password:</label><input type="password" name="password" value="<?php echo $password;?>" /><br /><br />
    <label>First Name:</label><input type="text" name="firstname" value="<?php echo $firstname; ?>" /><br /><br />
    <label>Last Name:</label><input type="text" name="lastname" value="<?php echo $lastname; ?>" /><br /><br />
    <label>Type:</label><br />
    <input type="radio" name="type" value="<?php echo $type; ?>" /> Student<br />
    <input type="radio" name="type" value="<?php echo $type; ?>" /> Teacher<br />

        <input type="submit" value="Edit" />


<?php include("../admin/includes/footer.php"); ?>
        header("Location: ".$fullpath."login/unauthorized.php");


thanks in advance

Recommended Answers

All 9 Replies

What is the error?

error it gives after pressing edit button is this

Notice: Undefined index: type in C:\xampp\htdocs\project\admin\users-edit-action.php on line 7

and this id the script on which it gives the error..i think error is due to wrong placement of values in radio buttons..

<?php include("../includes/config.php");?>

if (!$con) { die('Could not connect: ' . mysql_error()); }

 mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$firstname."' , lastname='".$lastname." email='".$email."' type='".$type."' WHERE (id='".$id."')");
$result = mysql_query($query);
echo "User has been updated Successfully!!";

I am wondering if your name="type" is causing a conflict as type is used as part of a form elements details. Have you tried changing it to something else and see what happens?

Also, are you sure that one of the radio buttons is being selected?

Member Avatar for diafol
<input type="radio" name="type" value="<?php echo $type; ?>" /> Student<br />
<input type="radio" name="type" value="<?php echo $type; ?>" /> Teacher<br />

Why are you giving both radios the same value? It can't discrominate between them. I also suggest making one a default with checked="checked".

yup i know tht this is the wrong way but i cant understand how would i take the value from data base??? as i want to edit the already filled record then it should be checked already...how can i do that?? i mean how can i get the value of that type whether it is S or T..so that i could edit and change the type when i want to edit it..

Member Avatar for iamthwee

Like diafol said (off topic:when did you change your username?) the radio button names need to be unique.

Ipso facto. <- that's latin BTW.

So, you radio buttons need to have unique names!

Now from your PHP file it is quite tedious to go through each name and check if it isset();

So we create a grouped radio button with the [] syntax in the HTML. That way we can just loop through using the foreach syntax.

@diafol well i want to retrieve the value from database.. how would i do that..the values are uniqe as thay are coming from database, i dont know how to check which value is selected in database to update it further..

Like this:

<input type="radio" name="type" value="Student" <?php if ($type=='Student') { echo 'checked'; } ?> /> Student<br />
<input type="radio" name="type" value="Teacher" <?php if ($type=='Teacher') { echo 'checked'; } ?> /> Teacher<br />

thankyou very much.problem is solved :)

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.