Why is the value of id getting randomized? - php

My code is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SomuFinance - Personal Finance Manager</title>
<link rel="stylesheet" type="text/css" href="indexStyle.css">
<script src="scripts/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="scripts/jquery.validate.min.js"></script>
<style type="text/css">
#addItemContainer {
background-color: rgba(204,207,232,1);
}
</style>
<script type="text/javascript">
var flag=0;
</script>
</head>
<body>
<form id="list" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="container">
<input type="submit" class="button" name="edit" id="edit" value="Edit" />
<input type="button" class="button" name="delete" value="Delete" />
<input type="hidden" id="action" name="action">
<table id="listDB">
<tr>
<th>Select</th>
<th>ID</th>
<th>Category ID</th>
<th>Shop</th>
<th>Item</th>
<th>Quantity</th>
<th>Unit</th>
<th>Price Based On</th>
<th>MRP</th>
<th>Seller's Price</th>
<th>Last Updated On</th>
</tr>
<?php
$dbc = mysqli_connect('localhost','root','atlantis2016','itemDB')
or die("Error Connecting to Database");
if(isset($_POST['confirmDelete']))
{
if($_POST['action']=='confirmDelete')
{
foreach ($_POST['selected'] as $delete_id)
{
$query = "DELETE FROM grocery WHERE id = $delete_id";
mysqli_query($dbc, $query)
or die('Error querying database.');
}
}
}
$query1 = "SELECT DISTINCT category FROM grocery";
$result1 = mysqli_query($dbc, $query1)
or die("Error Querying Database");
while($row = mysqli_fetch_array($result1))
{
$category = $row['category'];
$query2 = "SELECT * FROM grocery WHERE category='$category' ORDER BY item ASC";
$result2 = mysqli_query($dbc, $query2)
or die("Error Querying Database");
echo '<tr>';
echo '<td class="catHead" colspan=11>'.$category.'</td>';
echo '</tr>';
$catCount=1;
while($inRow = mysqli_fetch_array($result2))
{
$id = $inRow['id'];
$shop = $inRow['shop'];
$item = $inRow['item'];
$qnty = $inRow['quantity'];
$unit = $inRow['unit'];
$price_based_on = $inRow['price_based_on'];
$mrp = $inRow['MRP'];
$sellers_price = $inRow['sellers_price'];
$last_updated_on = $inRow['last_updated_on'];
echo '<tr>';
echo '<td><input type="checkbox" id="selected" value="' . $id . '" name="selected[]" /></td>';
echo '<td>'.$id.'</td>';
echo '<td>'.$catCount.'</td>';
echo '<td>'.$shop.'</td>';
echo '<td class="leftAligned">'.$item.'</td>';
echo '<td>'.$qnty.'</td>';
echo '<td>'.$unit.'</td>';
echo '<td>'.$price_based_on.'</td>';
echo '<td class="pri">₹'.$mrp.'</td>';
echo '<td class="pri">₹'.$sellers_price.'</td>';
echo '<td>'.$last_updated_on.'</td>';
echo '</tr>';
$catCount++;
}
}
?>
</table>
</div>
<div class="dialogBG">
<div id="deleteConfirmDialog" class="dialog">
<div class="closeDialog"></div>
<p>Sure you want to delete the selected Data?</p>
<input type="submit" id="confirmDelete" class="dialogButton" name="confirmDelete" value="Delete" />
<input type="button" id="cancelDelete" class="dialogButton cancelButton" name="cancelDelete" value="Cancel" />
</div>
</div>
</form>
<div class="dialogBG">
<div id="addItemContainer" class="dialog">
<div class="closeDialog"></div>
<h1>Edit Item</h1>
<form id="data" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<?php
if(isset($_POST['action']))
{
if($_POST['action']=='edit')
{
echo '<script>flag=1;</script>';
foreach ($_POST['selected'] as $edit_id)
{
$query = "SELECT * FROM grocery WHERE id = $edit_id";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
break;
}
$inRow = mysqli_fetch_array($result);
$id = $inRow['id'];
$shop = $inRow['shop'];
$category = $inRow['category'];
$item = $inRow['item'];
$qnty = $inRow['quantity'];
$unit = $inRow['unit'];
$price_based_on = $inRow['price_based_on'];
$mrp = $inRow['MRP'];
$sellers_price = $inRow['sellers_price'];
$last_updated_on = $inRow['last_updated_on'];
}
}
?>
<div class="leftAligned">
<div class="inp">
<label for="shop">ID : </label>
<input type="text" id="id" name="id" value="<?php echo $id; ?>" required disabled>
</div> <br>
<div class="inp">
<label for="shop">Shop : </label>
<input type="text" id="shop" name="shop" value="<?php echo $shop; ?>" required>
</div> <br>
<div class="inp">
<label for="category">Category : </label>
<input type="text" id="category" name="category" value="<?php echo $category; ?>" required>
</div> <br>
<div class="inp">
<label for="item">Item : </label>
<input type="text" id="item" name="item" value="<?php echo $item; ?>" required>
</div> <br>
<div class="inp">
<label for="qnty">Quantity : </label>
<input type="text" id="qnty" name="qnty" value="<?php echo $qnty; ?>" required>
</div> <br>
<div class="inp">
<label for="unit">Unit : </label>
<input type="text" id="unit" name="unit" value="<?php echo $unit; ?>" required>
</div> <br>
<div class="inp">
<label for="price_based_on">Price based on : </label>
<select name="price_based_on" id="price_based_on">
<option value="kilos">Kilos</option>
<option value="packet">Packet</option>
<option value="bottle">Bottle</option>
<option value="box">Box</option>
<option value="piece">Piece</option>
</select>
</div> <br>
<div class="inp">
<label for="mrp">MRP (₹) : </label>
<input type="text" id="mrp" name="mrp" value="<?php echo $mrp; ?>" required>
</div> <br>
<div class="inp">
<label for="sellers_price">Seller's Price (₹) : </label>
<input type="text" id="sellers_price" value="<?php echo $sellers_price; ?>" name="sellers_price" required>
</div> <br>
<div class="inp">
<label for="last_updated_on">Last Updated on : </label>
<input type="date" id="last_updated_on" name="last_updated_on" value="<?php echo $last_updated_on; ?>" required>
</div>
</div>
<div class="inp">
<input id="insertButton" type="submit" name="submit" value="Insert">
</div>
<div id="message">
<?php
if(isset($_POST['submit']))
{
echo "<script> alert('$id'); </script>";
$shop = $_POST['shop'];
$category = $_POST['category'];
$item = $_POST['item'];
$qnty = $_POST['qnty'];
$unit = $_POST['unit'];
$price_based_on = $_POST['price_based_on'];
$mrp = $_POST['mrp'];
$sellers_price = $_POST['sellers_price'];
$last_updated_on = $_POST['last_updated_on'];
$result=null;
$query = "UPDATE grocery SET shop='$shop', category='$category', item='$item', quantity='$qnty', unit='$unit', price_based_on='$price_based_on', mrp='$mrp', sellers_price='$sellers_price', last_updated_on='$last_updated_on' WHERE id='$id'";
if(!empty($shop)&&!empty($category)&&!empty($item)&&is_numeric($qnty)&&!empty($unit)&&is_numeric($mrp)&&is_numeric($sellers_price)&&!empty($last_updated_on))
{
$result = mysqli_query($dbc, $query)
or die(mysqli_error($dbc));
}
if($result)
{
echo '<span class="success">Item Edited Successfully!</span>';
}
else
{
echo '<span class="failure">Failed to insert Item.</span>';
}
//header("Refresh:2");
}
?>
<script>
$(document).ready(function(){
$( "#data" ).validate({
rules: {
qnty: {
number: true
},
mrp: {
number: true
},
sellers_price: {
number: true
}
},
messages: {
qnty : {
number: '<br> <span class="failure err">Enter a valid quantity</span>'
},
mrp : {
number: '<br> <span class="failure err">Enter a valid MRP</span>'
},
sellers_price : {
number: '<br> <span class="failure err">Enter a valid Price</span>'
},
}
});
});
</script>
</div>
</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('.button').click(function(event){
if($(this).val()=="Delete")
{
$("#deleteConfirmDialog").show(200).parent(".dialogBG").fadeIn(200);
$("#action").val('confirmDelete');
}
else if($(this).val()=="Edit")
{
event.preventDefault();
$("#action").val('edit');
$("#list").submit();
}
});
if(flag===1)
{
console.log("This shouldn't be there if the page reloads!");
$("#addItemContainer").show(200).parent(".dialogBG").fadeIn(200);
}
$('#confirmDelete').click(function(){
$(".closeDialog").trigger("click");
});
$('#cancelDelete').click(function(){
$("input:checkbox[name='selected[]']").prop('checked', false);
});
$(".closeDialog").click(function (e){
$(this).parent(".dialog").hide('200').parent(".dialogBG").fadeOut('200');
});
$(".cancelButton").click(function (e){
$(this).parent(".dialog").hide('200').parent(".dialogBG").fadeOut('200');
});
});
</script>
<?php
mysqli_close($dbc);
?>
</body>
</html>
Notice that I obtain the id of the first selected element by using the lines:
foreach ($_POST['selected'] as $edit_id)
{
$query = "SELECT * FROM grocery WHERE id = $edit_id";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
break;
}
$inRow = mysqli_fetch_array($result);
$id = $inRow['id'];
Now, I use the id(which is exactly the same as edit_id) thus obtained to access the record in the DB, and show it in the popup.
<div class="leftAligned">
<div class="inp">
<label for="shop">ID : </label>
<input type="text" id="id" name="id" value="<?php echo $id; ?>" required disabled>
</div> <br>
<div class="inp">
<label for="shop">Shop : </label>
<input type="text" id="shop" name="shop" value="<?php echo $shop; ?>" required>
</div> <br>
<div class="inp">
<label for="category">Category : </label>
<input type="text" id="category" name="category" value="<?php echo $category; ?>" required>
</div> <br>
<div class="inp">
<label for="item">Item : </label>
<input type="text" id="item" name="item" value="<?php echo $item; ?>" required>
</div> <br>
<div class="inp">
<label for="qnty">Quantity : </label>
<input type="text" id="qnty" name="qnty" value="<?php echo $qnty; ?>" required>
</div> <br>
<div class="inp">
<label for="unit">Unit : </label>
<input type="text" id="unit" name="unit" value="<?php echo $unit; ?>" required>
</div> <br>
<div class="inp">
<label for="price_based_on">Price based on : </label>
<select name="price_based_on" id="price_based_on">
<option value="kilos">Kilos</option>
<option value="packet">Packet</option>
<option value="bottle">Bottle</option>
<option value="box">Box</option>
<option value="piece">Piece</option>
</select>
</div> <br>
<div class="inp">
<label for="mrp">MRP (₹) : </label>
<input type="text" id="mrp" name="mrp" value="<?php echo $mrp; ?>" required>
</div> <br>
<div class="inp">
<label for="sellers_price">Seller's Price (₹) : </label>
<input type="text" id="sellers_price" value="<?php echo $sellers_price; ?>" name="sellers_price" required>
</div> <br>
<div class="inp">
<label for="last_updated_on">Last Updated on : </label>
<input type="date" id="last_updated_on" name="last_updated_on" value="<?php echo $last_updated_on; ?>" required>
</div>
</div>
The ID and all the relevant details thus far are exactly as they should be.
However, further down, when I try to use the ID to update the record, using the statement
UPDATE grocery SET shop='$shop', category='$category', item='$item',
quantity='$qnty', unit='$unit', price_based_on='$price_based_on',
mrp='$mrp', sellers_price='$sellers_price',
last_updated_on='$last_updated_on'
WHERE id='$id'
somehow the id has changed to the last value of id in the table. So, instead of updating the table's correct record with the updated values, since the id "magically" changes at this point (after the sumbit button has been pressed), the last value of the id appears. I want the id to stay the same as the original id.
Why is this happening and how can I solve this?

