i have created a login system where i can login as a admin, or as a user (employer). If i'm logged in as a admin, on the next page i can update, delete or create a new employer, and if i'm logged in as a employer a didn't have that options. This works fine, but today when i'm logged in as admin a don't have that permission and i got a message: You can't create a new user (this is the message that i have posted in else statement).
This is my homepage.php script. Any help?
<?php
require_once("connection.php");
$user_id = $_SESSION['userid'];
$role = $_SESSION['role'];
$sql = "SELECT * FROM login";
$stmt = $conn->query($sql);
?>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href="#"><?php echo $role ?></a>
</div>
<div class="container">
<?php if($role == 'admin') { ?>
<button type="button" class="btn btn-default navbar-btn">New Employee</button>
<?php } else { }?>
<button type="button" class="btn btn-default navbar-btn">Employee</button>
<button type="button" class="btn btn-default navbar-btn">Sign Out</button>
</div>
</nav>
<div class="box">
<div class="col-sm-4 col-md-6 col-md-offset-2">
<table class="table table-hover table-striped table bordered" border="1">
<thead>
<tr>
<th style="width:250px">UserName</th>
<th style="width:250px">User Password</th>
<th style="width:250px">User Role</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($stmt as $row){ ?>
<tr>
<td><?php echo $row['user_name'] ?></td>
<td>*******</td>
<td><?php echo $row['user_role'] ?></td>
<?php if($role == "admin"){ ?>
<td>
<form action="delete.php" name="deleteForm" method="post">
<input type="hidden" name="delete_id" value="<?php echo $row['user_id'] ?>"/>
<button type="submit" name="delete_user" class="btn btn-info">Delete</button>
</form>
</td>
<td>
<form action="update.php" name="updForm" method="post">
<input type="hidden" name="update_id" value="<?php echo $row['user_id'] ?>"/>
<button type="submit" name="update_user" class="btn btn-info">Update</button>
</form>
</td>
<?php } ?>
</tr>
<?php } ?>
<?php if($role == "admin"){ ?>
<form action="add_user.php" method="POST" name="add_user">
<tr>
<td><input type="text" name="username" class="form-control"/></td>
<td><input type="text" name="password" class="form-control"/></td>
<td>
<select name="select_role" class="form-control">
<option value="admin">Admin</option>
<option value="emp">Employee</option>
</selet>
</td>
<td>
<button type="submit" name="sub_user" class="btn btn-danger">Add User</button>
</td>
</tr>
<?php } else{ ?>
<tr>
You can't add a new user!
</tr>
<?php } ?>
</form>
</tbody>
</table>
</div>
</div>
</body>
</html>
where is session_start();
function because without this function how can you get the session variables so please first put the session_start() at top of the file and then check.
Related
One of my html forms is not POSTing data, the submit button respect the action attribute and redirect the page as spected BUT $_POST[] is empty for some reason. could sonebody help me find the issue here?
I already tried using html method POST and even ajax to process the form and submit the data, and theres no case. $_POST[] will allways stay empty (this is the only page that does that, I hava an exact copy of the form but without the GET method and it works fine...
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="nocep-rules.css" rel="stylesheet" type="text/css">
<?php
session_start();
$link = mysqli_connect("localhost", "xxxx", "xxxx", "xxxxxx");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
<?php
if(!isset($_SESSION['logged'])){
header("location: /bubale/login.php");
}
?>
</head>
<body>
<div class="header">
<img class="logo" src="/bubale/img/logo1.png" alt="" />
<img class="foro-title" src="/bubale/img/loja_title.png" alt="" />
</div>
<div class="menu">
<nav class="site-nav">
<ul>
<li>HOME</li>
<li>LOJA</li>
<li>FORUM</li>
<li>CHECKOUT</li>
<li>SAIR</li>
</ul>
</nav>
</div>
<div class="info">
<table width="100%">
<tr>
<td width="20%">
<h2 class="text">USUÁRIO:</h2>
<?php echo $_SESSION['logged']; ?>
<h2 class="text2">PONTOS:</h2>
<?php
$sql5= "Select points from profile where user = '".$_SESSION['logged']."'";
$result5 = mysqli_query($link, $sql5);
if(mysqli_num_rows($result5)==1){
while($row5 = mysqli_fetch_assoc($result5)) {
echo $row5['points'];
}
}
?>
</td>
<td width="30%">
<?php
$sql2= "select * from bolsinhas where user = '".$_SESSION['logged']."' && rev_id = '0'";
$result2 = mysqli_query($link, $sql2);
$count = mysqli_num_rows($result2);
?>
<h2 class="text">BOLSINHAS:</h2>
<?php echo $count; ?>
<h2 class="text2">PRODUTOS:</h2>
<?php
$sql3= "select * from fullsize where user = '".$_SESSION['logged']."' && rev_id = '0'";
$result3 = mysqli_query($link, $sql3);
$count3 = mysqli_num_rows($result3);
echo $count3;
?>
</td>
<td>
<?php
if(!empty($_SESSION["shopping_cart"])) {
$cart_count = count(array_keys($_SESSION["shopping_cart"]));
}else{$cart_count = "0";}
?>
<img id="icon1" src="img/basket.png" title="Compras" ><span id = "count_wrapper"><a id="count">
<?php echo $cart_count; ?></a></span>
<img class="icon" src="img/sale.png" title="Promoção" alt="" >
<img class="icon" src="img/points.png" title="Fidelidade Buba'le" alt="" >
</td>
</table>
</div>
<h1 class="frete">FRETE:</h1>
<div class="wrapper_frete">
<?php
$rua1 = $_GET['1'];
$numero1 = $_GET['2'];
$apt1 = $_GET['3'];
$cep1 = $_GET['4'];
?>
<table id="forma_frete" width="100%">
<tbody>
<th>DADOS PESSOAIS</th>
<th>OOPS!!!</th>
<tr>
<form id="modform" method="POST" action="nocep2.php">
<td width="40%" class="td2">
<table id="nested" width="100%">
<tr>
<td id="td-nested-left" width="30%">
<label class="label-form" for="user">USUÁRIO:</label><br>
<label class="label-form" for="rua">RUA:</label><br>
<label class="label-form" for="numero">NÚMERO:</label><br>
<label class="label-form" for="apt">APT:</label><br>
<label class="label-form" for="cep">CEP:</label><br>
</td>
<td id="td-nested-right">
<input name="user" form="buttons" type="text" maxlenght="20" disabled value="<?php echo $_SESSION['logged']; ?>" /><br>
<input name="rua" form="buttons" type="text" value="<?php echo $rua1; ?>" /><br>
<input name="numero" form="buttons" type="text" value="<?php echo $numero1;?>" /><br>
<input name="apt" form="buttons" type="text" value="<?php echo $apt1; ?>" /><br>
<input name="cep" form="buttons" type="text" value="<?php echo $cep1;?>" />
</td>
</tr>
</table>
<input type="submit" class="refresh" value="ATUALIZAR">
</td>
</form>
<td id="td_mensage">
<h3 id="mensage">-irrelevant text-. </h3>
</td>
</tr>
<tr>
<td id="td_ob" colspan="2">
<h3 id="comentario">OBSERVAÇAÕ:</h3>
<textarea form="buttons" name="observacion" id="text_ob" placeholder="Deixe aqui sua observaçaõ..."></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<h1 class="frete">SUA COMPRA:</h1>
<?php
if(isset($_SESSION["shopping_cart"])){
$total_price = 0;
?>
<?php } ?>
<table class="table">
<tbody>
<tr>
<th></th>
<th>PRODUTO</th>
<th>QUANTIDADE</th>
<th>VALOR UNITARIO</th>
<th>VALOR TOTAL</th>
</tr>
<?php
foreach ($_SESSION["shopping_cart"] as $product){
?>
<tr>
<td id="imgtd"><img src='<?php echo $product["image"]; ?>' width="90" height="80" /></td>
<td><?php echo $product["name"]; ?><br />
<form method='post' action=''>
<input type='hidden' name='code' value="<?php echo $product["code"]; ?>" />
</form></td>
<td><form method='post' action=''>
<input type='hidden' name='code2' value="<?php echo $product["code"]; ?>" />
<?php echo $product["quantity"];?>
</form></td>
<td><?php echo "R$".$product["price"]; ?></td>
<td><?php echo "R$".$product["price"]*$product["quantity"]; ?></td>
</tr>
<?php
$total_price += ($product["price"]*$product["quantity"]);
}
?>
<tr>
<td class="td_tot" colspan="5" align="right"><strong id="total">TOTAL: <?php echo "R$".$total_price; ?></strong></td>
</tr>
</tbody>
</table>
<form method="post" action="contact-venta.php" id="buttons">
<?php
?>
<input type="hidden" name="compras" value="<?php echo print_r($_SESSION["shopping_cart"], TRUE); ?>"/>
<input type="hidden" name="total" value="<?php echo $total_price; ?>">
<input type="submit" id="submit" value="ENVIAR">
</form>
<?php mysqli_close($link); ?>
</body>
</html>
the issue is with the first submit (the one with the value ACTUALIZAR), the form will go to nocep2.php BUT $_POST[] will remain empty .... I posted the entire page just in case there is an issue I'm not seeing....
Your HTML is rather confused.
Firstly, <form> is not a valid element in <tr>. The browser is rendering them outside the table, and separate from your <input>. Move your form tags inside the <td>, or move them outside the <table>
Eg
<table>
<tr>
<td>
<form method="POST">
<input type="text" name="inputName">
<input type="submit">
</form>
</td>
</tr>
</table>
Or, if you need to spread your form over several cells:
<form method="POST">
<table>
<tr>
<td>
<input type="text" name="inputName1">
</td>
<td>
<input type="text" name="inputName2">
</td>
<td>
<input type="submit">
</td>
</tr>
</table>
</form>
Secondly, you're creating a number of <input> elements of type "hidden", each with their own form tags, so they are each part of a different form. Reorder your code so that the hidden elements appear within the same <form> as the rest of your <input>
<html>
<title>Certification</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<?php
date_default_timezone_set("Asia/Muscat");
//echo date_default_timezone_get();
?>
<?php
include('connect-db.php');
$Id = $_GET['Id'];
$result = mysql_query("SELECT * FROM master WHERE IDM=$Id")
or die(mysql_error());
$row = mysql_fetch_array($result);
$Asset_Number = $row['Asset_number'];
$Description2 = $row['Description2'];
$Parent_Verified = $row['Parent_Verified'];
$Make=$row['Make'];
$Model=$row['Model'];
$Serial_Number=$row['Serial_Number'];
$Associated_with=$row['Associated_with'];
$Comment=$row['Comment'];
$Date_of_Manufacture=$row['Date_of_Manufacture'];
$Unit=$row['Physically_Verified_Location'];
if(isset($_POST['submit'])!=""){
$name1=$_FILES['photo']['name'];
$size=$_FILES['photo']['size'];
$type=$_FILES['photo']['type'];
$temp=$_FILES['photo']['tmp_name'];
$ext = end((explode(".", $name1)));
$date = date('Y-m-d H:i:s');
$caption1=$_POST['caption'];
$link=$_POST['link'];
$Inspection_type = $_POST['Inspection_type'];
$Inspection_comp = $_POST['Inspection_comp'];
$Inspection_Date = $_POST['Inspection_Date'];
$Expiry_Date = $_POST['Expiry_Date'];
$name = $Asset_Number.'-'.$Inspection_type.'-'.$Inspection_comp.'-'.$Inspection_Date.'-'.$Expiry_Date.'.' . end(explode(".",$_FILES['photo']['name']));
move_uploaded_file($temp,"/files/".$name);
if(mysql_query("INSERT INTO upload (name,date,Asset_Number,Serial_Number,Inspection_type,Inspection_comp,Inspection_Date,Expiry_Date,id_m)VALUES ('$name','$date','$Asset_Number','$Asset_sno','$Inspection_type','$Inspection_comp','$Inspection_Date','$Expiry_Date','$Id')"))
{
header('location:certificate.php');
Exit;
}
else{
die(mysql_error());
}
}
?>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#WellCAT td.exdate').each(function(){
if ($(this).text() ==cal.getTime();') {
$(this).css('background-color','#ff9933');
}
else $(this).css('background-color','#99ccff');
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<?php include('dbcon.php'); ?>
<div class="col-sm-12 col-md-12 col-lg-12" style="background-color:#33ccff;">
<H4><U><CENTER>CERTIFICATE UPDATE</CENTER></U> </H1>
</div>
</head>
<body>
<div class="container fluid">
<div class="row">
<form class="form-inline" enctype="multipart/form-data" action="" id="wb_Form1" name="form" method="post">
<input type="hidden" name="Id" value="<?php echo $Id; ?>"/>
<div class="col-sm-4" style="background-color:lavender;">
<label class="form-control">ID</label><label class="form-control"><?php echo $Id; ?></label><br>
<label class="form-control">Asset Number</label><label class="form-control"><?php echo $Asset_Number; ?></label><br>
<label class="form-control">Description</label><label class="form-control"><?php echo $Description2; ?></label><br>
<label class="form-control">Parent</label><label class="form-control"><?php echo $Parent_Verified; ?></label><br>
<label class="form-control">Make</label><label class="form-control"><?php echo $Make; ?></label><br>
<label class="form-control">Model</label><label class="form-control"><?php echo $Model; ?></label><br>
<label class="form-control">Serial Number</label><label class="form-control"><?php echo $Serial_Number; ?></label><br></div>
<div class="col-sm-4" style="background-color:lavender;"><br><br>
<label class="form-control">Associated with</label><label class="form-control"><?php echo $Associated_with; ?></label><br>
<label class="form-control">Comment</label><label class="form-control"><?php echo $Comment; ?></label><br>
<label class="form-control">Date of Manufacture</label><label class="form-control"><?php echo $Date_of_Manufacture; ?></label><br>
<label class="form-control">Unit</label><label class="form-control"><?php echo $Unit; ?></label><br></div>
<div class="col-sm-4" style="background-color:lavender;">
<br><br>
<label class="form-control">Inspection type</label><select class="form-control" name="Inspection_type" required="required"> <option value=""></option><br>
<option value="Major">Major Inspection</option>
<option value="Intermediate">Intermediate Inspection</option>
<option value="Other">Other Inspection</option>
</select>
<label class="form-control">Inspection Company</label><input type="text" class="form-control" name="Inspection_comp"><br>
<label class="form-control">Inspection Date</label><input type="date" class="form-control" name="Inspection_Date"><br>
<label class="form-control">Expiry Date</label><input type="date" class="form-control" name="Expiry_Date">
<div class="alert alert-danger" role="alert">
Please choose file here.....(Maximum allowed file size 10Mb)
</div>
<input type="file" class="form-control"name="photo" id="photo" required="required">
<input type="submit" class="btn btn-danger" value="SUBMIT" name="submit">
</div>
</form>
</div>
</div>
<div class="col-md-18">
<div class="container-fluid" style="margin-top:0px;">
<div class = "row">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<form method="post" action="deletefile.php" >
<table id="WellCAT" cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>ID</th>
<th>Asset Number</th>
<th>Inspection Type</th>
<th>Inspection Company</th>
<th>Inspection Date</th>
<th>Expiry Date</th>
<th>FILE NAME</th>
<th>Date</th>
<th>Download</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
$query=mysql_query("select * from upload WHERE id_m=$Id")or die(mysql_error());
while($row=mysql_fetch_array($query)){
$id=$row['id'];
$Asset_Number=$row['Asset_Number'];
$Inspection_type=$row['Inspection_type'];
$Inspection_comp=$row['Inspection_comp'];
$Inspection_Date=$row['Inspection_Date'];
$Expiry_Date=$row['Expiry_Date'];
$name=$row['name'];
$date=$row['date'];
?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['Asset_Number'] ?></td>
<td><?php echo $row['Inspection_type'] ?></td>
<td><?php echo $row['Inspection_comp'] ?></td>
<td><?php echo $row['Inspection_Date'] ?></td>
<td><?php echo $row['Expiry_Date'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['date'] ?></td>
<td>
<span class="glyphicon glyphicon-paperclip" style="font-size:20px; color:blue"></span>
</td>
<td>
<span class="glyphicon glyphicon-trash" style="font-size:20px; color:red"></span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('#WellCAT').DataTable();
});
</script>
I have two issues..
1 - Every time refresh my page the code is uploading a same date to the table.
I have tried redirecting to header location to header... but it still having the same issue..
2 - When i am moving the this file (file upload.php) to another folder in my directory, the downloading function will not work.
isset function return true or false depend on the variable is set or not.
in your code if(isset($_POST['submit'])!="") is checking is submit of post is set , which return false, then you try to compare with not equal empty string , which return true ..
if(isset($_POST['submit'])!="")
if(false != "") // isset($_POST['submit']) , when post is not set
if(true)
I think you get the point ..
you can do by checking is post of submit set or not, do not need any extra logic
if(isset($_POST['submit'))
will do the job.
Well, your condition is wrong.
Change the condition to do this.
From:
if(isset($_POST['submit'])!=""){
To:
if(isset($_POST['submit')){
You should try changing following line:
if(isset($_POST['submit'])!="")
To:
if(isset($_POST['submit']) && $_POST['submit'] != ""){
In my code there is a table that displays search results. When a user clicks on the radio button and then clicks on the modify item button, it should open up the modal with information about the item gotten from the database based on item id. Currently the modal opens up with information about all the items on the result page, not just the item selected using the radio button I don't know why it's not taking the value of the radio button and displaying everything.
Here's my code:
Controller:
class Search extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('searchModel');
$this->load->model('itemModal');
}
public function index(){
$this->load->view('base');
$this->load->view('search');
}
public function displayItem(){
//modify item button is clicked
if(isset($post['#modifyItem'])){
//radio button is checked
if(isset($post['id'])){
//value from the radio button
$id=$this->input->post("id");
$data['results'] = $this->itemModal->get_item_by_id($id);
//open modal with the results
$this->load->view('searchResult/#modifyItem',$data);
}
}
}}
Model:
<?php
class ItemModal extends CI_Model {
function __construct(){
parent::__construct();
}
function get_item_by_id($id){
$this->db->select('*');
$this->db->where('inventoryID =',$id);
// Execute the query.
$query = $this->db->get('inventory');
// Return the results.
return $query->result_array();
}
}
View:
<body>
<h1><center>Item List</center></h1>
<hr>
<div class="container">
<form method="post" action="<?php echo site_url('itemView/viewItems'); ?>">
<table>
<tr>
<th><center><input type="radio" name="id"></center></th>
<th>Inventory ID</th>
<th>Master Code</th>
<th><center>Item Name</center></th>
<th>Color Name</th>
<th><center>Location</center></th>
<th><center>Checkout Allowed</center></th>
</tr>
<?php foreach($results as $rows):?>
<tr>
<td><input type="radio" name="id" value="<?php echo $rows['inventoryID'] ?>" <?php echo set_radio('id', '$rows[inventoryID]'); ?>></td>
<td><?php echo $rows['inventoryID'] ?></td>
<td><?php echo $rows['masterCode'] ?></td>
<td><?php echo $rows['itemName'] ?></td>
<td><?php echo $rows['colorName'] ?></td>
<td><?php echo $rows['location'] ?></td>
<td><input type="checkbox" <?php if($rows['checkoutAllowed'] == 'Yes') echo " checked='checked' "; ?>></td>
</tr>
<?php endforeach; ?>
</table>
</form><br><br>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modifyItem" data-title="Modify an Item" onclick="<?php echo site_url("Search/displayItem"); ?>">Modify an Item</button>
<!-- Modify an Item Modal -->
<div id="modifyItem" class="modal fade">
<div class="modal-dialog">
<form action="<?php echo site_url("Search/updateItem"); ?>" method='POST'>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modify an Item</h4>
</div>
<div class="modal-body">
<form role="form">
<?php foreach($results as $rows):?>
<table>
<tr>
<td><input type="text" name="rfid" value="<?php echo $rows['inventoryID']?>"/></td>
<td><input type="text" name="itemCode" placeholder="Item Code"/></td>
<td><input type="text" name="masterCode" value="<?php echo $rows['masterCode']?>"/></td>
</tr>
<tr>
<td><input type="text" name="itemName" value="<?php echo $rows['itemName']?>" /></td>
<td><input type="text" name="colorCode" placeholder="Color Code" /></td>
<td><input type="text" name="colorName" placeholder="Color Name" /></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Location" /></td>
<td><input type="text" name="makelocation" placeholder="Location Made"/></td>
<td><input type="text" name="itemCategory" placeholder="Item Category" /></td>
</tr>
<tr>
<td><input type="text" name="materialDescription" placeholder="Material Description" /></td>
<td><input type="text" name="supplier" placeholder="Supplier/Vendor" /></td>
<td><input type="text" name="checkoutAllowed" placeholder="Checkout Allowed" /></td>
</tr>
</table>
<div class="row personal-info">
<div class="col-sm-4">
<div class="form-group">
<textarea name="itemDescription" placeholder="Insert information regarding the weather this item is suitable for and where it is used"></textarea>
<textarea name="Comments" placeholder="Additional Coments on the Item"></textarea>
</div>
</div>
</div>
<?php endforeach; ?>
</form>
</div>
<div class="modal-footer" style="text-align:center;">
<input type="submit" class="btn btn-primary" name="modifyItem" value="Modify Item">
</div>
</div>
</form>
</div>
</div>
<!-- Modify an Item Modal -->
</div></body>
Why you load two time foreach its not good way when multiple record on database for load all data its take to more time use display record pagination library of codei-gniter and for edit make dynamic model code using ajax
your function in controller 'displayItem' write code for modify item and make edit form html
<table>
<tr>
<th><center><input type="radio" name="id"></center></th>
<th>Inventory ID</th>
<th>Master Code</th>
<th><center>Item Name</center></th>
<th>Color Name</th>
<th><center>Location</center></th>
<th><center>Checkout Allowed</center></th>
</tr>
<?php foreach($results as $rows):?>
<tr>
<td><input type="radio" name="id" value="<?php echo $rows['inventoryID'] ?>" <?php echo set_radio('id', '$rows[inventoryID]'); ?>></td>
<td><?php echo $rows['inventoryID'] ?></td>
<td><?php echo $rows['masterCode'] ?></td>
<td><?php echo $rows['itemName'] ?></td>
<td><?php echo $rows['colorName'] ?></td>
<td><?php echo $rows['location'] ?></td>
<td><input type="checkbox" <?php if($rows['checkoutAllowed'] == 'Yes') echo " checked='checked' "; ?>></td>
</tr>
<?php endforeach; ?>
</table>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modifyItem" data-title="Modify an Item" onclick="updateItem();">Modify an Item</button>
<!--Bootstrap model for edit start-->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content" id="model_data">
//append form data here
</div>
</div>
</div>
<!--Bootstrap model for edit end-->
<script>
function updateItem()
{
var CHECKBOXIDS = PASS_CHECKBOX_CHECKEDVALUE;
$('#model_data').html('');
$.ajax({
url: "<?php echo site_url('Search/displayItem');?>",
type: "POST",
dataType: "html",
data: {'<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>', 'checkids': CHECKBOXIDS, },
catch : false,
success: function (data) {
$('#model_data').append(data);
}
});
}
Here is the code. The "surveys" are generated elsewhere. I need validation that a radio button is clicked in each group of answers. The number of answers and answer groups will be variable.
<div id="main">
<div class="container">
<!-- display a table of surveys -->
<h2><?php echo $survey['title']; ?></h2>
<form class="survey" name="take_survey" action="./take_survey" method="post">
<table class="table table-hover">
<input type="hidden" name="survey" value="<?php echo $survey['id'] ?>" />
<tr>
<th>Question</th>
<th>Response</th>
</tr>
<?php foreach ($questions as $question) : ?>
<tr>
<td><?php echo $question['question']; ?></td>
<td></td>
</tr>
<?php foreach ($answers as $answer) : ?>
<?php if ($answer['question_id'] == $question['id']) : ?>
<tr>
<td> <?php echo $answer['answer']; ?></td>
<td><input type="radio" name="question_<?php echo $question['id']?>" value="<?php echo $answer['id'] ?>"></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</tr>
</table>
<div class="eventButtons">
<input class="btn btn-default" type="submit" name="submit" id="submit" value="Save">
<input class="btn btn-default" type="reset" name="reset" id="reset" value="Clear" class="btn">
</div>
</form>
</div>
</div>
I just want to ask on how can I create a dynamic ID in the fields that I have loaded.
Here is my view:
<div id="content">
<form action="" method="POST">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" onclick="location.reload();"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
</div>
<div id="div1">
<fieldset>
<legend><?php // echo $tablename; ?></legend>
<table id="table_main">
<tr>
<th>Column Name:</th>
<th>Type:</th>
<th>Length/Values:</th>
</tr>
<?php foreach($updatemaintenance1 as $field) { ?>
<tr>
<td><input type="text" value="<?php echo $field->name; ?>" style="width: 80%"/></td>
<td>
<select style="width: 80%">
<option><?php echo $field->type; ?></option>
<option>INT</option>
<option>VARCHAR</option>
<option>TEXT</option>
<option>DATE</option>
</select>
</td>
<td><input type="text" value="<?php echo $field->max_length; ?>" style="width: 100%"/></td>
</tr>
<?php } ?>
<tr>
<?php //foreach ($tablename as $row1) { ?>
<td><input type="text" id="ninja79" name="ninja79" value="<?php echo $table_name1; ?>"/></td>
<?php// } ?>
</tr>
</table>
<div class="modal-footer">
<button type="button" class="btn_editinventorytype btn-info btn-sm">Update</button>
<button type="button" class="btn_deleteinventorytype btn-danger btn-sm">Delete</button>
</div>
</fieldset>
</div>
</form>
</div>
As you can see I have a foreach loop where I placed all the values from my database. What I want is to generate an ID on the textboxes and the selectbox. And I have this code in the model where I can modify the loaded fields.
Here is my model:
public function modify_table($modify){
$fields = array($modify[''] = array('name' => $modify[''],
'type' => $modify[''],
'constraint' => $modify['']),
);
$this->dbforge->modify_column($modify['ninja79'], $fields);
}
This codes are not as simple as 'SELECT * FROM 'tablename' I mean I'm talking about modifying tables in the database, so please could you help me? All I want is to have a dynamic ID in my model and in my view. I have no idea on how to code that. This is confusing so PLEASE I need your help. Thank you in advance!