When checking my nonce, the hidden input values ($form_action, $timestamp, and $form_hash) are returning as blank instead of returning as equal the nonce variables ($action, $time, and $hash). This is preventing my if statement from running and my form data from submitting to the database. If I directly set the respective variables as equal the code runs great and the data is inserted into the database so I am pretty sure the problem is coming from the PHP code that is inserted as the value for the hidden inputs. Does anyone know why this is returning as blank?
HTML Code
<!DOCTYPE html>
<html>
<body>
<h1>Tournament Registration</h1>
<hr style=
"background-color:black;
margin:auto;">
<form
action="/Forms/connection.php"
method="post">
<input
type = "hidden"
name = "timestamp"
value ="<?php echo $time; ?>">
<input
type = "hidden"
name = "form_action"
value = "<?php echo $action; ?>">
<input
type = "hidden"
name = "form_hash"
value = "<?php echo $hash; ?>">
<div
class="form-field">
<input
style=
"width:250px;
padding:10px;
margin-top: 20px;"
type="text"
class="text"
name="firstname"
placeholder="First Name"
required>
<br>
<br>
</div>
<div
class="form-field">
<input
style=
"width:250px;
padding:10px;"
type="text"
class="text"
name="lastname"
placeholder="Last Name"
required>
<br>
<br>
</div>
<div
class="form-field">
<input
style=
"width:250px;
padding:10px;"
type="email"
class="text"
name="email"
placeholder="Email"
required>
<br>
<br>
</div>
<div
class="form-field">
<input
style=
"width:250px;
padding:10px;"
type="text"
class="text"
name="phonenumber"
placeholder="Phone Number"
required>
<br>
<br>
</div>
<div
class="form-field">
<input
style=
"width:250px;
padding:10px;"
type="text"
class="text"
name="handicap"
placeholder="Handicap"
required>
<br>
<br>
</div>
<div
class="form-field">
<select
style=
"width:250px;
padding:10px;"
class="text"
name="shirtsize"
size = 1
required>
<option
value=""
selected>
Shirt Size
</option>
<option
value="S">
S
</option>
<option
value="M">
M
</option>
<option
value="L">
L
</option>
<option
value="XL">
XL
</option>
<option
value="2XL">
2XL
</option>
<option
value="3XL">
3XL
</option>
</select>
</div>
<br>
<div
class="form-field">
<input
style=
"width:250px;
padding:10px;
margin-left:auto;"
type="submit"
value="Register">
</div>
</form>
</body>
</html>
PHP Code
<?php
require_once('config.php');
//Nonce
$time = time();
$action = 'tournament_registration';
$str = sprintf('%s_%s_%s', $action, $time, $NONCE_SALT);
$hash = hash('sha512', $str);
if (! empty($_POST)){
// Extract Post Data
extract($_POST);
$timestamp = $_POST['timestamp'];
$form_action = $_POST['form_action'];
$form_hash = $_POST['form_hash'];
echo "timestamp = "; print_r($timestamp);
echo '<br/>';
echo "form_action = "; print_r($form_action);
echo '<br/>';
echo "form_hash = "; print_r($form_hash);
echo '<br/>';
echo "firstname = "; print_r($firstname);
echo '<br/>';
echo "lastname = "; print_r($lastname);
echo '<br/>';
echo "email = "; print_r($email);
echo '<br/>';
echo "phonenumber = "; print_r($phonenumber);
echo '<br/>';
echo "handicap = "; print_r($handicap);
echo '<br/>';
echo "shirtsize = "; print_r($shirtsize);
echo '<br/>';
// Check Nonce
$calc_str = sprintf('%s_%s_%s', $form_action, $timestamp, $NONCE_SALT);
$calc_hash = hash('sha512', $calc_str);
if($calc_hash == $form_hash){
$filter_firstname = filter_var($firstname, FILTER_SANITIZE_STRING);
$filter_lastname = filter_var($lastname, FILTER_SANITIZE_STRING);
$filter_email = filter_var($email, FILTER_VALIDATE_EMAIL);
$filter_phonenumber = filter_var($phonenumber, FILTER_SANITIZE_STRING);
$filter_handicap = filter_var($handicap, FILTER_SANITIZE_STRING);
$filter_shirtsize = filter_var($shirtsize, FILTER_SANITIZE_STRING);
}
if ($filter_email != false){
//Send to database
$mysql = new mysqli($servername, $username, $password, $database);
$stmt = $mysql->prepare("INSERT INTO Registration (firstname, lastname, email, phonenumber, handicap, shirtsize) VALUES (?,?,?,?,?,?)");
$stmt->bind_param('ssssss', $filter_firstname, $filter_lastname, $filter_email, $filter_phonenumber, $filter_handicap, $filter_shirtsize);
$insert = $stmt->execute();
//Close Connection
$stmt->close();
$mysql->close();
}
else {
$insert = false;
}
}
else {
$insert = false;
}
?>
Related
I have a problem when uploading image into database using mysql.
When I click button for upload the image, the error comes out like this:
"Undefined index image in C:\xampp\htdocs\fyp\kemaskinipemandu.php" at line 29 and 30.
I've tried other solution from StackOverflow but it didn't work out at all. So, here is my html and my php code.
if (isset($_POST['kemaskini'])){
$email = $_SESSION['driverEmail'];
$nama = $_POST['nama'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$kp = $_POST['kp'];
$tel = $_POST['tel'];
$alamat = $_POST['alamat'];
$exdate = date('Y-m-d', strtotime($_POST['lesen']));
$class = $_POST['jenislesen'];
$image = $_FILES['image']['name'];//imageUpload
move_uploaded_file($_FILES['image']['tmp_name'], "img/".$_FILES['image']['name']);
if($password === $cpassword){
$query = "UPDATE driver SET driverName='$nama', driverPassword='$password', cpassword='$cpassword', driverICNum='$kp', contNum='$tel',
address='$alamat', licenseExDate='$exdate', class='$class', image='$image' WHERE driverID='$driverID';";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
if($result)
{
?>
<script>
alert('Kemas Kini Pemandu Berjaya. ');
window.location.href="kemaskinipemandu.php";
</script>
<?php
}
}else {
?>
<script>
alert('Kata laluan tidak sama. ');
window.location.href="kemaskinipemandu.php";
</script>
<?php
}
}
and the line that have error are :
$image = $_FILES['image']['name'];//imageUpload
move_uploaded_file($_FILES['image']['tmp_name'], "img/".$_FILES['image']['name']);
Select image to upload:
<form action="kemaskinipemandu.php" method = "POST" enctype="multipart/form-data">
<center>
<?php
$email = $_SESSION['driverEmail'];
$query=" SELECT * from driver where driverID='$driverID'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$count = mysqli_num_rows($result);
if (isset($count) and ($count > 0)) {
while($row = mysqli_fetch_assoc($result)){
$name = $row['driverName'];
$password = $row['driverPassword'];
$cpassword = $row['cpassword'];
$ic = $row['driverICNum'];
$contNum = $row['contNum'];
$address = $row['address'];
$exdate = $row['licenseExDate'];
$class = $row['class'];
$image = $row['image'];
?>
<div class="col-md-6">
<div class="form-group">
<img src="<?php echo $image ?>" height="200" width="200"/><br><br>
<div class="form-inline">
Select image to upload:
<input type="file" name="image" id="image" style="margin-left:2%"><br><br>
</div>
<label for="nama">Nama :</label>
<input type="nama" class="form-control" name="nama" value="<?php echo $name ?>" ><br>
<label for="email">Email :</label>
<input type="email" class="form-control" name="email" value="<?php echo $email ?>" ><br>
<label for="password">Kata Laluan :</label>
<input type="password" class="form-control" name="password" value="<?php echo $password ?>" ><br>
<label for="password">Pengesahan Kata Laluan :</label>
<input type="password" class="form-control" name="cpassword" value="<?php echo $cpassword ?>" ><br>
<label for="kp">No. Kad Pengenalan :</label>
<input type="kp" class="form-control" name="kp" value="<?php echo $ic ?>" ><br>
<label for="tel">No. Tel :</label>
<input type="tel" class="form-control" name="tel" value="<?php echo $contNum ?>" ><br>
<label for="alamat">Alamat :</label>
<textarea type="alamat" class="form-control" name="alamat" rows="6"><?php echo $address ?></textarea><br>
<label for="lesen">Tamat Tempoh Lesen Memandu :</label>
<input type="date" class="form-control" name="lesen" value="<?php echo $exdate ?>" ><br>
<label for="jenislesen">Lesen/Kelas:</label>
<input type="text" class="form-control" name="jenislesen" value="<?php echo $class ?>" >
</div>
</div>
<?php } }?>
<input type="submit" class="btn btn-primary" name="kemaskini" value="Kemas Kini"></br>
</center>
</form>
I hope someone can help me. Thank you.
I'm still very new to php and form validation. I am currently trying to create an update form that validates before submitting the data to the database. So far I have successfully managed to update the data in the database when submitting the form.
But now I am trying to validate the data and make sure that the 4 fields are filled in and not left blank, if some of the form fields are left blank then I need the form to reload with what was already filled in on the form previously.
I have started adding in form validation into the script below but this is script I have successfully used for adding new data to a database. I'm having trouble trying to wrap my head around what I need to change to make it work for an UPDATE query. Thanks in advance
The only fields i need to update in the form is the description, img_path, location and payment.
<?php
$mysqli = new mysqli("localhost", "root", "", "etrading");
session_start(); //start session
//Check that a product ID is specified for the page
if (isset($_GET['ItemID'])) {
$productID = $_GET['ItemID'];
}else{
header("Location: index.php");
}
if (isset($_POST['Name'])) {
$Name = $_POST['Name'];
$Description = $_POST['Description'];
$img_path = $_POST['img_path'];
$Quantity = $_POST['Quantity'];
$Category = $_POST['Category'];
$Location = $_POST['Location'];
$Saletype = $_POST['Saletype'];
$Price = $_POST['Price'];
$Duration = $_POST['Duration'];
$Payment = $_POST['Payment'];
$updateQuery = "UPDATE item SET Description = '$Description', img_path = '$img_path', Location = '$Location', Payment = '$Payment' WHERE ItemID= $productID";
$mysqli->query($updateQuery);
echo ("Product successfully updated");
}
$query = "SELECT * FROM item WHERE ItemID = $productID";
$result = $mysqli->query($query);
if($result->num_rows > 0) {
$data = $result->fetch_array(MYSQLI_BOTH);
//prepare input data in an array
$updatedata = array($Description, $img_path, $Location, $Payment);
//prepare error list
$errors = array ();
//Validation tests and store list
if ($Description == "" || $img_path == "" || $Location == "" || $Payment == "" ) {
array_push($errors, "All form fields must be filled out before submitting.");
}
//if errors redirect back to form page and save attempted data.
if (count($errors) > 0) {
$_SESSION['updatedata'] = $updatedata;
$_SESSION['errors'] = $errors;
header("Location: ../edit.php");
}else{
unset($_SESSION['updatedata']);
unset($_SESSION['errors']);
}
if(isset($_SESSION['errors'])) {
$errors = $_SESSION['errors'];
for ($errorCount = 0; $errorCount < count($errors); $errorCount++) {
echo ("<p class='error'>Error: " . $errors[$errorCount] . "</p>");
}
}
?>
<div id="form">
<h2> Edit Product </h2>
<form action="edit.php?ItemID=<?php echo $productID; ?>" method="POST" >
<fieldset>
<h4>Sell Your Item</h4>
<p><label class="title" for="Name">Name:</label>
<input type="text" placeholder="<?php echo $data['Name']; ?>" name="Name" id="Name" title="Please enter item name"
readonly ><br />
<label class="title" for="Description">Description:</label>
<textarea name="Description" rows="5" cols="33" placeholder="<?php echo $data['Description']; ?>" id="Description" title="Please describe your item" ></textarea><br />
<img src="../img/<?php echo $data['img_path']; ?>" />
<br>
Select image to upload:
<input type="file" name="img_path" placeholder="<?php echo $data['img_path']; ?>" id="img_path" accept="image/jpg"><br>
<label class="title" for="Quantity">Quantity:</label>
<input type="text" placeholder="<?php echo $data['Quantity']; ?>" name="Quantity" id="Quantity" title="Number of items" readonly><br />
<label class="title" for="Category">Category:</label>
<input type="text" placeholder="<?php echo $data['Category']; ?>" name="Category" id="Category" Title="Category" readonly >
<label class="title" for="Location">Location:</label>
<input type="text" placeholder="<?php echo $data['Location']; ?>" name="Location" id="Location" title="Enter item location" ><br />
<label class="title" for="Saletype">Sale Type:</label>
<input type="text" placeholder="<?php echo $data['Saletype']; ?>" name="Saletype" id="Saletype" title="Sale Type" readonly >
<label class="title" for="Price">Price: $</label>
<input type="text" placeholder="<?php echo $data['Price']; ?>" name="Price" id="Price" title="Please enter your name" readonly><br />
<label class="title" for="Duration">Duration:</label>
<input type="text" placeholder="<?php echo $data['Duration']; ?>" name="Duration" id="Duration" title="End Date" readonly><br />
<label class="title" for="Payment">Payment Type:</label>
<input type="text" placeholder="<?php echo $data['Payment']; ?>" name="Payment" id="Payment" title="Payment" readonly >
<select name="Payment" id="Payment" >
<option value="PayPal">PayPal</option>
<option value="Bank Deposit">Bank Deposit</option>
<option value="Card">Credit Card</option>
</select><br>
<div class="submit"><input type="submit" value="submit" name="submit" /></div>
<div class="reset"><input type="reset" /></div>
</fieldset>
</form>
You could use the required attribute on the HTML form. This will ensure the form can not be submitted unless there are input values.
<input type="text" required />
In your PHP file, you can use the isset() function to check all the values.
if (isset($description) && isset($img_path) && isset($description) && isset($payment))
{
// other code
}
You should also make sure to escape the values.
if (isset($description) && isset($img_path) && isset($description) && isset($payment))
{
$description = mysqli_real_escape_string($conn, $description);
$img_path = mysqli_real_escape_string($conn, $img_path);
$location = mysqli_real_escape_string($conn, $location);
$payment = mysqli_real_escape_string($conn, $payment);
$updateQuery = "UPDATE item SET Description = '$Description', img_path = '$img_path', Location = '$Location', Payment = '$Payment' WHERE ItemID= $productID";
$mysqli->query($updateQuery);
}
The mysqli_real_escape_string escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection
You should always do validation on both frontend and backend.
Try this.. this would work.. It worked for me..
<input type="text" name="name" value="<?php echo $name; ?>" required="required" placeholder="Enter name">
I am using Unique Key for the field 'name', but when I update the record using edit file through admin, it gives me an error for duplicate entry. I can't remove unique key, it's required..
<!--update process-->
<?php
if(isset($_POST['submit']) and !empty($_POST['token'])){
print_r($_POST);
$name = $_POST['name'];
$size = $_POST['size'];
$linkt = $_POST['link'];
$seeds = $_POST['seeds'];
$leechs = $_POST['leechs'];
$active = $_POST['active'];
$query = "UPDATE tplus_torrentlist SET name = '$name', size = '$size', link = '$linkt', seeds = '$seeds', leechs = '$leechs', active = '$active'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
$error = mysqli_error($link);
if(empty($error)){
$_SESSION['flash'] = '<blockquote style="background: green; color: #fff">One record updated</blockquote>';
header('location:dashbord.php');
}
else{
$_SESSION['flash'] = '<blockquote style="background: green; color: #fff">Sorry cant updated this record</blockquote>';
header('location:dashbord.php');
}
}
?>
<!--fetch values from database according to id-->
<?php
$sql = "SELECT * FROM tplus_torrentlist WHERE id = $id limit 1";
$result = mysqli_query($link ,$sql) or die(mysqli_error($link));
$row = $result->fetch_array();
?>
<div class="container">
<div class="row clearfix">
<div class="col-md-8 col-md-offset-2">
<?php if(!empty($response)){echo $response;} ?>
<h3>Edit this torrent</h3>
<hr/>
<form role="form" class="form" action="edit.php?id=<?php echo $_GET['id']?>" method="POST">
<label>Name</label>
<input type="text" name="name" value="<?php echo $row['name']?>" class="form-control input-sm">
<label>Size</label>
<input type="text" name="size" value="<?php echo $row['size']?>" class="form-control input-sm">
<label>Link</label>
<input type="text" name="link" value="<?php echo $row['link']?>" class="form-control input-sm">
<label>Seeds</label>
<input type="text" name="seeds" value="<?php echo $row['seeds']?>" class="form-control input-sm">
<label>Leechs</label>
<input type="text" name="leechs" value="<?php echo $row['leechs']?>" class="form-control input-sm">
<label>Active</label>
<select name="active" class="form-control input-sm">
<?php if($row['active'] ==0){?>
<option value="0">Active</option>
<option value="1">InActive</option>
<?php }else{ ?>
<option value="1">InActive</option>
<option value="0">Active</option>
<?php } ?>
</select>
<br/>
<input type="hidden" name="token" value="<?php echo rand(100, 100000)?>">
<input type="submit" name="submit" value="update torrent" class="btn btn-info">
</form>
</div>
</div>
</div>
Any solution without removing unique key from the field 'name' ?
Your update query need to correct as following -
$query = "UPDATE tplus_torrentlist SET name = '$name', size = '$size', link = '$linkt', seeds = '$seeds', leechs = '$leechs', active = '$active' WHERE id = $id limit 1";
I have the form that is for users to edit their profiles:
<div id="page">
<?php echo message(); ?>
<?php echo form_errors($errors); ?>
<h2>Edit Admin: <?php echo htmlentities($admin["username"]); ?></h2>
<form action="edit_admin.php?usr_serno=<?php echo urlencode($admin["usr_serno"]); ?>" method="post">
<p>Username:
<input type="text" name="username" value="<?php echo htmlentities($admin["username"]); ?>" />
</p>
<p>Password:
<input type="password" name="password" value="" />
<?php if (!isset($_GET["password"])
</p>
<p>Email:
<input type="text" name="email" value="<?php echo htmlentities($admin["email"]); ?>" />
</p>
<p>Role:
<select type="int" name="role_serno">
<option value="1">Administrator</option>
<option value="2">User</option>
</select>
</p>
<p>First Name:
<input type="text" name="name" value="<?php echo htmlentities($admin["name"]); ?>" />
</p>
<p>Last Name:
<input type="text" name="lastname" value="<?php echo htmlentities($admin["lastname"]); ?>" />
</p>
<p>ID:
<input type="text" name="id" value="<?php echo htmlentities($admin["id"]); ?>" />
</p>
<p>Address:
<input type="text" name="address" value="<?php echo htmlentities($admin["address"]); ?>" />
</p>
<p>Postcode:
<input type="text" name="postcode" value="<?php echo htmlentities($admin["postcode"]); ?>" />
</p>
<p>City:
<select id="city" type="text" name="city" value="<?php echo htmlentities($admin["city"]); ?>">
<option value="Nicosia">Nicosia</option>
<option value="Limassol">Limassol</option>
<option value="Larnaca">Larnaca</option>
<option value="Paphos">Paphos</option>
<option value="Other">Other</option>
</select>
<input id="other_city" type="text" name="other_city" value="<?php echo htmlentities($admin["city"]); ?>" />
</p>
<p>Telephone:
<input type="text" name="telephone" value="<?php echo htmlentities($admin["telephone"]); ?>" />
</p>
<p>College:
<input type="text" name="college" value="<?php echo htmlentities($admin["college"]); ?>" />
</p>
<input type="submit" name="submit" value="Edit Admin" />
</form>
<br />
Cancel
</div>
`
And on top of that page i am checking and trying to update the users profile:
if (isset($_POST["submit"])) {
$required_fields = array("username","email","role_serno",
"name","lastname","id","telephone","address","college","postcode","city");
validate_presences($required_fields);
$fields_with_max_lengths = array("username" => 30);
validate_max_lengths($fields_with_max_lengths);
if (empty($errors)) {
// Perform Update
//if (!isset ($_POST["password"]))
//$hashed_password = $_GET["password"];
//if (isset ($_POST["password"]))
$id_serno = $admin["usr_serno"];
$username = mysql_prep($_POST["username"]);
$hashed_password = password_encrypt($_POST["password"]);
$email=mysql_prep($_POST["email"]);
$role_serno=mysql_prep($_POST["role_serno"]);
$name=mysql_prep($_POST["name"]);
$lastname=mysql_prep($_POST["lastname"]);
$id=mysql_prep( $_POST["id"]);
$date_create=mysql_prep( $_POST["date_create"]);
$address=mysql_prep( $_POST["address"]);
$postcode=mysql_prep( $_POST["postcode"]);
$city=mysql_prep( $_POST["city"]);
$telephone=mysql_prep( $_POST["telephone"]);
$college=mysql_prep( $_POST["college"]);
$query = "UPDATE users SET ";
$query .= "username = '{$username}', ";
$query .= "password = '{$hashed_password}', ";
$query .= "email = '{$email}', ";
$query .= "role_serno = '{$role_serno}', ";
$query .= "name = '{$name}', ";
$query .= "lastname = '{$lastname}', ";
$query .= "id = '{$id}', ";
$query .= "address = '{$address}', ";
$query .= "postcode = '{$postcode}', ";
$query .= "city = '{$city}', ";
$query .= "telephone = '{$telephone}', ";
$query .= "college = '{$college}' ";
$query .= "WHERE usr_serno = {$id_serno} ";
$query .= "LIMIT 1";
$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) == 1) {
// Success
$_SESSION["message"] = "Admin updated.";
redirect_to("manage_admins.php");
} else {
// Failure
$_SESSION["message"] = "Admin update failed.";
}
}
} else {
// This is probably a GET request
} // end: if (is set($_POST["submit"]))`
the issue comes when the user is posting a form without passing the password in cause then the database is updated with empty password and i have a check not to accept empty passwords at lo-gin page.
Is there a way to avoid and check this.
Please advise cause I am new with developing in php and I am not 100% sure how this is going to be done.
I tried so far to check if post value is empty then pass the current database value without encoding it.. but for some reason the if check doesn't actually do anything
you can check like this
if (isset($_POST["submit"]) && trim($_POST['password']) !="") {
//run the code
}else{
}
You can add a client side javascript validation here.
In case of server side
check
if(empty($_POST['password']))
{
// whatever you want to ask and do
}
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.