Related

How do I display the record before deleting that record?

I wish to display the record to the user that I am deleting in PHP?
I am trying to display the record in a form that I want to delete but only the input type = text values are being displayed and the radio button values are not being displayed?
<?php
require('/home/s3022041/sqlC/dbConnect.php');
if(isset($_POST['search']))
{
$search = mysqli_real_escape_string($connection, $_POST['id']);
$id = $_POST['id'];
$stp1 = preg_replace("/[^a-zA-Z0-9]/", "", $id); //grab only the alphanumerics
$stp2 = strtoupper($stp1); //Make all alphabets uppercase
$stp3 = preg_replace('/\d+/', '',$stp2); //extract the alphabets part
$newsearchid = str_replace($stp3,"-".$stp3."-",$stp2); //put hyphens before and after the alphabet part
$query = "SELECT * FROM cars WHERE Registration_Number = '$newsearchid' ";
$query_run = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($query_run))
{
?>
<form action="delete_process.php" method="POST" class="form">
<h2>Car Registration Form</h2>
<div class="mb-3">
<input type="radio" name="Car" id="Toyota" value=" <?php echo $row['make']; ?>" />
<label for="Toyota" class="form-label">Toyota</label>
<select name="Models[Toyota]" class="form-control" value=" <?php echo $row['model']; ?>">
<option value="">None</option>
<option value="Camri">Camri</option>
<option value="Corolla">Corolla</option>
<option value="Estima">Estima</option>
</select><br>
<input type="radio" name="Car" id="Nissan" value=" <?php echo $row['make']; ?>"/>
<label for="Nissan" class="form-label">Nissan</label>
<select name="Models[Nissan]" class="form-control" value=" <?php echo $row['model']; ?>">
<option value="">None</option>
<option value="Micra">Micra</option>
<option value="roller">roller</option>
<option value="fushe">fushe</option>
</select><br>
<input type="radio" name="Car" id="Mercedez" value=" <?php echo $row['make']; ?>"/>
<label for="Mercedez" class="form-label">Mercedez</label>
<select name="Models[Mercedez]" class="form-control" value=" <?php echo $row['model']; ?>">
<option value="">None</option>
<option value="5series">5series</option>
<option value="x7">x7</option>
<option value="x5">x5</option>
</select><br>
<label for="vehicleidentificationnumber" class="form-label">vehicle identification
number(VIN)</label>
<input type="text" disabled="disabled" name="vehicleidentificationnumber" class="form-control" maxlength=20 value=" <?php echo $row['VIN']; ?>" required >
<br>
<label for="ManufacturingYear" class="form-label">Manufacturing Year</label>
<input type="text" name="Manufacture_Year" class="form-control" maxlength=20 value=" <?php echo $row['Manufacture_Year']; ?>" required >
<label for="Enginesize" class="form-label">Engine size</label>
<input type="text" name="Engine_Size" class="form-control" maxlength=20 value=" <?php echo $row['Engine_Size']; ?>" required>
<label for="TransmissionType" class="form-label">TransmissionType</label><br>
<input type="radio" name="Transmission_Type" id="TransmissionType" value=" <?php echo $row['Transmission_Type']; ?>" />
<label for="Automatic" class="form-label">Automatic</label><br>
<input type="radio" name="Transmission_Type" id="TransmissionType" value=" <?php echo $row['Transmission_Type']; ?>" />
<label for="Manual" class="form-label">Manual</label><br>
<input type="radio" name="Transmission_Type" id="TransmissionType" value=" <?php echo $row['Transmission_Type']; ?>" />
<label for="SemiAutomatic" class="form-label">Semi-Automatic</label><br>
<label for="NoofSeats" class="form-label">No. of Seats</label>
<input type="number" name="NoOfSeats" class="form-control" value="<?php echo $row['NoOfSeats']; ?>" maxlength=20 required>
<label for="Noofdoors" class="form-label">No. of doors</label>
<input type="number" name="NoOfDoors" class="form-control" maxlength=20 value="<?php echo $row['NoOfDoors']; ?>" required>
<label for="Fueltype" class="form-label">Fuel type</label>
<input type="text" name="Fuel_Type" class="form-control" maxlength=20 value=" <?php echo $row['Fuel_Type']; ?>" required>
<label for="Colour" class="form-label">Colour</label>
<input type="text" name="Colour" class="form-control" maxlength=20 value=" <?php echo $row['Colour']; ?>" required>
<label for="RegistrationNumber" class="form-label">Registration Number (use Dublin
registration) </label>
<input type="hidden" disabled="disabled" name="Registration_Number" class="form-control" maxlength=20 value=" <?php echo $row['Registration_Number']; ?>" required>
<label for="Dateoffirstregistration" class="form-label">Date of first registration</label>
<input type="date" name="DateOfRegestration" class="form-control" maxlength=20 value=" <?php echo $row['DateOfRegestration']; ?>" required>
</div>
<button type="submit" name="search" class="btn btn-primary">Delete</button>
</form>
<?php
}
}
else{
echo "<h1> No records found </h1>";
echo "<a href='index.php'>home</a>";
}
?>
</div>
<div class="modal-footer">
</form>
Here I am trying to delete the above record that is displayed but it says deleted successfully but when I go and check the records it is not deleted it's still there?
<?php
require('/home/s3022041/sqlC/dbConnect.php');
if(isset($_POST['search']))
{
$search = mysqli_real_escape_string($connection, $_POST['search']);
$id = $_POST['Registration_Number'];
$query = "DELETE FROM `cars` WHERE Registration_Number='$id' ";
$query_run = mysqli_query($connection, $query) or die ("not done");
if($query_run)
{
echo "<h1> deleted successfully</h1>";
echo "<a href='index.php'>home</a>";
}
else
{
echo "<h1> not deleted </h1>";
echo "<a href='index.php'>home</a>";
echo 'Error! ' . mysqli_error($connection);
}
}
Change
1. Form
<input type="radio" name="Car" id="Toyota" value="<?=$row['make']; ?>" />
to
<input type="radio" name="Car" id="Toyota" <?=($row['make'] == 'Toyota' ? 'value="'.$row['make'].'" checked':NULL); ?> />
<!-- or better yet -->
<input type="radio" name="Car" id="Toyota" value="Toyota" <?=($row['make'] == 'Toyota' ? 'checked':NULL); ?> />
2. Database
File: delete_process.php
// Change
if($query_run) // << This only tell the script the sql statement run with no errors
// To
if(mysql_affected_rows()<=1) // << This confirms that one or more rows where changed by the sql statement
Explained
PHP Shorthand If/Else Using Ternary Operators (?:)
/* basic usage */
$var = 5;
$var_is_greater_than_two = ($var > 2 ? true : false); // returns true
Reason for error
If a radio button are not being displayed, it most-likely an 'Undefined variable' when getting $row['make'].
Other thing, remove the white spacing from. As this may play a part when using a MYSQL Statement.
<!-- From -->
value=" <?php echo $row['Registration_Number']; ?>"
<!-- To -->
value="<?=$row['Registration_Number']; ?>"
*Shorthand one line echo/print <?=

