Second form on a PHP page won't run - php

I have two forms on a page. When I run the first, it works as intended, but the second, despite having different form id and all the elements being named, will not (it attempts to run the first form, I think, but with no elements being posted it will return no result).
The second form is in the "Roles" section.
Here is the code - any help is appreciated!
/***** Section: Rights *****/
echo '
<!-- div: Edit -->
<div id="dashboardPanelWrapper">
<div id="sectionArrow"></div>
<div id="dashboardPanelTitle">User rights and privileges</div>
<div id="dashboardPanelContent">';
echo "<div id='DV_simple_wrapper_wide'>";
echo "<table width='60%'><tr><th>Role</th><th>Staff</th><tr>";
$query = "SELECT DISTINCT rightName FROM ".$dbName.".rights WHERE siteLimit='gpvwc' AND rightName!='ADMIN' ORDER BY rightName ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$role=$row[0];
echo "<tr><td>$role</td><td>";
// $query2= "SELECT userId FROM ".$dbName.".rights WHERE rightName='$role' AND siteLimit='gpvwc'";
$query2 = "SELECT CONCAT (u.firstName, ' ',u.lastName) AS username, r.head FROM ".$dbName.".rights r LEFT JOIN ".$dbName.".users u ON r.userId=u.id WHERE r.rightName='$role' AND r.siteLimit='gpvwc' ORDER BY r.head DESC, username ASC";
$result2 = mysql_query($query2);
while ($row = mysql_fetch_row($result2)) {
$name=$row[0];
$head=$row[1];
if ($head=='1') { $name="<b>$name, </b>"; }
if ($head=='0') { $name="$name, "; }
echo "$name";
}
echo "</td></tr>";
}
echo "</table>";
echo "<form id='1' action='' method='post'>";
$usersAsArray = $user->listUsers($banned=false);
echo '<div id="defButtonWrapperH">';
echo '<select id="DriverAppealEvent" class="defSelectV" style="min-width: 70px; margin-bottom: 10px;" onchange="submitTarget(this.value);">';
echo '<option value="0">--</option>';
foreach ($usersAsArray as $key => $value) {
echo '<option value="'.$key.'"';
if (isset($target) && $target == $key)
echo 'selected';
echo '>'.$value.'</option>';
}
echo '</select>';
echo '</div>';
echo '<p> </p>';
echo '<p> </p>';
$userToEdit = false;
if ($target) {
$userToEdit = $user->userToView($target);
// Check if any rights given for this user and update form if any
$query = "SELECT u.*, r.rightName, r.countryLimit, r.siteLimit, r.isActive, r.head FROM ".$dbName.".users u
LEFT JOIN ".$dbName.".rights r ON r.userId=u.id WHERE u.id=".$target;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($row['rightName'] != '') {
$userToEdit['rights'][] = array(
'rightName' => $row['rightName'],
'rightCountryLimit' => $row['countryLimit'],
'rightSiteLimit' => $row['siteLimit'],
'rightIsActive' => $row['isActive'],
'rightHead' => $row['head']
);
}
}
mysql_free_result($result);
// If the user has rights then write a table with all them plus options to revoke
if (!empty($userToEdit['rights'])) {
drawUserRightsTable($userToEdit);
}
echo "</form>";
// Draw selector with rights here so we can add new rights to this user
$useradd=$userToEdit['id'];
echo "<form id='addadmin' action='$RKP/kernel/lib/php_lib/action/AC_Admins.php?op=add&user=$useradd' method='post'>";
echo "Role: <select name='role'>";
$query = "SELECT DISTINCT rightName FROM ".$dbName.".rights WHERE rightName!='ADMIN' ORDER BY rightName ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$righttoadd=$row[0];
echo "<option value='$righttoadd'>$righttoadd</option>";
}
echo "</select></br>";
echo "Head: <input type='radio' name='head' value='0' checked> No <input type='radio' name='head' value='1'> Yes";
echo "<p> </p>";
MODW_Buttons_Button(Normal,Normal,Normal,Normal,None,$RKP,$id,BGenSu,$intern,$intcont);
echo "</form>";
//echo '<pre>';print_r($userToEdit);echo '</pre>';
}
echo "</div>";
echo ' </div>
</div>';
/***** Section: Roles *****/
echo '
<!-- div: Edit -->
<div id="dashboardPanelWrapper">
<div id="sectionArrow"></div>
<div id="dashboardPanelTitle">Disciplinary Committee Roles</div>
<div id="dashboardPanelContent">';
echo "<div id='DV_simple_wrapper_wide'>";
echo "<table width='60%'><tr><th>Series</th><th>Staff</th><th> </th><tr>";
$query = "SELECT id, compName FROM ".$dbName.".competitions WHERE active='1' AND id!='10' ORDER BY id ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$compid=$row[0];
$compName=$row[1];
echo "<tr><td><b>$compName</b></td><td>";
// $query2= "SELECT userId FROM ".$dbName.".rights WHERE rightName='$role' AND siteLimit='gpvwc'";
$query2 = "SELECT CONCAT (u.firstName, ' ',u.lastName) AS username, r.role, u.id, r.series FROM ".$dbName.".DC_roles r LEFT JOIN ".$dbName.".users u ON r.user=u.id WHERE r.series='$compid' ORDER BY username ASC";
$result2 = mysql_query($query2);
while ($row = mysql_fetch_row($result2)) {
$name=$row[0];
$role=$row[1];
$userid=$row[2];
$seriesid=$row[3];
if ($role=='1') { $name="<i>$name</i>"; }
if ($role=='0') { $name="$name"; }
echo "$name <a href='$RKP/kernel/lib/php_lib/action/AC_Admins.php?op=DelDCRights&user=$userid&comp_id=$seriesid'><b>X</b></a></br>";
}
echo "</td></tr>";
}
echo "</table>";
echo "</div>";
echo "<form id='dcroles' action='$RKP/kernel/lib/php_lib/action/AC_Admins.php?op=AddDCRights' method='post'>";
echo "User: <select id='userDC' name='userDC'>";
$query1 = "SELECT id, firstName, lastName FROM ".$dbName.".users ORDER BY lastName ASC, firstName ASC";
$result1 = mysql_query($query1);
while ($row = mysql_fetch_row($result1)) {
$DCuserId=$row[0];
$DCfirstName=$row[1];
$DClastName=$row[2];
echo "<option value='$DCuserId'>$DClastName, $DCfirstName</option>";
}
echo "</select></br>";
echo "</br>";
echo "Series: <select id='seriesDC' name='seriesDC'>";
$query = "SELECT id, compName FROM ".$dbName.".competitions WHERE active='1' AND id!='10' ORDER BY id ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$DCcompId=$row[0];
$DCcompName=$row[1];
echo "<option value='$DCcompId'>$DCcompName</option>";
}
echo "</select></br>";
echo "Third Checker: <input type='radio' id='head' name='head' value='0' checked> No <input type='radio' name='head' value='1'> Yes</br>";
echo "<input type='submit' value='Submit'>";
echo "</form>";

