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')";
Related
I'm having a small college project about discussion room service. I'm stuck at updating the database of the rooms.
I already used mysqli_error() function, and that didn't return any error, I wonder why.
Here's my form code:
<?php
//Tahap 1. Buat koneksi Database
$host = "localhost";
$user = "root";
$pass = "";
$name = "pinjamruang";
$koneksi = mysqli_connect($host, $user, $pass, $name);
//Periksa apakah koneksi berhasil
if(mysqli_connect_errno()){
echo "Error: ";
echo mysqli_connect_error();
echo "<br /> Error Code: ";
echo mysqli_connect_errno();
die();
}
$sql = "SELECT * FROM ruangan";
$keranjang = mysqli_query($koneksi, $sql);
$row = mysqli_fetch_assoc($keranjang);
?>
<h1 class="page-header">Edit Karyawan</h1><br>
<form class="form-horizontal" action="process/process-ruangan-edit.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="inputKodeRuangan" class="col-sm-2 control-label">Kode Ruangan</label>
<div class="col-sm-10">
<input type="text" name="kode" class="form-control" id="inputKodeRuangan" value="<?php echo $row['kode'];?>" placeholder="Kode Ruangan">
</div>
</div>
<div class="form-group">
<label for="inputJumlahMeja" class="col-sm-2 control-label">Jumlah Meja</label>
<div class="col-sm-10">
<input type="number" name="meja" class="form-control" id="inputJumlahMeja" value="<?php echo $row['meja'];?>"placeholder="Jumlah Meja">
</div>
</div>
<div class="form-group">
<label for="inputJumlahKursi" class="col-sm-2 control-label">Jumlah Kursi</label>
<div class="col-sm-10">
<input type="number" name="kursi" class="form-control" id="inputJumlahKursi" value="<?php echo $row['kursi'];?>"placeholder="Jumlah Kursi">
</div>
</div>
<div class="form-group">
<label for="inputStatus" class="col-sm-2 control-label">Status</label>
<div class="col-sm-10">
<select name="status" class="form-control" id="inputStatus">
<option value="available">Tersedia</option>
<option value="unavailable">Tidak Tersedia</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputNote" class="col-sm-2 control-label">Catatan Khusus</label>
<div class="col-sm-10">
<input type="text" name="note" class="form-control" id="inputNote" value="<?php echo $row['note'];?>"placeholder="Catatan Khusus">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="hidden" name="id" value="<?php echo $row2['id']; ?>" />
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</form>
And here's my process code:
<?php
// Tahap 1. Buat koneksi database
$host = "localhost";
$user = "root";
$pass = "";
$name = "pinjamruang";
$koneksi = mysqli_connect($host, $user, $pass, $name);
//Periksa apakah koneksi berhasil
if(mysqli_connect_errno()){
echo "Error: ";
echo mysqli_connect_error();
echo "<br />Error Code: ";
echo mysqli_connect_errno();
die();
}
//Tahap 2. Lakukan Query SQL
// Dapatkan data dari form dan dibersihkan
$kode = mysqli_real_escape_string($koneksi, $_POST['kode']);
$meja = mysqli_real_escape_string($koneksi, $_POST['meja']);
$kursi = mysqli_real_escape_string($koneksi, $_POST['kursi']);
$status = mysqli_real_escape_string($koneksi, $_POST['status']);
$note = mysqli_real_escape_string($koneksi, $_POST['note']);
$sql = "UPDATE ruangan
SET kode = '$kode',
kursi = $kursi,
meja = $meja,
status = '$status',
note = '$note'
WHERE id = $_POST[id]";
mysqli_query($koneksi,$sql);
echo mysqli_error($koneksi);
//header('Location: ../index.php?page=ruangan');
?>
Any help would be much appreciated, I'm still really new at PHP and basically programming so, thanks a lot!
In your form code you are referencing $row2 which hasn't been defined yet.
<input type="hidden" name="id" value="<?php echo $row2['id']; ?>" />
You should change it to
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
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?
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 6 years ago.
I checked source code ten times but can't find anymistake,for some reason i remember it was working now it doesn't work,i didn't change anything elsewhere to blame everything wors except update,when iclick Edit button it gives error,meaning that there was something wrong with query.
<?php
$editId = $_GET['id'];
$event = mysqli_query($con, "SELECT * FROM events WHERE id = '$editId'")->fetch_assoc();
if(isset($_POST['submit'])){
$name = $_POST['name'];
$description = $_POST['description'];
$date = $_POST['date'];
$artists = $_POST['artists'];
$tickets = $_POST['tickets'];
$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', ticket='$tickets' WHERE id = '$editId'");
}
?>
<?php if(isset($updateQuery) && $updateQuery): ?>
<div class="alert alert-success">
<strong>Successfully Edited</strong>
</div>
<?php endif; ?>
<?php if(isset($updateQuery) && !$updateQuery): ?>
<div class="alert alert-danger">
<strong>Error</strong>
</div>
<?php endif; ?>
<form action="<?php echo $app_host; ?>/admin/?page=editevent&id=<?php echo $editId; ?>" method="post">
<div class="form-group">
<label for="name">Name</label>
<input value="<?php echo $event['name']; ?>" required="true" type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description"><?php echo $event['description'];; ?></textarea>
</div>
<div class="form-group">
<label for="date">Date</label>
<input value="<?php echo $event['date']; ?>" required="true" type="text" class="form-control" id="date" name="date">
</div>
<div class="form-group">
<label for="artists">Artists</label>
<input value="<?php echo $event['artists']; ?>" required="true" type="text" class="form-control" id="artists" name="artists" data-role="tagsinput">
</div>
<div class="form-group">
<label for="tickets">Ticket Link</label>
<input value="<?php echo $event['tickets']; ?>" required="true" type="text" class="form-control" id="tickets" name="tickets" data-role="tagsinput">
</div>
<input name="submit" type="submit" class="btn btn-default" value="Edit Event" />
</form>
Okay,so you declare a variable ,
$tickets = $_POST['tickets'];
and than you say
$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', ticket='$tickets' WHERE id = '$editId'");
}
and solution is simple:
$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', tickets='$tickets' WHERE id = '$editId'");
}
simply changed 'ticket' in query to 'tickets'.
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);
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);