Update php mysql image field lost

I'm updating my post with an image field. Every thing is going fine, but i lose the path of the image, son if i leave the field empty the image path is null.
I have been trying different ways of including the old path to the field image. Those are the lines that have the old path and the new path.
<input type="file" name="image" value="<?php echo $row['image']; ?>">
<input type="hidden" name="old_image" value="<?php echo $row['image']; ?>" >
I tried also with <input type="file" name="image" value="<?php echo $image; ?>"> but it doesn't work.
Any suggestion?
Thanks in advance!
:)
This is my code:
<?php
require 'database.php';
$db = mysqli_connect("", "", "", "");
$id=$_GET["id"];
$title='';
$image='';
$image_text='';
$category='';
$result = mysqli_query($db, "SELECT * FROM `images` WHERE `id` = $id ");
while ($row = mysqli_fetch_array($result))
{
$title=$row['title'];
$image=$row['image'];
$papayos = $row['papayos'];
$cantidad = $row['cantidad'];
$image_text=nl2br($row['image_text']);
$category=$row['category'];
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Modificar. Lapapaya.org Educación y colaboración </title>
<meta name="keywords" content="colaboracion, economía del bien común, emprendimiento"/>
<meta name="description" content="Plataforma para desarrollo de proyectos productivos con bonos de intercambio"/>
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" type="image/png" href="images/favicon.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.8.0/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<section class="section has-background-white">
<div class="container">
<div class="columns is-centered">
<img class="logo-intro" src="images/logo.png" alt="Logo">
<br>
</div>
</div>
</section>
<form method="POST" action='' enctype="multipart/form-data">
<div class="container">
<h1>Título del artículo</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning is-fullwidth" type="text" name="title" value="<?php echo $title; ?>" placeholder="Título">
</div>
<br>
<br>
<div>
<div class="notification"> <h1>Imagen</h1>
<input type="hidden" name="size" value="1000000">
<div class="field">
<div class="control">
<input type="file" name="image" value="<?php echo $row['image']; ?>">
<input type="hidden" name="old_image" value="<?php echo $row['image']; ?>" >
</div>
</div>
<div>
<h1>Descripción</h1>
<textarea class="textarea" name="image_text" rows="8" cols="80"><?php echo $image_text; ?></textarea>
<br>
<h1>Categoría</h1>
<div class=" select is-warning is-fullwidth">
<select type="text" class="" name="category" value="<?php echo $category; ?>">
<option value="1 ">Productos agrícolas</option>
<option value="2 ">Servicio</option>
<option value="3 ">Artesanía</option>
<option value="4 ">Arte</option>
<option value="5">Diseño Industrial</option>
<option value="6 ">Ciudad</option>
<option value="7 ">Economía</option>
<option value="8 ">Emprendimiento</option>
<option value="9 ">Programación</option>
<option value="10 ">Reflexión</option>
<option value="11">Río</option>
<option value="12 ">Seguridad alimentaria</option>
<option value="13 ">Vivienda</option>
</select>
</div>
<h1>Precio</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning" type="number" name="papayos" value="<?php echo $papayos; ?>" placeholder="Papayos">
</div>
<br>
<h1>Cantidad</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning" type="number" name="cantidad" value="<?php echo $cantidad; ?>" placeholder="Cantidad">
</div>
<br>
<br>
<div>
<button class="button is-outlined is-medium is-fullwidth" type="update" name="update">Modificar</button>
</div>
</div>
</form>
</body>
</html>
<?php
$server = '';
$username = '';
$password = '';
$database = '';
if (isset($_POST['update'])) {
$title=$_POST['title'];
$image_text=nl2br($_POST['image_text']);
$category=$_POST['category'];
$papayos =$_POST['papayos'];
$cantidad =$_POST['cantidad'];
$total = $papayos * $cantidad;
$old_image = $_POST['old_image'];
if(isset($_FILES['image']['name']) && ($_FILES['image']['name']!="")) {
$size=$_FILES['image']['size'];
$temp=$_FILES['image']['tmp_name'];
$type=$_FILES['image']['type'];
$image_name=$_FILES['image']['name'];
unlink("images/$old_image");
move_uploaded_file($temp, "images/$image_name");
}else {
$image_name=$old_image;
}
$update=mysqli_query($db, "UPDATE images SET title = '$title', image = '$image_name', image_text = '$image_text', category = '$category', papayos = '$papayos', cantidad = '$cantidad', total = '$total' WHERE id = $id");
if ($update) {
echo "<script>alert('Datos actualizados exitosamente')</script>";
echo "<script>window.open('index.php', '_self')</script>";
}
else {
echo "<script>alert('Inserción fallida')</script>";
}
} ?>
I fixed adding this above the imput file:
<img src="images/<?php echo $image; ?>">
:)