Related

Send multiple select data to database

i have one html table that integrates to tables from my database. What i want to do is send the data from the html select (max 2 options) to another table, but i also want to insert the "id","nome" "praia", "turno" and the day". Can someone help? If u feel that my post misses information let me know in the comments and i share that information
what i am getting
example of what i want
Form that i have to generate the days in the table:
<form method="post" name="rangee">
<label> Insira as datas </label>
<?php
// escolher os dias que vão aparecer na tabela
$sql_query = "SELECT * FROM tb_dias";
$resultset = mysqli_query($conn, $sql_query) or die("database error:" . mysqli_error($conn));
echo "<select name='dia1' size='1' class='form-select form-select-sm'>";
echo "<option value='' disabled selected hidden> Dias </option>";
while ($re = mysqli_fetch_assoc($resultset))
{
$dia1 = $re['dia'];
$id1 = $re['id_dia'];
echo "<option value=$id1>$dia1</option>";
}
?>
</select>
<?php
$sql_query = "SELECT * FROM tb_dias";
$resultset = mysqli_query($conn, $sql_query) or die("database error:" . mysqli_error($conn));
echo "<select name='dia2' size='1' class='form-select form-select-sm'>";
echo "<option value='' disabled selected hidden> Dias </option>";
while ($re = mysqli_fetch_assoc($resultset))
{
$dia2 = $re['dia'];
$id2 = $re['id_dia'];
echo "<option value=$id2>$dia2</option>";
}
?>
</select>
<input type="submit" name="enviar" class="alertButton">
</form>
Form that contains my html table:
<form method="POST" action="select.php">
<table class="table-responsive table-striped table-bordered" id="example">
<thead>
<tr>
<th>Id</th>
<th>Nome Praia</th>
<th>Turno</th>
<?php
$x = 0;
$dias = array();
while ($row = mysqli_fetch_assoc($resultsett))
{
echo "<th>" . $row['dia'] . "</th>";
$dia = $row['dia'];
$id_dia = $row['id_dia'];
array_push($dias, $id_dia);
$x++;
}
?>
</tr>
</thead>
<tbody>
<?php
$sql_query = "SELECT * FROM tb_praia";
$resultset = mysqli_query($conn, $sql_query) or die("database error:" . mysqli_error($conn));
while ($res = mysqli_fetch_assoc($resultset))
{
$id_praia = $res['id_praia'];
$nome_praia = $res['nome_praia'];
$turno = $res['turno'];
?>
<tr id="<?php $id_praia; ?>">
<td> <?php echo $id_praia; ?></td>
<td><?php echo $nome_praia; ?> </td>
<td><?php echo $turno; ?></td>
<?php for ($i = 0;$i < $x;$i++)
{
if ($id_praia % 2 == 0){
$query = "SELECT tb_nadadores.id_nadador, nome from tb_disponibilidade inner JOIN
tb_nadadores on tb_disponibilidade.id_nadador=tb_nadadores.id_nadador
where id_dia = $dias[$i] and Tarde=1 order by id_nadador ASC";
}else{
$query = "SELECT tb_nadadores.id_nadador, nome from tb_disponibilidade inner JOIN
tb_nadadores on tb_disponibilidade.id_nadador=tb_nadadores.id_nadador
where id_dia = $dias[$i] and Manhã=1 order by id_nadador ASC ";
}
$resposta = mysqli_query($conn, $query);
echo (
'<td>
<select name="nadadores[]" size="1" class="form-select multiple-select" multiple>
<br>'
);
if (mysqli_num_rows($resposta) > 0)
{
while ($teste = mysqli_fetch_assoc($resposta))
{
$nadador = $teste['nome'];
$id_nadador = $teste['id_nadador'];
echo "<option value=$id_nadador>$nadador</option>";
}
echo '</select>';
}
else{
echo 'Não foram encontrados resultados!';
}
echo "<input type='hidden' name='dias[]' value=$dias[$i] >";
echo "<input type='hidden' name='turno' value=$turno >";
echo "<input type='hidden' name='id_praia' value=$id_praia >";
echo "<input type='hidden' name='nome_praia' value=$nome_praia>";
}
}
?>
</tr>
</tbody>
</table>
<input type="submit" name="enviar" value="Enviar">
</form>
Select.php
<?php
include_once ("db_connect.php");
if(isset($_POST['enviar'])){
$nadadores_nomes = $_POST['nadadores'];
$id_praia = $_POST['id_praia'];
$nome_praia = $_POST['nome_praia'];
$turno = $_POST['turno'];
$dias = $_POST['dias'];
$dia = implode(",",$dias);
$nadadores= implode(",",$nadadores_nomes);
for ($i = 0; $i<=$dia; $i++){
for($j=1;$j<=2;$i++){
echo "Os nadadores com ids : " .$nadadores[$j]. " vao trabalhar na praia: " .$id_praia. " no turno " .$turno. " no dia" .$dia[$i];
}
}
}
?>

