Undefined property: stdClass:: in AngularJS CRUD - php

Form:
<!-- Form used for updation of data into database -->
<form class="form-horizontal alert alert-warning" id="editForm" ng-submit="ProcessClient(currentUser)" hidden style="margin-top: 3%;">
<h3 class="text-center">Client preluat</h3>
<div class="form-group">
<label for="Name">Nume client:</label>
<input type="text" class="form-control" ng-model="currentUser.nume_client" value="{{currentUser.nume_client}}">
</div>
<div class="form-group">
<label for="Motive">Motivul prezentării la recepție:</label>
<select class="form-control" name="motive">
<option>Ridicare produs</option>
<option>Predare produs</option>
<option>Factura storno</option>
<option>Reclamatie</option>
<option>Informare</option>
</select>
</div>
<div class="form-group">
<label for="Email">Fișă service:</label>
<input type="text" class="form-control" />
</div>
<div class="form-group">
<label for="fise_cu_probleme" style="float: left; margin-left: 2%;">Observație:</label>
<input type="checkbox" name="fise_cu_probleme" class="checkbox" value="DA" id="checkbox" ng-model="currentUser.fise_cu_probleme" />
</div>
<div class="form-group" id="observatii" style="display: none;">
<label for="observatii">Observații:</label>
<textarea class="form-control" name="observatii" value=""></textarea>
</div>
<div class="form-group">
<button class="btn btn-warning" ng-disabled="empList.$invalid" ng-click="updateMsg(currentUser.id)">Client soluționat</button>
</div>
</form>
AngularJS:
$scope.ProcessClient = function(info){
$http.post('includes/assets/receptie_clienti/databaseFiles/processing_client.php',{"id":info.id,"name":info.nume_client,"gender":info.motiv,"email":info.fisa_service,"observatii":info.observatii,"fise_cu_probleme":info.fise_cu_probleme}).success(function(data){
$scope.show_form = true;
if (data == true) {
getInfo();
}
});
}
And php code where query executes:
<?php session_start();
// Including database connections
require_once 'database_connections.php';
// Fetching the updated data & storin in new variables
$data = json_decode(file_get_contents("php://input"));
// Escaping special characters from updated data
$id = mysqli_real_escape_string($connection, $data->id);
$name = mysqli_real_escape_string($connection, $data->name);
$email = mysqli_real_escape_string($connection, $data->email);
$gender = mysqli_real_escape_string($connection, $data->gender);
$fise_cu_probleme = mysqli_real_escape_string($connection, $data->fise_cu_probleme);
$observatii = mysqli_real_escape_string($connection, $data->observatii);
$date = date_create('');
$ora_rezolvare = date_format($date, 'H:i');
$client_rezolvat = 'REZOLVAT';
$operator = $_SESSION['username'];
// mysqli query to insert the updated data
mysqli_begin_transaction($connection);
$query = mysqli_query($connection,"UPDATE flux_zilnic SET motiv='$gender',nume_client='$name',status_rezolvare='$client_rezolvat',ora_rezolvare='$ora_rezolvare',fisa_service='$email',fise_cu_probleme='$fise_cu_probleme',observatii='$observatii' WHERE id='$id'") or die("NU AM ACTUALIZAT FLUXUL ZILNIC DEOARECE: <br>".mysqli_error($connection));
$queryTwo = mysqli_query($connection,"UPDATE birouri SET disponibilitate = 'LIBER' WHERE username = '$operator'") or die("NU AM ACTUALIZAT DISPONIBILITATEA DEOARECE: <br>".mysqli_error($connection));
mysqli_commit($connection);
?>
It returnes me error:
PHP Notice: Undefined property: stdClass::$fise_cu_probleme in
C:\wamp64\www\includes\assets\receptie_clienti\databaseFiles\processing_client.php
PHP Notice: Undefined property: stdClass::$observatii in
C:\wamp64\www\includes\assets\receptie_clienti\databaseFiles\processing_client.php
What can it be the problem?

Related

Unable to add data into database in php