I want to echo the fullname of the user without him putting it on the form

I have a table that has some values. One of them is the full name of the user. I want to echo the full name from the db that it is saved. I have 2 different tables for the risks and for the users. I thought about doing it with something like <?php echo $_SESSION['user']['fullname'] ?> but I don't know where to write that. There is also another page that i pass the values from the form into the db but I don't know if I should echo the full name from there.
<?php require_once('config.php') ?>
<?php
session_start();
// Check if the user is logged in, if not then redirect him to login page
if (!isset($_SESSION["loggedin"]) and $_SESSION["loggedin"] !== true) {
header("location: index.php");
exit;
}
?>
<?php
$connect = new PDO("mysql:host=localhost;dbname=riskit", "root", "");
$query = "SELECT * FROM risktable ORDER BY riskId";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
?>
<html>
<title>Risk Table</title>
<head>
<?php require_once( ROOT_PATH . '/includes/head_section.php') ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<body>
<div class="container">
<?php include( ROOT_PATH . '/includes/navbar.php') ?>
<br />
<br />
<h2 align="center">Risk Table</h2><br />
<h3 align="center">Add Risks</h3>
<br />
<form method="post" id="add_details">
<div class="form-group">
<label>Your Name</label>
<input type="text" name="fullname" class="form-control" required />
</div>
<div class="form-group">
<label>Risk Name</label>
<input type="text" name="riskName" class="form-control" required />
</div>
<div class="form-group">
<label>Description</label>
<input type="text" name="description" class="form-control" required />
</div>
<div class="form-group">
<label>Control Enviroment</label>
<input type="radio" name="controlEnv" class="form-control" required
<?php if (isset($controlEnv) && $controlEnv=="internal") echo "checked";?>
value="internal">Internal
<input type="radio" name="controlEnv" class="form-control" required
<?php if (isset($controlEnv) && $controlEnv=="external") echo "checked";?>
value="external">External
</div>
<br/>
<div class="form-group">
<label>Risk Category</label>
<input type="text" name="riskCat" class="form-control" required />
</div>
<div class="form-group">
<label>Risk Type</label>
<input type="radio" name="rtype" class="form-control" required
<?php if (isset($rtype) && $rtype=="threat") echo "checked";?>
value="threat">Threat
<input type="radio" name="rtype" class="form-control" required
<?php if (isset($rtype) && $rtype=="opportunity") echo "checked";?>
value="opportunity">Opportunity
</div>
<br/>
<div class="form-group">
<label>Phase</label>
<input type="text" name="phase" class="form-control" required />
</div>
<input type="submit" name="add" id="add" class="btn btn-success" value="Add" />
</div>
</form>
<br />
<h3 align="center">View Details</h3>
<br />
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Risk Name</th>
<th>Description</th>
<th>Contol Enviroment</th>
<th>Risk Category</th>
<th>Risk Type</th>
<th>Phase</th>
<th>Creator</th>
</tr>
</thead>
<tbody id="table_data">
<?php
foreach($result as $row)
{
echo '
<tr>
<td>'.$row["riskName"].'</td>
<td>'.$row["description"].'</td>
<td>'.$row["controlEnv"].'</td>
<td>'.$row["riskCat"].'</td>
<td>'.$row["rtype"].'</td>
<td>'.$row["phase"].'</td>
<td>'.$row["fullname"].'</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('#add_details').on('submit', function(event){
event.preventDefault();
$.ajax({
url:"insertRiskTable.php",
method:"POST",
data:$(this).serialize(),
dataType:"json",
beforeSend:function(){
$('#add').attr('disabled', 'disabled');
console.log('before');
},
success:function(data){
$('#add').attr('disabled', false);
console.log('in success');
if(data.riskName)
{
var html = '<tr>';
html += '<td>'+data.riskName+'</td>';
html += '<td>'+data.description+'</td>';
html += '<td>'+data.controlEnv+'</td>';
html += '<td>'+data.riskCat+'</td>';
html += '<td>'+data.rtype+'</td>';
html += '<td>'+data.phase+'</td>';
html += '<td>'+data.fullname+'</td></tr>';
$('#table_data').prepend(html);
$('#add_details')[0].reset();
}
}
})
});
});
</script>