How do I create an edit-option for each row in a table?

I am using the following code to display certain rows from my database table:
<?php
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'Error';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
$db = include "connect2db.php";
$query = "select * from notes where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo '<p>Number of rows found: '.$num_results.'</p>';
for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
echo '<i>';
echo stripslashes($row['date']);
echo '</i><br /> ';
echo '<b>';
echo stripslashes($row['notetitle']);
echo '</b><br /> ';
echo stripslashes($row['note']);
echo '<br /><br /> ';
echo '</p>';
}
$result->free();
$db->close();
?>
Now I would like to display an edit-link for each row displayed, that can open a new page in which it is possible to edit a specific row. I already have the code that lets you edit the row:
<?php
if ($_REQUEST['save']=="Save") { // is data submitted?
// create variables
$noteid = $_REQUEST['noteid'];
$coursename = $_REQUEST['coursename'];
$notetitle = $_REQUEST['notetitle'];
$note = $_REQUEST['note'];
$query = "UPDATE notes SET ";
$query .= "coursename='$coursename', ";
$query .= "notetitle='$notetitle', ";
$query .= "note='$note' ";
$query .= "WHERE noteid='$noteid'";
$result = $db->query($query);
} elseif ($_REQUEST['delete']=="Delete") { // is data to be removed?
$noteid = $_REQUEST['noteid'];
$query="DELETE FROM notes WHERE noteid='$noteid'";
$result = $db->query($query);
}
?>
<div class="formular">
<div class="row1">
<p>Id</p>
<p>Notetitle</p>
<p>Note</p>
</div>
<?php
$query = "SELECT * FROM notes ORDER BY noteid DESC";
$result = $db->query($query);
while ($row = mysqli_fetch_array($result)) {
echo "<form ".$_SERVER['PHP_SELF']." name='edit-form' method='post' class='row1'>\n";
echo "<p class='align_top padding_top'>".$row['noteid']."<input type='hidden' name='noteid' value='".$row['noteid']."' /></p>\n";
echo "<p class='align_top'><input type='text' name='notetitle' value='".$row['notetitle']."' /></p>\n";
echo "<p><textarea name='note' rows='10' cols='50'>".$row['note']."</textarea></p>\n";
echo "<p><input type='submit' name='save' value='Save' /></p>";
echo "<p><input type='submit' name='delete' value='Delete' /></p>";
echo "</form>\n";
}
echo '</div>';
$result->free();
$db->close();
?>
What I am struggling with is how to display an edit-link for each row that lets you open a page where you can edit/delete the content of only that row.
I hope someone can help, I am very new at this.
Thank you!
Add a button next to each row that opens an edit page (or modal) with the id inside, example: <button onclick="edit('randomId')">Edit RandomId </button>
You could implement something different that accepts the unique id of that specific row and open a new page or modal with it.

