I have a group of radio buttons placed in a form with method post. But anytime the form is post the value from the radio button is zero. Below is the code
<form method="POST" action='insert_per.php'>
<table >
<caption>
Grant Permissions
</caption>
<thead>
<tr>
<th class="center"><strong>Name</strong></th>
<th class="center"><strong>Email</strong></th>
<?PHP if($_SESSION['user_group'] == 63){
echo '<th class="center"><strong>System Admin</strong></th>';
echo '<th class="center"><strong>Admin</strong></th>';
echo '<th class="center"><strong>User</strong></th>';
} ?>
<th class="center"><strong></strong></th>
</tr>
</thead>
<?php
if($stmt->execute()){
// output data of each row
while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>
<tr>
<td border="0" type="hidden" style="display:none;"><input type="hidden" name="hidden" value=<?php echo $rows['member_id']; ?></td>
<td class="center"><?php echo $rows['username']; ?></td>
<td class="center"><?php echo $rows['email']; ?></td>
<?PHP if($_SESSION['user_group'] == 63){ ?>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="system admin"
<?php echo ($rows['permission']== 31 )?'checked':'' ?>></input> </td>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="admin"
<?php echo ($rows['permission']== 15 )?'checked':'' ?> ></input> </td>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user"
<?php echo ($rows['permission']== 1 )?'checked':'' ?> ></input> </td> <?PHP } ?>
<td class="center"><button name="SUBMIT" type="SUBMIT">submit</button></td>
</tr>
<?php
}
}
?>
</table>
</form>
Below is the code for the insert_per.php
echo "this is the gp "+ $_POST['gp'];
echo "this is the gp "+ $_POST['hidden'];
try{
$stmt= $dbh->prepare("UPDATE `members_groups` SET `group_id`=(SELECT group_id FROM groups WHERE
group_name = ? ) WHERE member_id = ?");
$stmt->bindParam(1, $_POST['gp'] , PDO::PARAM_STR);
$stmt->bindParam(2 , $_POST['hidden'] , PDO::PARAM_INT);
if($stmt->execute()) {
echo " the privilege was granted successfully ".'<BR>';
echo "<a href='user_acc.php'>View result</a>";
}
} catch(PDOException $e)
{
echo "An error occured ".$e->getMessage();
}
The radio buttons are expected to produce one of the following values
"system admin"
"admin"
"user"
but it always produces zero "0" value.
Related
As a beginner in PHP.
I have a dropdownlist of event names and a button, And I tried to display it only when I selecting any value > 0 only. Please help me out.
Thanks in advance
<?Php
#$event=$_GET['event'];
if(strlen($event) < 0 ){
echo "Data Error";
exit;
}
$sql="SELECT id,event_name FROM wp_evr_event order by id";
if(isset($event) and strlen($event) > 0){
$quer="SELECT id,fname,status,email,event_id FROM wp_evr_attendee where event_id=$event order by fname";}
else{$quer="SELECT id,fname,status,email,event_id FROM wp_evr_attendee order by event_id";}
echo "<form method=post name=Reload action=''>";
echo "<select name='event' onchange=\"reload(this.form)\"><option value=''>please select..</option>";
foreach ($con->query($sql) as $row){
if($row['id']==#$event){echo "<option selected value='$row[id]'>$row[event_name]</option>"."<BR>";}
else{echo "<option value='$row[id]'>$row[event_name]</option>";
}
}
echo "</select>";
?>
</div>
<div class="container">
<table>
<tr>
<td class='c_td'>id</td>
<td class='c_td'>name</td>
<td class='c_td'>status</td>
<td class='c_td'>email</td>
<td class='c_td'>event_id</td>
<td class='c_td'>edit</td> <td>delete</td>
</tr>
<?php
$i=1;
foreach ($con->query($quer) as $row2) {
$i=$i+1;
?>
<tr>
<td class='i_td'><?php echo $row2['id'] ?> </td>
<td class='i_td'><?php echo $row2['fname'] ?> </td>
<td class='i_td'><?php echo $row2['status'] ?> </td>
<td class='i_td'><?php echo $row2['email'] ?> </td>
<td class='i_td'><?php echo $row2['event_id'] ?> </td>
</tr>
<?php
}
?>
Because only the names of attendees will be exported for the selected event
<?php
echo '<td><a class="btn" href="test3.php?event=' . $row2['event_id'] . '">Export To Excel</a> </td>';
?>
I tried this
select:invalid + button {
display: none;
}
I want to display a columns with radio buttons based on a data from mysql table and using php , but I am not able to toggle between the radio buttons. Below is the code.
while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>
<tr>
<td border="0" type="hidden" style="display:none;"><input type="hidden" name="hidden" value=<?php echo $rows['member_id']; ?></td>
<td class="center"><?php echo $rows['username']; ?></td>
<td class="center"><?php echo $rows['email']; ?></td>
<?PHP if($_SESSION['user_group'] == 63){
echo '<td class="center"><input type="radio" id='?><?php echo $rows['username']; 'name="gp" value="system admin"' ?>
<?php echo ($rows['permission']== 31 )?'checked':'' ?>'</input> </td>' <?PHP ;
echo '<td class="center"><input type="radio" id='?><?php echo $rows['username']; 'name="gp" value="admin"' ?>
<?php echo($rows['permission']== 15 )?'checked':'' ?> '</input> </td>' <?PHP ;
echo '<td class="center"><input type="radio" id='?><?php echo $rows['username'];'name="gp" value="user"'
?><?php echo ($rows['permission']== 1 )?'checked':'' ?> '</input> </td>' <?PHP ; }
elseif($_SESSION['user_group'] == 31){
echo '<td class="center"><input type="radio" id='?><?php echo $rows['username']; 'name="gp" value="admin"' ?>
<?php echo($rows['permission']== 15 )?'checked':'' ?> '</input> </td>' <?PHP ;
echo '<td class="center"><input type="radio" id='?><?php echo $rows['username'];'name="gp" value="user"'
?><?php echo ($rows['permission']== 1 )?'checked':'' ?> '</input> </td>' <?PHP ; }
elseif($_SESSION['user_group'] == 15){
echo '<td class="center"><input type="radio" id='?><?php echo $rows['username'];'name="gp" value="user"'
?><?php echo ($rows['permission']== 1 )?'checked':'' ?> '</input> </td>' <?PHP ; }?>
<td class="center"><button name="update" type="update">submit</button></td>
</tr>
<?php
}
looks like there is an error in the code. Any help with it. The current rendition is below.
I want to toggle between the radio buttons.
was able to figure it out. Deleted echo command from the beginning of the html column lines. the code is presented below.
while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>
<tr>
<td border="0" type="hidden" style="display:none;"><input type="hidden" name="hidden" value=<?php echo $rows['member_id']; ?></td>
<td class="center"><?php echo $rows['username']; ?></td>
<td class="center"><?php echo $rows['email']; ?></td>
<?PHP if($_SESSION['user_group'] == 63){ ?>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="system admin"
<?php echo ($rows['permission']== 31 )?'checked':'' ?>></input> </td>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="admin"
<?php echo ($rows['permission']== 15 )?'checked':'' ?> ></input> </td>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user"
<?php echo ($rows['permission']== 1 )?'checked':'' ?> ></input> </td> <?PHP }
elseif($_SESSION['user_group'] == 31){ ?>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="admin"
<?php echo ($rows['permission']== 15 )?'checked':'' ?> ></input> </td>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user"
<?php echo ($rows['permission']== 1 )?'checked':'' ?> ></input> </td> <?PHP }
elseif($_SESSION['user_group'] == 15){ ?>
<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user"
<?php echo ($rows['permission']== 1 )?'checked':'' ?> ></input> </td><?PHP }?>
This worked just fine.
So, I am trying to sort a database by clickable links. I have a function that is supposed to order them, but for some reason it isn't working. Also, once I add something to the database and submit, if I click on the links to order, it sends me to my actual function holding file in the url, which is weird.
Forgive table formatting issues. I'm still debugging that.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Project 1</title>
</head>
<body>
<h1 style='text-align:center;'>Movie Collection Database</h1>
<form method='post' action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align='center' border='1' cellpadding='5'>
<tr>
<td>
<input type="text" size='40' name="movieTitle" value="Movie Title">
</td>
<td>
<input type="text" name="studioName" value="Studio Name">
</td>
<td>
<select name="movieRating">
<option value="G">G</option>
<option value="PG">PG</option>
<option value="PG-13">PG-13</option>
<option value="R">R</option>
<option value="NC-17">NC-17</option>
<option value="Not Rated">Not Rated</option>
</select>
</td>
<td>
<input type="text" name="publicationYear" value="2015">
</td>
<td>
<input type="number" name="imdbRating" value="10.0">
</td>
<td>
<input type="number" name="runTime" value="0">
</td>
<td>
<input type="checkbox" name="add">Add
</td>
</tr>
</table>
<?php
$db = new PDO("mysql:host=localhost;dbname=berkleyr", "berkleyr", "12345");
?>
<?php include_once("Project1DB.php"); ?>
<?php if ($_SERVER['REQUEST_METHOD'] === "POST"):
delete($db);
if(isset($_POST['add']))
{
try
{
Insert($db, $_POST['movieTitle'], $_POST['studioName'], $_POST['movieRating'], $_POST['publicationYear'], $_POST['imdbRating'], $_POST['runTime']);
}
catch (PDOException $error)
{
$db->rollback();
echo "Bad things Happened";
$db = null;
die("Connection failed: " . $error->getMessage());
}
}
?>
<table align='center' border='1'>
<tr>
<th>Title</th>
<th>Studio Name</th>
<th>Rating</th>
<th>Pub Year</th>
<th>IMDB Rating</th>
<th>Run Time</th>
<th>Delete</th>
</tr>
<?php foreach (Select($db) as $row): ?>
<tr>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['studio']; ?></td>
<td><?php echo $row['rating']; ?></td>
<td><?php echo $row['pub_year']; ?></td>
<td><?php echo $row['imdb_rating']; ?></td>
<td><?php echo $row['run_time']; ?></td>
<?php echo "<td><input type='checkbox' name='". $row['id'] . "' value='" . $row['id'] . "'></td>";?>
</tr>
<?php endforeach ?>
<?php
if (isset($db))
{
$db = null; // make sure an exception didn't already close the connection. If not, close it now.
}
?>
<?php else: ?>
<table align='center' border="1">
<tr>
<th>Title</th>
<th>Studio Name</th>
<th>Rating</th>
<th>Pub Year</th>
<th>IMDB Rating</th>
<th>Run Time</th>
<th>Delete</th>
</tr>
<?php foreach (Select($db) as $row): ?>
<tr>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['studio']; ?></td>
<td><?php echo $row['rating']; ?></td>
<td><?php echo $row['pub_year']; ?></td>
<td><?php echo $row['imdb_rating']; ?></td>
<td><?php echo $row['run_time']; ?></td>
<?php echo "<td><input type='checkbox' name='". $row['id'] ."' value='" . $row['id'] . "'></td>";?>
</tr>
<?php endforeach ?>
<?php endif ?>
<td colspan="7" align="center">
<input type='submit' name='submit' value='Update Database' />
</td>
</table>
</form>
</body>
</html>
Here is my function for sorting:
function orderBy($order)
{
switch($order)
{
case "title":
$sorted = $this->db->prepare("SELECT * FROM movie ORDER BY movie.title ASC");
break;
case "studio":
$sorted = $this->db->prepare("SELECT * FROM movie ORDER BY movie.studio ASC");
break;
case "rating":
$sorted = $this->db->prepare("SELECT * FROM movie ORDER BY movie.rating ASC");
break;
case "pub_year":
$sorted = $this->db->prepare("SELECT * FROM movie ORDER BY movie.pub_year ASC");
break;
case "imdb_rating":
$sorted = $this->db->prepare("SELECT * FROM movie ORDER BY movie.imdb_rating ASC");
break;
case "run_time":
$sorted = $this->db->prepare("SELECT * FROM movie ORDER BY movie.run_time ASC");
break;
}
$sorted->execute();
}
I want to insert selected rows in the database but I am unable to get count of checked check-boxes. However in one of my form where I am updating records I could get count but here I couldn't. Code is as below
<tr class="odd gradeX">
<td>
<input type="checkbox" class="checkboxes" value="<?php echo $row['student_id']; ?>" name="ids[]" />
</td>
<td>
<?php echo $row['first_name']." ".$row['last_name'];?>
</td>
<td>
<?php echo $row['father_mobile'];?>
</td>
<td class="hidden-480">
<a href="mailto:<?php echo $row['email'];?>">
<?php echo $row['email'];?>
</a>
</td>
<td class="hidden-480">
<?php echo $row['address'];?>
</td>
<td class="center hidden-480">
<?php echo $row1['track_name'];?>
</td>
<td>
<?php echo $row2['level_name'];?>
</span>
</td>
</tr>
<?php
if(isset($_POST['move']))
{
echo "count is" . count($_POST["ids"]);
for($i=0; $i<count($_POST["ids"]); $i++){
echo $sql = "inset into tbl_student_batches set bacth_id='".$_POST['batch_id']."',student_id='".$_POST['ids']."'";
if (mysql_query($sql)) {
$msg = "Selected students moved to next batch successfully";
header("location:convert_level?msg=$msg");
}else{
$errmsg = ("Error while moving.". mysql_error());
}
}
}
you can try in this way
$studentIds = explode(' ', $_POST['ids']);
$totalId= count($studentIds);
Hi to all i have a problem, i want to remove the duplicate value from my looping
eg.
I have a 4 record,
It must be 4 records display from my output, the problem is, it display a 16 records that's why I need to remove duplicate from my looping statement
See my code below
coming from submit
<input type='text' value='<?php echo "$row[partyid]"; ?>' name='phonenum[]' readonly />
for ($i=0; $i<sizeof($phonenum);$i++)
{
$sql = "SELECT *
FROM
$table2,
$table3
WHERE
$table2.billdate = '$date'
AND $table3.tel_three LIKE '%$phonenum[$i]%'
";
<?php if( $rs == null ):?>
<tr>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
</tr>";
<?php else:?>
<?php while( $row = mysql_fetch_assoc($rs) ):
?>
<tr>
<form action='flookup.php' method='post'>
<td align='center'><?php echo "<font size=1>".$row['billdate']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['calldate']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['partyid']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['billedamount']."</font>"; ?></td>
<td align='center'>
<?php echo "<font size=1>".$row['partyid']."</font>"; ?>
<input type='hidden' value="<?php echo $row['partyid']; ?>" name='phonenum' readonly />
</td>
<td align='center'><?php echo "<font size=1>".$row['value']."</font>"; ?>
<input type='hidden' value="<?php echo $row['value']; ?>" name='sipvalue' readonly />
<td align='center'><input type='text' value="<?php echo $row['value']; ?>" name='value' readonly />
</td>
</tr>
<?php endwhile;?>
<?php endif;
}
?>
You need to modify your SQL statement to add a joining condition between $table2 and $table3
$sql = "SELECT *
FROM
$table2,
$table3
WHERE
$table2.billdate = '$date'
AND $table3.tel_three LIKE '%$phonenum[$i]%'
AND $table2.something = $table3.something
";