php - edit SESSION variable in multiple page form

currently I am doing multiple page form (page 1 and page 2). I save the details in page 1 using SESSION and insert successfully to database. I also successfully retrieve the data from database and display on page (activityLog.php).
However, I face problem when I want to edit/update the form.The value in the form wasn't update as well as the database. Please help.Thanks.
Below is my display cause page and edit form (editIndividual.php).
activityLog.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>My Activity Log</title>
<?php
session_start();
include 'header.php';
?>
<div id="content">
<div class="section">
<h4 align="center" style="font-size:28px;">My Activity Log</h4>
<div>
Basic Setting
Change Password
<a class="selected" href="activityLog.php">My Activity Log</a>
</div>
<label style="font-size:19px;color:#333;"<strong>Manage your cause below.</strong>
<div class="figure">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" class="register">
<div class="first" >
<?php
include 'dbconn.php';
if(isset($_SESSION['email'])){
$query="SELECT * from cause join user_info on cause.userID=user_info.userID where email='{$_SESSION['email']}'";
$result=mysqli_query($conn, $query);
while ($row=mysqli_fetch_array($result)){
$causeID = $row['causeID'];
$title = $row['title'];
$category = $row['category'];
$donateType = $row['donateType'];
$goal = $row['goal'];
$description = $row['description'];
$createDate = $row['createDate'];
$image = $row['image'];
echo "<a href='editIndividual.php?u=$causeID'>".$title."</a><br>";
echo "<img height='80' width='100' src='upload/".$image."'><br>";
}
}
?>
<fieldset>
</fieldset>
</div>
</form><!--end form-->
</div>
</div>
</div>
<?php include 'footer.php';?> <!--include footer.php-->
</body>
</html>
editIndividual.php
<html>
<head>
<meta charset="UTF-8" />
<!--include header-->
<?php
session_start();
include 'dbconn.php';
include 'header.php';
if(!isset($_SESSION['email'])){
echo "Please login before proceed!";
header("location:login.php");
}
else{
if(isset($_GET['u'])){
$causeID = $_GET['u'];
$query="SELECT * from cause where causeID=$causeID ";
$result=mysqli_query($conn, $query);
while ($row=mysqli_fetch_array($result)){
$causeID = $row['causeID'];
$title = $row['title'];
$category = $row['category'];
$donateType = $row['donateType'];
$goal = $row['goal'];
$description = $row['description'];
$createDate = $row['createDate'];
$image = $row['image'];
}
//update title
$title = $_SESSION['title'];
$upTitle = "UPDATE cause set title='$title' where causeID='$causeID'";
$upTitleResult = mysqli_query($conn,$upTitle);
//update category
$category = $_SESSION['category'];
$upCategory = "UPDATE cause set category='$category' where causeID='$causeID'";
$upCategoryResult = mysqli_query($conn,$upCategory);
//update donate type
$donateType = $_SESSION['donateType'];
$upDonateType = "UPDATE cause set donateType='$donateType' where causeID='$causeID'";
$upDonateTypeResult = mysqli_query($conn,$upDonateType);
//update goal
$goal = $_SESSION['goal'];
$upGoal = "UPDATE cause set goal='$goal' where causeID='$causeID'";
$upGoalResult = mysqli_query($conn,$upGoal);
//update description
$description = $_POST['description'];
$upDes = "UPDATE cause set description='$description' where causeID='$causeID'";
$upDesResult = mysqli_query($conn,$upDes);
//update image
$image = $_FILES['imageToUpload']['name'];
$upImage = "UPDATE cause set image='$image' where causeID='$causeID'";
$upImageResult = mysqli_query($conn,$upImage);
}
}
?>
<!--Change choose file button default name-->
<script>
function HandleBrowseClick()
{
var fileinput = document.getElementById("imageToUpload");
fileinput.click();
}
function Handlechange()
{
var fileinput = document.getElementById("imageToUpload");
fileinput.value;
}
</script>
<div id="content">
<div>
<form action="activityLog.php" id="editInd_form" name="editInd_form" class= "register" method="post">
<div class="first">
<fieldset>
<label for="title"><strong>Cause Title: </strong></label><br>
<input type="text" id="title" name="title" class="inputtext" value="<?php echo $title?>"/><br>
<label for="category" ><strong><span class="error-message" style="color:red">*</span>Category:</strong></label><br>
<select id="category" name="category" onchange="document.getElementById('editInd_form').submit()">
<?php
$categoryArray=array("Select a category", "Animal Welfare", "Children", "Education", "Environment", "Health", "OKU", "Refugees", "Senior Citizen", "Community", "Women Welfare", "Youth");
for ($i=0; $i<count($categoryArray); $i++){
if ($i == $category){
echo "<option value='".$i."' selected>".$categoryArray[$i]."</option>";
}
else{
echo "<option value='".$i."'>".$categoryArray[$i]."</option>";
}
}
?>
</select><br>
<label for="donateType"><strong><span class="error-message" style="color:red;">*</span>Type of Donation:</strong></label><br>
<select id="donateType" name="donateType" onchange="document.getElementById('editInd_form').submit()" >
<?php
$donateTypeArray=array("Please Select","Fundraising","Books","Clothing","Electric product", "Food","Water","Other");
for ($j=0; $j<count($donateTypeArray); $j++){
if ($j == $donateType){
echo "<option value='".$j."' selected>".$donateTypeArray[$j]."</option>";
}
else{
echo "<option value='".$j."'>".$donateTypeArray[$j]."</option>";
}
}
?>
</select><br>
<label for="goal"><strong><span class="error-message" style="color:red">*</span>Please state your goal:</strong></label><br>
<input type="text" id="goal" name="goal" class="inputtext" value="<?php echo $goal?>" placeholder="enter an amount(RM) for fundraising, uniform, 1.5L mineral water, ..."><br>
</fieldset></div>
<div><fieldset>
<label for="description"><strong>Tell us your story: </strong></label><br>
<textarea name="description" style="width:350px;height:150px;"><?php echo $description?>
</textarea><br>
<!-- <img src="images/image-icon.png" class="image-icon" height="150" width="150"> <img src="images/video-icon.png" height="150" width="150">-->
<label for="imageToUpload"><strong>Upload Your Photo:</strong></label><br>
<input type="file" name="imageToUpload" id="imageToUpload" style="display:none;" onChange="Handlechange();">
<input type="button" value="Change image" id="fakeBrowse" onclick="HandleBrowseClick();"/>
<?php include 'upload1.php';?>
<input type="submit" name="submit" id="save" value=""><br>
</fieldset>
</div>
</form>
</table>
</div>
</div> <!--content end-->
<!--include footer-->
<?php include 'footer.php';?>
</body>
</html>
for your reference, this is my create form (2 pages form)
createIndividual.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<!--include header-->
<?php
session_start();
include 'dbconn.php';
if(!isset($_SESSION['email'])){
echo "Please login before proceed!";
header("location:login.php");
}
include 'header.php';
?>
<div id="content">
<div>
<h3 align="center"> Create your own cause</h3>
<h4><strong> Step 1: Title, Category, Goal</strong></h4>
<form action="createIndividual2.php" id="createInd_form" class= "register" method="post">
<div class="form">
<fieldset>
<label for="title"><strong>Cause Title: </strong></label><br>
<input type="text" id="title" name="title" class="inputtext"/><br>
<label for="category" ><strong><span class="error-message" style="color:red">*</span>Category:</strong></label><br>
<select id="category" name="category">
<option value="0"> Select a category</option>
<option value="1"> Animal Welfare</option>
<option value="2"> Children</option>
<option value="3"> Education </option>
<option value="4"> Environment</option>
<option value="5"> Health</option>
<option value="6"> OKU</option>
<option value="7"> Refugees</option>
<option value="8"> Senior Citizen</option>
<option value="9"> Community</option>
<option value="10"> Women Welfare</option>
<option value="11"> Youth</option>
</select><br>
<label for="donateType"><strong><span class="error-message" style="color:red;">*</span>Type of Donation:</strong></label><br>
<select id="donateType" name="donateType">
<option value="0">Please Select</option>
<option value="1">Fundraising</option>
<option value="2">Books</option>
<option value="3">Clothing</option>
<option value="4">Electric product</option>
<option value="5">Food</option>
<option value="6">Water</option>
<option value="7">Other</option>
</select><br>
<label for="goal"><strong><span class="error-message" style="color:red">*</span>Please state your goal:</strong></label><br>
<input type="text" id="goal" name="goal" class="inputtext" placeholder="enter an amount(RM) for fundraising, uniform, 1.5L mineral water, ..."><br>
<input type="submit" name="submit" id="next" value=""><br>
</fieldset>
</div>
</form>
</table>
</div>
</div> <!--content end-->
<!--include footer-->
<?php include 'footer.php';?>
</body>
</html>
createIndividual2.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<!--include header-->
<?php
session_start();
$_SESSION['title'] = $_POST['title'];
$_SESSION['category'] = $_POST['category'];
$_SESSION['donateType'] = $_POST['donateType'];
$_SESSION['goal'] = $_POST['goal'];
include 'header.php';
?>
<div id="content">
<div>
<h3 align="center"> Create your own cause</h3>
<h4><strong> Step 2: Tell us your story</strong></h4>
<form action="checkCause.php" id="createIndividual" class= "register" method="post" enctype="multipart/form-data">
<div class="form">
<fieldset>
<label for="title"><strong>Tell us your story: </strong></label><br>
<textarea name="description" style="width:500px;height:150px;">
</textarea><br>
<!-- <img src="images/image-icon.png" class="image-icon" height="150" width="150"> <img src="images/video-icon.png" height="150" width="150">-->
<label for="imageToUpload"><strong>Upload Your Photo:</strong></label><br>
<input type="file" name="imageToUpload" id="imageToUpload">
<input type="submit" name="upload" id="submit" value=""><br>
<button onclick="goBack()" id="back"></button>
<script>
function goBack() {
window.history.back();
}
</script>
<?php include 'upload1.php';?>
</fieldset>
</div>
</form>
</table>
</div>
</div> <!--content end-->
<?php include 'footer.php';?> <!--include footer.php-->
</body>
</html>
In editIndividual.php you have a error. You first get data from MySQL and after that you setup data from sessions. But where you check if new data exist and return old if not exists?
Look my integration in your code:
<html>
<head>
<meta charset="UTF-8" />
<!--include header-->
<?php
session_start();
include 'dbconn.php';
include 'header.php';
if(!isset($_SESSION['email'])){
echo "Please login before proceed!";
header("location:login.php");
}
else{
if(isset($_GET['u'])){
$causeID = $_GET['u'];
$query="SELECT * from cause where causeID=$causeID ";
$result=mysqli_query($conn, $query);
while ($row=mysqli_fetch_array($result)){
$causeID = $row['causeID'];
$title = $row['title'];
$category = $row['category'];
$donateType = $row['donateType'];
$goal = $row['goal'];
$description = $row['description'];
$createDate = $row['createDate'];
$image = $row['image'];
}
//update title
$title = (isset($_SESSION['title'])&&!empty($_SESSION['title'])?$_SESSION['title']:$title);
$upTitle = "UPDATE cause set title='$title' where causeID='$causeID'";
$upTitleResult = mysqli_query($conn,$upTitle);
//update category
$category = (isset($_SESSION['category'])&&!empty($_SESSION['category'])?$_SESSION['category']:$category);
$upCategory = "UPDATE cause set category='$category' where causeID='$causeID'";
$upCategoryResult = mysqli_query($conn,$upCategory);
//update donate type
$donateType = (isset($_SESSION['donateType'])&&!empty($_SESSION['donateType'])?$_SESSION['donateType']:$donateType);
$upDonateType = "UPDATE cause set donateType='$donateType' where causeID='$causeID'";
$upDonateTypeResult = mysqli_query($conn,$upDonateType);
//update goal
$goal = (isset($_SESSION['goal'])&&!empty($_SESSION['goal'])?$_SESSION['goal']:$goal);
$upGoal = "UPDATE cause set goal='$goal' where causeID='$causeID'";
$upGoalResult = mysqli_query($conn,$upGoal);
//update description
$description = (isset($_POST['description'])&&!empty($_POST['description'])?$_POST['description']:$description);
$upDes = "UPDATE cause set description='$description' where causeID='$causeID'";
$upDesResult = mysqli_query($conn,$upDes);
//update image
$image = (isset($_FILES['imageToUpload']['name']) && !empty($_FILES['imageToUpload']['name'])?$_FILES['imageToUpload']['name']:$image);
$upImage = "UPDATE cause set image='$image' where causeID='$causeID'";
$upImageResult = mysqli_query($conn,$upImage);
}
}
?>
<!--Change choose file button default name-->
<script>
function HandleBrowseClick()
{
var fileinput = document.getElementById("imageToUpload");
fileinput.click();
}
function Handlechange()
{
var fileinput = document.getElementById("imageToUpload");
fileinput.value;
}
</script>
<div id="content">
<div>
<form action="activityLog.php" id="editInd_form" name="editInd_form" class= "register" method="post">
<div class="first">
<fieldset>
<label for="title"><strong>Cause Title: </strong></label><br>
<input type="text" id="title" name="title" class="inputtext" value="<?php echo $title?>"/><br>
<label for="category" ><strong><span class="error-message" style="color:red">*</span>Category:</strong></label><br>
<select id="category" name="category" onchange="document.getElementById('editInd_form').submit()">
<?php
$categoryArray=array("Select a category", "Animal Welfare", "Children", "Education", "Environment", "Health", "OKU", "Refugees", "Senior Citizen", "Community", "Women Welfare", "Youth");
for ($i=0; $i<count($categoryArray); $i++){
if ($i == $category){
echo "<option value='".$i."' selected>".$categoryArray[$i]."</option>";
}
else{
echo "<option value='".$i."'>".$categoryArray[$i]."</option>";
}
}
?>
</select><br>
<label for="donateType"><strong><span class="error-message" style="color:red;">*</span>Type of Donation:</strong></label><br>
<select id="donateType" name="donateType" onchange="document.getElementById('editInd_form').submit()" >
<?php
$donateTypeArray=array("Please Select","Fundraising","Books","Clothing","Electric product", "Food","Water","Other");
for ($j=0; $j<count($donateTypeArray); $j++){
if ($j == $donateType){
echo "<option value='".$j."' selected>".$donateTypeArray[$j]."</option>";
}
else{
echo "<option value='".$j."'>".$donateTypeArray[$j]."</option>";
}
}
?>
</select><br>
<label for="goal"><strong><span class="error-message" style="color:red">*</span>Please state your goal:</strong></label><br>
<input type="text" id="goal" name="goal" class="inputtext" value="<?php echo $goal?>" placeholder="enter an amount(RM) for fundraising, uniform, 1.5L mineral water, ..."><br>
</fieldset></div>
<div><fieldset>
<label for="description"><strong>Tell us your story: </strong></label><br>
<textarea name="description" style="width:350px;height:150px;"><?php echo $description?>
</textarea><br>
<!-- <img src="images/image-icon.png" class="image-icon" height="150" width="150"> <img src="images/video-icon.png" height="150" width="150">-->
<label for="imageToUpload"><strong>Upload Your Photo:</strong></label><br>
<input type="file" name="imageToUpload" id="imageToUpload" style="display:none;" onChange="Handlechange();">
<input type="button" value="Change image" id="fakeBrowse" onclick="HandleBrowseClick();"/>
<?php include 'upload1.php';?>
<input type="submit" name="submit" id="save" value=""><br>
</fieldset>
</div>
</form>
</table>
</div>
</div> <!--content end-->
<!--include footer-->
<?php include 'footer.php';?>
</body>
</html>