Session variable and Dynamic Pagination in php

<form action='movies.php' method='POST'>
Language: <select name="language">
<option selected>hindi</option>
<?php
require("config.php");
$result="SELECT language FROM movies";
$q = mysqli_query($conn,$result) or die(mysql_error());
while ($row=mysqli_fetch_array($q)) {
$s1=$row["language"];
echo "<option>
$s1
</option>";
}
echo "<br>"
?>
</select>
<br /> <br />
<input type='submit' value='Submit' />
</form>
<?php
$lang=#$_POST['language'];
$_SESSION["lang1"]=$lang;
/*
if($lang){
$sql = "SELECT name,language FROM movies WHERE language='$lang'";
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result)>0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<div class="query"> <img src="images\tiles\bb.jpg"> ';
echo "<h3> " . $row["name"]."</h3>". "<br>";
echo "</div>";
}
} else {
echo "0 results";
}
}
*/
$page=#$_GET['page'];
if($page==""|| $page=="1")
{
$page1=0;
}
else{
$page1=($page*3)-3;
}
$sql = "SELECT name,language FROM movies WHERE language='". $_SESSION['lang1']."' limit $page1,3 ";
$result = mysqli_query($conn,$sql);
$a= mysqli_num_rows($result);
while ($list=mysqli_fetch_array($result))
{
echo $list['name'] . " : " . $list['language'] . "<br />";
}
$sql = "SELECT name,language FROM movies WHERE language='$lang'";
$result = mysqli_query($conn,$sql);
$a= mysqli_num_rows($result);
$numrows=$a;
$rowsperpage=3;
$totalpages= ceil($numrows/$rowsperpage);
echo "</br>";
for($b=1;$b<=$totalpages;$b++)
{
?><?php echo $b." ";?> <?php
}
?>
I get proper output on movies.php which is the first 3 rows from database,but when i click on the dynamically created pagination link like movies.php?page=2 then there is no output on this page.This code works fine if i manually set the
$_SESSION["lang1"]="English"; then i get proper output but when i take input from the form it doesnt work.