<?php
if(isset($_POST["submit"]))
if (!empty($_FILES["uploadImage"]["name"])) {
//Including dbconfig file.
require 'config.php';
$ImageSavefolder = "images/student/";
move_uploaded_file($_FILES["uploadImage"]["tmp_name"] ,
"$ImageSavefolder".$_FILES["uploadImage"]["name"]);
$name = mysqli_real_escape_string($conn, $_POST['name']);
$fathername = mysqli_real_escape_string($conn, $_POST['fathername']);
$htno = mysqli_real_escape_string($conn, $_POST['htno']);
$phoneno = mysqli_real_escape_string($conn, $_POST['phoneno']);
$department = mysqli_real_escape_string($conn, $_POST['department']);
$class = mysqli_real_escape_string($conn, $_POST['class']);
$address = mysqli_real_escape_string($conn, $_POST['address1']);
$address2 = mysqli_real_escape_string($conn, $_POST['address2']);
$city = mysqli_real_escape_string($conn, $_POST['city']);
$state = mysqli_real_escape_string($conn, $_POST['state']);
$zip = mysqli_real_escape_string($conn, $_POST['zip']);
$sql= "INSERT INTO student_detail(name,fathername,htno,phoneno,department,class,address1,address2,city,state,zip) VALUES ('$name','$fathername','$htno','$phoneno','$department','$class','$address','$address2','$city','$state','$zip','".$_FILES['uploadImage']['name']."')";
if(!mysqli_query($conn,$sql))
{
echo "Not Updated";
}
else
{
echo "<br><div class='alert alert-success' role='alert'>Added Sucessfully !</div>";
}
}
?>
This code is not working for adding the following data into database. Did I do anything wrong? Please help me sort the problem.
I already created database with config.php
Form Data
<form method="post" action="" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<input type="text" class="form-control" placeholder="Please Enter Name" name="name">
</div>
<div class="form-group col-md-6">
<label for="fathername">Father's Name</label>
<input type="text" class="form-control" placeholder="Please Enter Father's Name" name="fathername">
</div>
<div class="form-group col-md-6">
<label for="htno">Hall Ticket/ Roll No.</label>
<input type="text" class="form-control" placeholder="Please Enter Hall Ticket/ Roll No." name="htno">
</div>
<div class="form-group col-md-6">
<label for="phoneno">Phone Number</label>
<input type="text" class="form-control" placeholder="Please Enter Phone No." name="phoneno">
</div>
<div class="form-group col-md-6">
<label for="department">Department</label>
<select class="form-control" name="department">
<option selected="selected">Choose your Department</option>
<?php
require('config.php');
$result = mysqli_query($conn,"SELECT * FROM department");
while($test= mysqli_fetch_array($result))
{
echo "<option value='".$test['department_name']."'>".$test['department_name']."</option>";
}
?>
</select>
</div>
<div class="form-group col-md-6">
<label for="class">Class</label>
<select class="form-control" name="class">
<option selected="selected">Choose your Class</option>
<?php
require('config.php');
$result = mysqli_query($conn,"SELECT * FROM class");
while($test= mysqli_fetch_array($result))
{
echo "<option value='".$test['class_name']."'>".$test['class_name']."
</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" class="form-control" placeholder="House No./Flat No." name="address1">
</div>
<div class="form-group">
<label for="address2">Address 2 (Optional)</label>
<input type="text" class="form-control" placeholder="Locality/Area/Street" name="address2">
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="city">City</label>
<input type="text" class="form-control" name="city">
</div>
<div class="form-group col-md-4">
<label for="state">State</label>
<select class="form-control" name="state">
<option selected="selected"name="bihar">bihar</option>
<option>...</option>
</select>
</div>
<div class="form-group col-md-2">
<label for="zip">Zip</label>
<input type="text" class="form-control" name="zip">
</div>
<div class="form-group col-md-6">
<label for="profile">Profile Pic</label><br>
<input type="file" accept="image/*" onchange="loadFile(event)" name="uploadImage" id="uploadImage">
<img id="output" style="width:20%;"/>
<script>
var loadFile = function(event) {
var reader = new FileReader();
reader.onload = function(){
var output = document.getElementById('output');
output.src = reader.result;
};
reader.readAsDataURL(event.target.files[0]);
};
</script>
</div>
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
you are trying to insert extra value which is not exist in query see here.
your field
(name,fathername,htno,phoneno,department,class,address1,address2,city,state,zip)
and your values
('$name','$fathername','$htno','$phoneno','$department','$class','$address','$address2','$city','$state','$zip','".$_FILES['uploadImage']['name']."')
you need to do add image field also
your full query
$sql= "INSERT INTO student_detail(name,fathername,htno,phoneno,department,class,address1,address2,city,state,zip,imageFieldName) VALUES ('$name','$fathername','$htno','$phoneno','$department','$class','$address','$address2','$city','$state','$zip','".$_FILES['uploadImage']['name']."')";
<?php
/* dbconnection.php file
$conn = mysqli_connect("localhost","root","12345") or die (mysqli_error());
mysqli_select_db($conn,"student") or die (mysqli_error());
*/
//Including dbconnection file here
include('dbconnection.php');
if(isset($_POST["submit"]))
{
if (!empty($_FILES["uploadImage"]["name"]))
{
$ImageSavefolder = "images/student/";
$name = $_FILES["uploadImage"]["name"];
$tmp_name = $_FILES["uploadImage"]["tmp_name"];
move_uploaded_file(tmp_name, $ImageSavefolder.$name);
$sql = "INSERT INTO students (name,fathername,htno,phoneno,department,class,address1,address2,city,state,zip,image) VALUES ('".$_POST["name"]."','".$_POST["fathername"]."','".$_POST["htno"]."','".$_POST["phoneno"]."','".$_POST["department"]."','".$_POST["class"]."','".$_POST["address1"]."','".$_POST["address2"]."','".$_POST["city"]."','".$_POST["state"]."','".$_POST["zip"]."','".$name."')";
if ($conn->query($sql) === TRUE)
{
echo "<script type= 'text/javascript'>alert('Record Inserted Successfully');</script>";
}
else
{
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}
}
}
?>

I cant submit my form data to MySQL database [duplicate]

This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 5 years ago.
The connection is correct fields are set correctly but can't locate the problem from the code.After an hour ago it was work fine but after putting more fields it goes stuck.Form submitting correctly but the fields in xampp have nothing.Please help me to submit data.See the variables below, in fact, all the code below.
<?php
$product = "";
$cost = "";
$other = "";
$otherOne = "";
$code = "";
$price = "";
$qty = "";
$kg = "";
$value = "";
$id = 0;
Here is my config.php file code and its connect properly with my database as it cant show any die() error.
<?php
//Database Connection
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'waqar';
$connection = mysqli_connect($host, $user,$pass,$db) or die("<h2>Database Connection Failed. Contact Your Administrator</h2>");
?>
//When Form Submits
if(isset($_POST['submit'])) {
$product = $_POST['product'];
$cost = $_POST['cost'];
$other = $_POST['other'];
$otherOne = $_POST['otherOne'];
$code = $_POST['code'];
$price = $_POST['price'];
$qty = $_POST['qty'];
$kg = $_POST['kg'];
$value = $_POST['value'];
//Query
$query = "INSERT INTO managment(product, cost, other, otherOne, code, price, value) VALUES ('$product','$cost','$other', '$otherOne', '$code', '$price', '$qty', '$kg', 'value')";
mysqli_query($connection, $query);
header("location: home.php");
}
?>
<?php include("header.php"); ?>
<div class="content">
<br/>
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-2"></div>
<div class="col-lg-10 col-md-10 col-sm-8">
<div class="login-form">
<form method="post">
<div class="row">
<div class="col-lg-6">
<input class="form-control" type="text" name="product" placeholder="Product..."><br>
</div>
<div class="col-lg-6">
<input class="form-control" type="text" name="code" placeholder="Code..."><br>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<input class="form-control" type="text" name="cost" placeholder="Cost..."><br>
</div>
<div class="col-lg-6">
<input class="form-control" type="text" name="price" placeholder="Price..."><br>
</div>
</div>
<input class="form-control" type="text" name="other" placeholder="Other..."><br>
<input class="form-control" type="text" name="otherOne" placeholder="Other..."><br>
<label class="radio-inline">
<input type="radio" name="qty" id="qty" value="qty"> Quantity
</label>
<label class="radio-inline">
<input type="radio" name="kg" id="kg" value="kg"> Kilograms
</label>
<br><br>
<input class="form-control" type="number" step="1.00" name="value" placeholder="Quantity / Kilograms"><br>
<input class="btn btn-primary pull-right" type="submit" name="submit" value="Add Record">
</form>
<br/>
<br/>
</div>
</div>
<div class="col-lg-10 col-md-10 col-sm-2"></div>
</div>
</div>
<?php include("footer.php"); ?>
You are missing the $ from value
$query = "INSERT INTO managment(product, cost, other, otherOne, code, price, value) VALUES ('$product','$cost','$other', '$otherOne', '$code', '$price', '$qty', '$kg', '$value')";

How to insert multiple rows of data [duplicate]

This question already has answers here:
Why can't I run two mysqli queries? The second one fails [duplicate]
(2 answers)
Closed 6 years ago.
I am trying to create a php/html form which will insert results into a dog show database. The problem no matter what I do I get this error:
QUERY FAILED .You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO.
Here is the code for the page any help appreciated.
<?php
if(isset($_POST['create_show'])) {
//Insert Judges
$show_title = escape($_POST['show_title']);
$show_user = escape($_POST['show_user']);
$show_category_id = escape($_POST['show_category_id']);
$show_status = escape($_POST['show_status']);
// $show_image = escape($_FILES['show_image']['name']);
//$show_image_temp = escape($_FILES['image']['tmp_name']);
$show_tags = escape($_POST['show_tags']);
$show_content = escape($_POST['show_content']);
//$show_date = escape(date('d-m-y'));
//INSERT Judges
$judge_affix = escape($_POST['judge_affix']);
$judge_name = escape($_POST['judge_name']);
$judge_show = escape($_POST['show_idj']);
//Insert Dogs
$dog_name = escape($_POST['dog_name']);
$resultIDD = escape($_POST['resultIDD']);
//Insert Into Results
$class_name = escape($_POST['class_name']);
$placement = escape($_POST['placement']);
$award = escape($_POST['award']);
//move_uploaded_file($show_image_temp, "../images/$show_image" );
//Insert Shows
$query = "INSERT INTO shows (show_category_id, show_title, show_user, show_content, show_tags, show_status) VALUES ('$show_category_id','$show_title','$show_user','$show_content','$show_tags','$show_status');";
$query .= "INSERT INTO judges (judge_affix, judge_name) VALUES ('$judge_affix','$judge_name');";
$query .= "INSERT INTO dogs (dog_name, resultIDD) VALUES ('$dog_name','$resultIDD');";
$query .= "INSERT INTO result(class_name, placement,) VALUES ('$class_name','$placement')";
$create_show_query = mysqli_query($connection, $query);
confirmQuery($create_show_query);
$the_show_id = mysqli_insert_id($connection);
echo "<p class='bg-success'>Show Created. <a href='../show.php?s_id={$the_show_id}'>View Post </a> or <a href='shows.php'>Edit More Shows</a></p>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="show_title">Show Title</label>
<input type="text" class="form-control" name="show_title">
</div>
<div class="form-group">
<label for="category">Category</label>
<select name="show_category" id="">
<?php
$query = "SELECT * FROM categories";
$select_categories = mysqli_query($connection,$query);
confirmQuery($select_categories);
while($row = mysqli_fetch_assoc($select_categories )) {
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<option value='$cat_id'>{$cat_title}</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="users">Users</label>
<select name="post_user" id="">
<?php
$users_query = "SELECT * FROM users";
$select_users = mysqli_query($connection,$users_query);
confirmQuery($select_users);
while($row = mysqli_fetch_assoc($select_users)) {
$user_id = $row['user_id'];
$username = $row['username'];
echo "<option value='{$username}'>{$username}</option>";
}
?>
</select>
</div>
<!-- <div class="form-group">
<label for="title">Post Author</label>
<input type="text" class="form-control" name="author">
</div> -->
<div class="form-group">
<select name="show_status" id="">
<option value="draft">Show Status</option>
<option value="published">Published</option>
<option value="draft">Draft</option>
</select>
</div>
<div class="form-group">
<label for="show_tags">Show Tags</label>
<input type="text" class="form-control" name="show_tags">
</div>
<div class="form-group">
<label for="judge_name">Show Tags</label>
<input type="text" class="form-control" name="judge_name">
</div>
<div class="form-group">
<label for="judge_affix">Show Tags</label>
<input type="text" class="form-control" name="judge_affix">
</div>
<div class="form-group">
<label for="show_content">Show Content</label>
<textarea class="form-control " name="show_content" id="" cols="30" rows="5">
</textarea>
</div>
<div class="form-group">
<p>Minor Puppy Dog</p>
</div>
<div class="form-group">
<label for="dog_name">1st Dog Name</label>
<input type="text" class="form-control" name="dog_name">
</div>
<div class="form-group">
<input type="hidden" class="form-control" name="placement" value="1">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="create_show" value="Publish Show">
</div>
</form>
The mysqli_query only executes one single query.
For executing multiple queries at once, you can use mysqli_multi_query.
Simply replace your mysqli_query with the mysqli_multi_query like so:
$create_show_query = mysqli_multi_query($connection, $query);

PHP undefined index id error [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
I am trying to submit this form and upon the submission it should redirect to itself back. However, the problem I am facing is that, after I submit the form it display this error:
Notice: Undefined index: id in C:\xampp\htdocs\iNetLink\configuration.php on line 9
Here is my form file:
<?php include("header.php");
if(ISSET($_POST['node'])){
$nodeID = $_POST['node'];
}else{
$nodeID = 0;
}
$requestID = $_GET['id'];
$qConfigurationForm = "SELECT * FROM configuration WHERE request_id = '$requestID' ";
$rConfigurationForm = $connection->query($qConfigurationForm);
$rowCount = $rConfigurationForm->rowCount();
$row = $rConfigurationForm->fetch();
if($rowCount > 0){
?>
<section id="content">
<section class="vbox">
<section class="scrollable padder">
<ul class="breadcrumb no-border no-radius b-b b-light pull-in">
<li></li>
</ul>
<div class="m-b-md">
<h3 class="m-b-none">Configuration</h3>
</div>
<section class="panel panel-default">
<!-- Tabs for navigation -->
<?php include("tabs.php");?>
</section>
<!-- Tabs for navigation ended -->
<!--forms-->
<section class="panel panel-default">
<header class="panel-heading font-bold">Line Configuration Information</header>
<div class="panel-body">
<form class="form-horizontal" method="post" action="configuration.php" data-validate="parsley">
<div class="col-md-6">
<div class="form-group">
<label class="col-sm-3 control-label" for="requestID"></label>
<div class="col-sm-6">
<input type="hidden" name="requestID" id="requestID" value="<?php echo $requestID;?>">
<input type="hidden" name="isUpdate" value="1" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Node</label>
<div class="col-sm-6">
<select name="node" id="node" class="form-control m-b" onchange="GetId()" data-required="true">
<option></option>
<?php
$qNode = "SELECT id,node FROM node WHERE id = '$nodeID'";
$rNode = $connection->query($qNode);
foreach($rNode as $node){
$nodeid = $node['id'];
$nodeName = $node['node'];
echo "<option value=\"$nodeid\" selected=\"selected\">$nodeName</option>";
}
echo "<optgroup></optgroup>";
$qNode = "SELECT id,node FROM node WHERE `status` = 1";
$rNode = $connection->query($qNode);
foreach($rNode as $node){
$nodeid = $node['id'];
$nodeName = $node['node'];
echo "<option value=\"$nodeid\">$nodeName</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Connection Type</label>
<div class="col-sm-6">
<select name="connectionType" id="connectionType" class="form-control m-b" data-required="true">
<option></option>
<?php
$connection_type = $row['connection_type'];
$qConnectionConfigType = "SELECT * FROM `connection_type_config` WHERE id = '$connection_type'";
$rConnectionConfigType = $connection->query($qConnectionConfigType);
foreach($rConnectionConfigType as $connectionConfigType){
$connectionConfigID = $connectionConfigType['id'];
$connectionType = $connectionConfigType['connection_type'];
echo "<option value=\"$connectionConfigID\" selected=\"selected\">$connectionType</option>";
}
echo "<optgroup></optgroup>";
$qConnectionConfigType = "SELECT * FROM `connection_type_config`";
$rConnectionConfigType = $connection->query($qConnectionConfigType);
foreach($rConnectionConfigType as $connectionConfigType){
$connectionConfigID = $connectionConfigType['id'];
$connectionType = $connectionConfigType['connection_type'];
echo "<option value=\"$connectionConfigID\">$connectionType</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="timeSlot">Time Slot</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="timeSlot" name="timeSlot" value="<?php echo $row['time_slot'];?>" data-required="true">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="dslUnifiNo">DSL/Unifi Username</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="dslUnifiNo" name="dslUnifiNo" value="<?php echo $row['dsl_username'];?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="remarksConfig">Remarks</label>
<div class="col-sm-6">
<textarea rows="4" cols="50" class="form-control" id="remarksConfig" name="remarksConfig"><?php echo $row['remarks'];?></textarea>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-sm-3 control-label">Port</label>
<div class="col-sm-6">
<select name="portNo" id="portNo" name="portNo" class="form-control m-b" data-required="true">
<!-- <option></option>
<?php
$qPortNo = "SELECT * FROM node_port WHERE node_id = '$nodeID' AND `status` = 1";
$rPortNo = $connection->query($qPortNo);
foreach($rPortNo as $portNo){
$portID = $portNo['id'];
$number = $portNo['port_no'];
echo "<option value=\"$portID\">$number</option>";
}
?> -->
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">E1 Circuit No.</label>
<div class="col-sm-6">
<select name="e1circuitNo" id="e1circuitNo" class="form-control m-b">
<option></option>
<?php
$e1_circuit_no = $row['e1_curcuit_no'];
$qE1Type = "SELECT * FROM `e1_type` WHERE id = '$e1_circuit_no'";
$rE1Type = $connection->query($qE1Type);
foreach($rE1Type as $e1Type){
$e1ID = $e1Type['id'];
$type = $e1Type['type'];
echo "<option value=\"$e1ID\" selected=\"selected\">$type</option>";
}
echo "<optgroup></optgroup>";
$qE1Type = "SELECT * FROM `e1_type`";
$rE1Type = $connection->query($qE1Type);
foreach($rE1Type as $e1Type){
$e1ID = $e1Type['id'];
$type = $e1Type['type'];
echo "<option value=\"$e1ID\">$type</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Changed Date</label>
<div class="col-sm-6">
<input class="input-m input-m form-control" type="date"
data-date-format="dd-mm-yyyy" id="changedDate" name="changedDate" value="<?php echo $row['changed_date'];?>" data-required="true">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="dslUnifiIp">DSL/Unifi IP</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="dslUnifiIp" name="dslUnifiIp" value="<?php echo $row['dsl_ip'];?>">
</div>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div class="btn-toolbar pull-right">
<input type="hidden" name="id" value="<?=$requestID;?>">
<input class="btn btn-warning " type="reset" value="Reset" name="reset" >
<input class="btn btn-info " type="submit" value="Save Draft" name="saveDraft">
<input class="btn btn-success " type="submit" value="Submit" name="Submit">
</div>
</div>
</form>
</div>
</section>
Line 9 is the $requestID = $_GET['id'];
Here is the executer for the form:
<?php
include("dbconnection.php");
session_start();
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
$requesterID = $_SESSION['id'];
print_r($_POST);
$node = $_POST['node'];
$connectionType = $_POST['connectionType'];
$timeSlot = $_POST['timeSlot'];
$dslUnifiNo = $_POST['dslUnifiNo'];
$remarksConfig = $_POST['remarksConfig'];
$port = $_POST['port'];
$e1circuitNo = $_POST['e1circuitNo'];
$changedDate = $_POST['changedDate'];
$dslUnifiIp = $_POST['dslUnifiIp'];
$requestID = $_POST['requestID'];
if(ISSET($_POST['isUpdate'])){
$qinsert = "UPDATE configuration SET
node = '$node',
connection_type = '$connectionType',
time_slot = '$timeSlot',
dsl_username = '$dslUnifiNo',
remarks = '$remarksConfig',
port = '$port',
e1_curcuit_no = '$e1circuitNo',
changed_date = '$changedDate',
dsl_ip = '$dslUnifiIp'
WHERE request_id = '$requestID'";
}else
{
$qinsert = "REPLACE INTO configuration SET
node = '$node',
connection_type = '$connectionType',
time_slot = '$timeSlot',
dsl_username = '$dslUnifiNo',
remarks = '$remarksConfig',
port = '$port',
e1_curcuit_no = '$e1circuitNo',
changed_date = '$changedDate',
dsl_ip = '$dslUnifiIp',
request_id = '$requestID'";
$requestID = $connection->lastInsertId();
if($status == 1){
$action = "lineApplication.php";
$dateCreated = date("Y-m-d H:i:s");
$userTypeID = 5;
$qinsertTss = "INSERT INTO notifications SET
user_id = '$requesterID',
action = '$action',
item_id = '$requestID',
created_at = '$dateCreated',
receive_user_type_id = '$userTypeID'";
$rinsertTss = $connection->query($qinsertTss);
}
}
$rinsert = $connection->query($qinsert);
header("location:configuration.php?id=$requestID");
Help! :)
You are sending you're POST to configuration.php not to your executer?
<form class="form-horizontal" method="post" action="configuration.php" data-validate="parsley">
Also...
$requestID = $_GET['id'];
this will error because $_GET['id'] is not available during POST. to fix your code try this:
$requestID = (isset($_GET['id'])) ? $_GET['id'] : 'add ID for POST';
or make sure your form is sending in the right PHP file

Undefined Variable on this tutorial on PHP with Bootstrap

Please help me fix this undefined variable I copy and pasted this code on my create.php and when i hit the create button on the home page i get this:
Notice: Undefined variable: fnameError in
C:\xampp\htdocs\TestCRUD\create.php on line 70
Notice: Undefined variable: lnameError in
C:\xampp\htdocs\TestCRUD\create.php on line 75
Notice: Undefined variable: ageError in
C:\xampp\htdocs\TestCRUD\create.php on line 80
Notice: Undefined variable: genderError in C:\xampp\htdocs\TestCRUD\create.php on line 89
<?php
if ( !empty($_POST)) {
require 'db.php';
// validation errors
$fnameError = null;
$lnameError = null;
$ageError = null;
$genderError = null;
// post values
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$age = $_POST['age'];
$gender = $_POST['gender'];
// validate input
$valid = true;
if(empty($fname)) {
$fnameError = 'Please enter First Name';
$valid = false;
}
if(empty($lname)) {
$lnameError = 'Please enter Last Name';
$valid = false;
}
if(empty($age)) {
$ageError = 'Please enter Age';
$valid = false;
}
if(empty($gender)) {
$genderError = 'Please select Gender';
$valid = false;
}
// insert data
if ($valid) {
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO users (fname,lname,age,gender) values(?, ?, ?, ?)";
$stmt = $PDO->prepare($sql);
$stmt->execute(array($fname,$lname,$age,$gender));
$PDO = null;
header("Location: index.php");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="row">
<h3>Create a User</h3>
</div>
<form method="POST" action="">
<div class="form-group <?php echo !empty($fnameError)?'has-error':'';?>">
<label for="inputFName">First Name</label>
<input type="text" class="form-control" required="required" id="inputFName" value="<?php echo !empty($fname)?$fname:'';?>" name="fname" placeholder="First Name">
<span class="help-block"><?php echo $fnameError;?></span>
</div>
<div class="form-group <?php echo !empty($lnameError)?'has-error':'';?>">
<label for="inputLName">Last Name</label>
<input type="text" class="form-control" required="required" id="inputLName" value="<?php echo !empty($lname)?$lname:'';?>" name="lname" placeholder="Last Name">
<span class="help-block"><?php echo $lnameError;?></span>
</div>
<div class="form-group <?php echo !empty($ageError)?'has-error':'';?>">
<label for="inputAge">Age</label>
<input type="number" required="required" class="form-control" id="inputAge" value="<?php echo !empty($age)?$age:'';?>" name="age" placeholder="Age">
<span class="help-block"><?php echo $ageError;?></span>
</div>
<div class="form-group <?php echo !empty($genderError)?'has-error':'';?>">
<label for="inputGender">Gender</label>
<select class="form-control" required="required" id="inputGender" name="gender" >
<option></option>
<option value="male" <?php echo $gender == 'male'?'selected':'';?>>Male</option>
<option value="female" <?php echo $gender == 'female'?'selected':'';?>>Female</option>
</select>
<span class="help-block"><?php echo $genderError;?></span>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Create</button>
<a class="btn btn-default" href="index.php">Back</a>
</div>
</form>
</div> <!-- /row -->
</div> <!-- /container -->
</body>
</html>
You're displaying errors even when the variables haven't been set. That brings up the notice you see. You can avoid them by checking if they are set first using isset or empty
<?= isset($someError) ? $someError : '' ?>
use isset();
// post values
$fname = isset($_POST['fname']);
$lname = isset($_POST['lname']);
$age = isset($_POST['age']);
$gender = isset($_POST['gender']);
On the lines like the following, you need to check that the variables have a value before trying to use them. So the following code...
<span class="help-block"><? echo $fnameError; ?></span>
...should be changed to this:
<span class="help-block"><?= isset($fnameError) ? $fnameError : ''; ?></span>
To prevent these errors being picked up and displayed you could also turn PHP error reporting off but fixing the problem is preferable:
<?php
error_reporting('off');
ini_set('display_errors', 'off');
You can added a hidden type input to form for process after send parameters:
PHP:
<?php
if (isset($_POST['h'])) {
....//your process
}
?>
HTML:
<form action="" method="POST">
.....<!--your input-->
<input type="hidden" name="h" value="true">
<button type="submit"> submit </button>
</form>

Categories