Post data not being sent by a code igniter form

I've got a slight problem with my CI2.0.2 application.
From what I can tell, it is not getting any post data from a form and so is failing to run an update function, though most pages work fine.
The form is as follows:
<?php echo form_open('job/update/', array('id' => 'update', 'name' => 'update')); ?>
<div class="images">
<?php echo img('application/images/updateJob.png');?>
</div>
<h1>Update Job</h1>
<br><br><br><br>
<div class="fieldset">
<?php
if (isset($error))
{
echo '<div id ="error">';
echo '<h2>Error:</h2>';
echo '<p>'.$error.'</p>';
echo '</div>';
}
?>
<input type="hidden" name="c" id='c' value="<?php if(!empty($view[0])) { echo $view[0]; } else { echo "0"; } ?>">
<div class="left">
<h4>Job Details:</h4>
<div>
<label for="job_number">Job No:</label>
<input type="text" name="job_number" id="job_number" value="<?php echo $job['jobno']; ?>" disabled="disabled">
</div>
<div>
<label for="date">Date:</label>
<input type="text" name="date" id="date" value="<?php echo $job['datetime']->format('d-M-Y'); ?>">
</div>
<div>
<label for="council">Council:</label>
<input type="text" name="council" id="council" value="<?php echo htmlspecialchars($job['council']); ?>"> *
</div>
<div>
<label for="dano">DA No:</label>
<input type="text" name="dano" id="dano" value="<?php echo htmlspecialchars($job['dano']); ?>">
</div>
<div>
<label for="client">Client:</label>
<input type="text" name="client" id="client" value="<?php echo $job['clientid']; ?>" disabled="disabled">
</div>
</div>
<div class="right" style="margin-left: 390px;">
<h4>Location:</h4>
<label for="street_no">Street No:</label>
<input type="text" name="street_no" id="street_no" value="<?php echo $address['streetno']; ?>"> *
<br>
<label for="street_name">Street Name:</label>
<input type="text" name="street_name" id="street_name" value="<?php echo $address['streetname']; ?>"> *
<br>
<label for="street_type">Street Type:</label>
<select name="street_type" id="street_type">
<?php
foreach ($street_types as $type)
{
echo '<option';
if ($type == $address['streettype']) echo ' selected="selected"';
echo '>'.$type.'</option>';
}
?>
</select> *
<br>
<label for="suburb">Suburb:</label>
<input type="text" name="suburb" id="suburb" value="<?php echo $address['suburb']; ?>"> *
<br>
<label for="postcode">Postcode:</label>
<input type="text" name="postcode" id="postcode" value="<?php echo $address['postcode']; ?>"> *
<br>
<label for="state">State:</label>
<input type="text" name="state" id="state" value="<?php echo $address['state']; ?>"> *
<br>
<label for="country">Country:</label>
<input type="text" name="country" id="country" value="<?php echo $address['country']; ?>">
<br>
<label for="dp">DP:</label>
<input type="text" name="dp" id="dp" value="<?php echo $address['dp']; ?>">
<br>
<label for="lot_no">Lot No:</label>
<input type="text" name="lot_no" id="lot_no" value="<?php echo $address['lotno']; ?>">
<br>
<label for="po_box">PO Box:</label>
<input type="text" name="po_box" id="po_box" value="<?php echo $address['pobox']; ?>">
</div>
<div>
<input type="submit" id="submit" name="submit" value="Submit" class="button">
<p>* = Required fields</p>
</div>
</div>
<?php echo form_close();?>
And the update section of the controller is as follows:
/**
* Update an existing job.
* #param int $job_number The number of the job to update.
*/
public function update($job_number=0)
{
$this->load->model('Job_model');
$job = array();
$address = array();
// Get post data.
$job['joblocation'] = '';
$job['jobno'] = $this->input->post('job_number');
$job['datetime'] = new DateTime($this->input->post('date'));
$job['dano'] = $this->input->post('dano');
$job['council'] = $this->input->post('council');
echo $job['jobno'];
echo $job['dano'];
echo $job['council'];
$address['streetno'] = $this->input->post('street_no');
$address['streetname'] = $this->input->post('street_name');
$address['suburb'] = $this->input->post('suburb');
$address['country'] = $this->input->post('country');
$address['postcode'] = $this->input->post('postcode');
$address['state'] = $this->input->post('state');
$address['dp'] = $this->input->post('dp');
$address['lotno'] = $this->input->post('lot_no');
$address['pobox'] = $this->input->post('po_box');
$address['streettype'] = $this->input->post('street_type');
echo "here2";
if (isset($_POST['submit']))
{
$this->Job_model->update($job);
echo "here";
redirect('job/');
}
// Otherwise, get the data from the database.
else
{
$job = $this->Job_model->search($job_number);
$job = $job[0];
$job['datetime'] = new DateTime($job['datetime']);
$address = $this->Job_model->get_address($job['joblocation']);
$address = $address[0];
}
// Get the street types.
$street_types = array();
$this->load->model('staff_model');
$streets = $this->staff_model->get_street_types();
foreach ($streets as $street)
{
$street_types[$street['streettype']] = $street['streettype'];
}
// Load the client list.
$clients = array();
$this->load->model('client_model');
$people = $this->client_model->get_client_person_list();
$companies = $this->client_model->get_client_company_list();
// Allocate view data.
$viewdata = array();
$viewdata['job'] = $job;
$viewdata['street_types'] = $street_types;
$viewdata['address'] = $address;
$viewdata['people'] = $people;
$viewdata['companies'] = $companies;
$this->layout->view('job/update', $viewdata);
}
Any ideas why this might be happening?
Thanks in advance,
James
Try changing the quotes you're using on this line:
<input type="hidden" name="c" id='c' value="<?php if(!empty($view[0])) { echo $view[0]; } else { echo '0'; } ?>" />
The way you had it with the double quotes around the 0 you were breaking that php because the first one would be closing the opening value quote.

Categories