get user selected option var from $_post - php

<script>
//this script show / hide lanes depend on user school choice
$(document).ready(function () {
toggleFieldsA();
toggleFieldsB();
toggleFieldsC();
toggleFieldsD();
toggleFieldsE();
//this will call our toggleFields function every time the selection value of School field changes
$("#school").change(function () {
toggleFieldsA();
toggleFieldsB();
toggleFieldsC();
toggleFieldsD();
toggleFieldsE();
});
});
function toggleFieldsA() {
if ($("#school").val() == 'School of Economics')
$("#a").show();
else
$("#a").hide();
}
function toggleFieldsB() {
if ($("#school").val() == 'School of Computer Science')
$("#b").show();
else
$("#b").hide();
}
function toggleFieldsC() {
if ($("#school").val() == 'School of Behavioral Sciences')
$("#c").show();
else
$("#c").hide();
}
function toggleFieldsD() {
if ($("#school").val() == 'School of Government and Politics')
$("#d").show();
else
$("#d").hide();
}
function toggleFieldsE() {
if ($("#school").val() == 'School of Nursing')
$("#e").show();
else
$("#e").hide();
}
</script>
<!---this part is course registration form using jquery mobile, javascript, html, and php---->
</head>
<body>
<?php
if (!empty($_POST)) {
//getting other details from the order form (later using files - now only demo capabilities)
$school_name = $_POST[school_name];
echo $school_name;
$lane_name = $_POST[lane_name];
echo $lane_name;
$year = $_POST[year];
echo $year;
} else {
?>
<div id='school_div'>
<span><label>School</label></span>
<?php
$sql = "SELECT school_name FROM school";
$result = mysql_query($sql);
echo "<select id='school' name='school_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['school_name'] ."'>" . $row['school_name'] ."</option>";
}
echo "</select>";
?>
</div>
<!---End of School part---->
<div id='a'>
<span><label>Lane</label></span>
<?php
$sql = "SELECT lane_name FROM lane WHERE `lane_school_id` = 1 ORDER BY `lane_name` ASC";
$result = mysql_query($sql);
echo "<select name='lane_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['lane_name'] ."'>" . $row['lane_name'] ."</option>";
}
echo "</select>";
?>
</div>
<div id='b'>
<span><label>Lane</label></span>
<?php
$sql = "SELECT lane_name FROM lane WHERE `lane_school_id` = 2 ORDER BY `lane_name` ASC";
$result = mysql_query($sql);
echo "<select name='lane_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['lane_name'] ."'>" . $row['lane_name'] ."</option>";
}
echo "</select>";
?>
</div>
<div id='c'>
<span><label>Lane</label></span>
<?php
$sql = "SELECT lane_name FROM lane WHERE `lane_school_id` = 3 ORDER BY `lane_name` ASC";
$result = mysql_query($sql);
echo "<select name='lane_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['lane_name'] ."'>" . $row['lane_name'] ."</option>";
}
echo "</select>";
?>
</div>
<div id='d'>
<span><label>Lane</label></span>
<?php
$sql = "SELECT lane_name FROM lane WHERE `lane_school_id` = 4 ORDER BY `lane_name` ASC";
$result = mysql_query($sql);
echo "<select name='lane_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['lane_name'] ."'>" . $row['lane_name'] ."</option>";
}
echo "</select>";
?>
</div>
<div id='e'>
<span><label>Lane</label></span>
<?php
$sql = "SELECT lane_name FROM lane WHERE `lane_school_id` = 5 ORDER BY `lane_name` ASC";
$result = mysql_query($sql);
echo "<select name='lane_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['lane_name'] ."'>" . $row['lane_name'] ."</option>";
}
echo "</select>";
?>
</div>
<!---End of Lane part---->
/*
I am trying to get user selected option from a form but when i try to get the info by using $_post i'am getting the lest option. i am using hide and show to filter the relevant "lanes" base on "school" choice
I'm getting always 'BA in Nursing'
*/
If I have understood your question correctly, you are trying to send the select values to the php script. For this you will need an html form, if you're not interested in A
<form method='POST'><!-- PUT THE PHP that creates the select options here!--></form>
Also, it's best to use quotes to access the $_POST super global array associative indexes:
$school_name = $_POST['school_name'];
$lane_name = $_POST['lane_name'];
$year = $_POST['year'];
Also, you could try print_r($_POST) to see what values you are receiving from the post!
In addition, the mysql extension is deprecated. It would be best if you were to switch to mysqli or PDO instead!

Approve submitted data by admin in php

There is registration form in which country field is there.if user's country is not in drop down list. user can select other at that time display one textbox and user enter their country in textbox.after submit country by user .how to approve the requested country and publish in country drop down list in php.
config.php
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die("Could not connect".mysql_error());
}
mysql_select_db("RateMyProfessor",$con);
?>
Demo.php
<?php
include ("config.php");
$query = "select * from user_details where is_approved='0'";
$result=mysql_query($query);
$i = 1; //counter for the checkboxes so that each has a unique name
echo "<form action='process.php' method='post'>"; //form started here
echo "<table border='1'>
<tr>
<th>UserId</th>
<th>Email</th>
<th>Country </th>
<th>Update</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['UserId'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['Country'] . "</td>";
echo "<td><input type='checkbox' name='check[$i]' value='".$row['UserId']."'/>";
echo "</tr>";
$i++;
}
echo "</table>";
echo "<input type='submit' name='approve' value='approve'/>";
echo "</form>";
mysql_close($con);
?>
process.php
<?php
include_once("config.php");
if(isset($_POST['approve']))
{
if(isset($_POST['check']))
{
foreach ($_POST['check'] as $value){
echo $value;
$sql = "update user_details set is_approved ='1' where UserId = '$value'";
mysql_query($sql) or die (mysql_error());
}
}
}
?>
when admin is approve country from admin side country is copy on country table.
You can insert a new record in country table at the time of approval
for e.g.
<?php
include_once("config.php");
if(isset($_POST['approve']))
{
if(isset($_POST['check']))
{
foreach ($_POST['check'] as $value){
echo $value;
$sql = "update user_details set is_approved ='1' where UserId = '$value'";
mysql_query($sql) or die (mysql_error());
$sql = "select other_country from user_details where UserId = '$value'";
$result = mysql_query($sql) or die (mysql_error());
if($Other_country_name = mysql_fetch_assoc($result))
{
$Other_country_name = $Other_country_name['other_country'];
}
$sql = "insert into country_table set name = '$Other_country_name'";
mysql_query($sql) or die (mysql_error());
}
}
}
?>
I have not implemented conditions. please do it by yourself

Categories