Here is my problem I tray to write data to mysql but when I do input
and press submit button, got console log message from function wich
mean everythig is ok, but when I look to db have nothing to see. Can
anyone help me.
Second thing what I need to do is SELECT data from that db, then
that data + new data from input = data save to db.
here is html code :
<div class="body-content bg-1">
<div class="col-sm-12 col-xs-12" ng-controller="UnosUSkladisteCtrl">
<div class="container">
<div class="alert alert-info alert-dismissable"><strong>Info!</strong> {{data.message}}</div>
<div class="center">
<h1>Ulaz robe u skladište</h1>
</div>
<p ng-controller="LoginCtrl">Dobro došao <b>{{deName}}</b> | <a id="logout" href ng-click="logout()">Odjava</a></p>
</div>
<div class="nav-button center col-sm-4 col-xs-4">Povratak</div>
<div>
<form class="form-horizontal col-xs-12" col-sm-12" name="signUpForm" ng-submit="submitFormSignUp()" novalidate>
<!-- Zlatni medvjed -->
<div class="form-group" ng-class="">
<label class="col-sm-4 col-xs-12 control-label no-padding-right " for="zlatni_medvjed">Zlatni medvjed boca 0.5l</label>
<div class="col-sm-4 col-xs-12">
<span class="block input-icon input-icon-right">
<input ng-model="zlatni_medvjed" placeholder="Količina boca 0.5l" type="number" class="form-control">
</span>
</div>
</div>
<!-- Crna kraljica -->
<div class="form-group" ng-class="">
<label class="col-sm-4 col-xs-12 control-label no-padding-right " for="crna_kraljica">Crna kraljica boca 0.5l</label>
<div class="col-sm-4 col-xs-12">
<span class="block input-icon input-icon-right">
<input ng-model="crna_kraljica" placeholder="Količina boca 0.5l" type="number" class="form-control">
</span>
</div>
</div>
<!-- Grička vještica -->
<div class="form-group" ng-class="">
<label class="col-sm-4 col-xs-12 control-label no-padding-right " for="gricka_vjestica">Grička vještica boca 0.5l</label>
<div class="col-sm-4 col-xs-12">
<span class="block input-icon input-icon-right">
<input ng-model="gricka_vjestica" placeholder="Količina boca 0.5l" type="number" class="form-control">
</span>
</div>
</div>
<!-- Dva klasa -->
<div class="form-group" ng-class="">
<label class="col-sm-4 col-xs-12 control-label no-padding-right " for="dva_klasa">Dva klasa boca 0.5l</label>
<div class="col-sm-4 col-xs-12">
<span class="block input-icon input-icon-right">
<input ng-model="dva_klasa" placeholder="Količina boca 0.5l" type="number" class="form-control">
</span>
</div>
</div>
<!-- SUBMIT BUTTON -->
<label class="col-sm-4 control-label no-padding-right"></label>
<div class="col-sm-4">
<button ng-click="insertdata()" type="submit" class="btn btn-primary btn-lg btn-block">Unesi količine u skladište</button>
</div>
</form>
</div>
</div>
Here is js file code :
angular.module('angularLoginApp')
.controller('UnosUSkladisteCtrl', function($scope,$http) {
$scope.insertdata = function(){
$http.post("database/unos-piva.php", {'zlatni_medvjed':$scope.zlatni_medvjed, 'crna_kraljica':$scope.crna_kraljica, 'gricka_vjestica':$scope.gricka_vjestica, 'dva_klasa':$scope.dva_klasa })
.success(function(data,status,headers,config){
console.log("Podaci uspiješno spremljeni");
alert("Nove količine piva su dodane u skladište");
});
}
$scope.data = {message: "Molimo vas da točno navedete što unosite u skladište"};
});
and this is PHP file code to connect :
<?php
$data = json_decode(file_get_contents("php://input"));
$zlatni_medvjed = mysql_real_escape_string($data->zlatni_medvjed);
$crna_kraljica = mysql_real_escape_string($data->crna_kraljica);
$gricka_vjestica = mysql_real_escape_string($data->gricka_vjestica);
$dva_klasa = mysql_real_escape_string($data->dva_klasa);
mysql_connect("localhost","root","");
mysql_select_db("medvedgrad");
mysql_query("INSERT INTO stanje_piva(`zlatni_medvjed`, `crna_kraljica`, `gricka_vjestica`,`dva_klasa`)VALUES('"$zlatni_medvjed"','"$crna_kraljica"','"$gricka_vjestica"','"$dva_klasa"')")
?>
mysql columns
zlatni_medvjed, crna_kraljica, gricka_vjestica, dva_klasa
The format of the insert statement is wrong - you are incorrectly using quotes ( both single and double ) and the statement was not terminated with a semi-colon.
mysql_query("
INSERT INTO stanje_piva(`zlatni_medvjed`, `crna_kraljica`, `gricka_vjestica`,`dva_klasa`)
VALUES('{$zlatni_medvjed}','{$crna_kraljica}','{$gricka_vjestica}','{$dva_klasa}')
");
That said, this sql is vulnerable to sql injection and you are using the now deprecated mysql_* class - upgrade your code to mysqli or PDO and learn how to use Prepared Statements
As for the second question do an update stanje_piva ... set field=field+new data.... where id=1 etc ~ you would not need the initial select statement
Related
So, I cannot find the solution to the problem I'm having. I'm really new to coding but learned how to start coding using basic HTML, PHP, PDO, and AJAX. So my problem comes from a form that retrieves dates from a calendar using the type=date from the form. The code of the form is down below.
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title text-center"><i class="fa fa-bar-chart fa-fw"></i> Ingreso de reporte</h3>
</div>
<div id="alert_success" class="panel-body">
<br>
<form method="post" class="form-horizontal" role="form" action="ajax_form_post.php" id="insertreport">
<div class="form-group">
<label class="control-label col-sm-2" for="video" style="color:#777;">ID de video</label>
<div class="col-sm-10">
<input type="text" name="video" class="form-control" id="video" placeholder="Ingresa id del video" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="date_i" style="color:#777;">Fecha de arriendo</label>
<div class="col-sm-10">
<input type="date" name="date_i" class="form-control" id="date_i" placeholder="" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="date_f" style="color:#777;">Fecha de devolución</label>
<div class="col-sm-10">
<input type="date" name="date_f" class="form-control" id="date_f" placeholder="" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="hidden" name="c_id" class="form-control" id="user_id" value="<?php echo $id ?>" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" name="update_customer" value="Enviar" id="submitdata">
</div>
</div>
</form>
<div class="text-right">
<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</div>
</div>
Now the problem starts with this Ajax form I built. BTW the script is working fine, the problem is inside this set of code.
<?php
/****************Get customer info to ajax *******************/
//require database class files
require("includes/pdocon.php");
//instatiating our database objects
$db = new Pdocon ;
if(isset($_POST['c_id'])){
$id = $_POST['c_id'];
$date_i = date("Y-m-d", strtotime($_POST['date_i']));
$date_f = date("Y-m-d", strtotime($_POST['date_f']));
$raw_v_id = clean_data($_POST['video']);
$v_id = val_int($raw_v_id);
$db->query('SELECT * FROM videos WHERE v_id = :v_id');
$db->bindvalue(':v_id', $v_id, PDO::PARAM_INT);
$row = $db->fetchSingle();
$db->query('INSERT INTO arriendo (transaccion, c_id, v_id, f_arriendo, f_devolucion)
VALUES (NULL, :c_id, :v_id :f_arriendo, :f_devolucion)');
$db->bindvalue(':f_arriendo', $date_i, PDO::PARAM_STR);
$db->bindvalue(':f_devolucion', $date_f, PDO::PARAM_STR);
$db->bindvalue(':c_id', $id, PDO::PARAM_INT);
$db->bindvalue(':v_id', $v_id, PDO::PARAM_INT);
$run = $db->execute();
}
if($run){
echo "<p class='bg-success text-center' style='font-weight:bold;'>Valor actualizado </p>";
}
?>
I get the following error:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''2021-08-05', '2021-08-06')' at line 2
Any help or a little guidance would be greatly appreciated. Thanks in advance.
all inputs are retrieved but unable to get the array(sp_serail[]) value when I check count using PHP I got count 1 array(sp_serail[]) count but the actual count will be 3. I can retrieve all input but the only array is not working
I tried all the possibility
($serial_no = array($_POST['sp_serail[]']);
//$serial_no = array($_POST['sp_serail']);)
When I submit all form data will posted I got output in google dev
tool(Network->header)->Form Data
user_id:4
bar_code: 1234
age_stock: 25
eng_stock: 12
sp_name: tst1
sp_qty: 3
sp_serail[]: 123457
sp_serail[]: 123456
sp_serail[]: 12345
<form action="issue_mat.php.php" id="Addqty" method="post">
<input list="eng_name" class="form-control has-feedback-left" name="eng_mobile" id="eng_mobile" placeholder="Enter Eng Mobile">
<span class="fa fa-file form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-6 col-sm-6 col-xs-12 ">
<input type="text" class="form-control has-feedback-left" id="bar_code" name="bar_code" placeholder="BarCode">
<span class="fa fa-barcode form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 ">
<input type="text" class="form-control" id="age_stock" name="age_stock" placeholder="WH Stock">
</div>
<div class="col-md-3 col-sm-3 col-xs-12 ">
<input type="text" class="form-control" id="eng_stock" name="eng_stock" placeholder="Eng Stock">
<input type="hidden" id="sp_name" name="sp_name" value="tst1">
</div>
<div class="col-md-6 col-sm-6 col-xs-12 ">
<input type="text" class="form-control" id="sp_qty" name="sp_qty" placeholder="QTY">
<input type="hidden" id="chk_sp_qty" name="chk_sp_qty" value="0">
</div>
<div class="col-md-6 col-sm-6 col-xs-12 ">
<input list="serial no." class="form-control has-feedback-left" name="add_serial" id="add_serial" placeholder="Item Serial No.">
<span class="fa fa-plus-square-o form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-6 col-sm-6 col-xs-12" id="seral_list">
<div class="x_panel">
<div class="x_title">
<h2>Serial NO |<small>Added spare serial no.</small></h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<div class="">
<ul class="to_do" id="list_serial"><li><p>12345</p><span style="float:right; top:-20px; position: relative;"><i id="46" class="del_serial fa fa-close" style="font-size:12px;color:red"></i></span><input type="hidden" value="12345" name="sp_serail" id="sp_serail"></li><li><p>123456</p><span style="float:right; top:-20px; position: relative;"><i id="44" class="del_serial fa fa-close" style="font-size:12px;color:red"></i></span><input type="hidden" value="123456" name="sp_serail" id="sp_serail"></li>
</div>
</div>
</div>
</div>
<div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3" id="butt_ons" style="bottom:-90px; position:relative;">
<button class="btn btn-primary" type="reset">Reset</button>
<button type="submit" id="edit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
$("#Addqty").on('submit',(function(e) {
$("#issue_data").html('');
e.preventDefault();
$.ajax({
url: "system/issue_mat.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data){
$("#issue_data").html(data);
},
error: function(){}
});
}));
`if($_POST['user_id']) {
$user_id=$_POST['user_id'];
$bar_code=$_POST['bar_code'];
$sp_qty=$_POST['sp_qty'];
$age_stock=$_POST['age_stock'];
$sp_name=$_POST['sp_name'];
$status=1;
$serial_no = array($_POST['sp_serail[]']);
//$serial_no = array($_POST['sp_serail']);
$spr_count = count($serial_no);
echo " $spr_count";
}
I want to retrieve all input with an actual array
When an input has a name like sp_serail[], PHP will put an array in $_POST['sp_serail'], it doesn't create $_POST['sp_serail[]']. So you need to do:
$serial_no = $_POST['sp_serail'];
$spr_count = count($serial_no);
Rectified and got the solution
Removed ($serial_no = array($_POST['sp_serail[]']);
//$serial_no = array($_POST['sp_serail']);)
becasue array post with array only no need to convert array into array
I want to update the data with PHP.when I click the button, the page refreshes and the update does not occur. How to correct
MY CODES:
File Name:Contact_settings
<form action="../netting/islem.php" method="post" class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Gsm Number<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="ayar_tel" value="<?php echo $ayarcek['ayar_tel'] ?>" required="required" class="form-control col-md-7 col-xs-12">
</div>
<div class="form-group">
<div align="right" class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<button type="submit" name="iletisim" class="btn btn-success right">Güncelle</button>
</div>
</div>
FİLE NAME:islem.php
if(isset($_POST['iletisim'])){
$ayarkaydet = $db->prepare("UPDATE ayar SET
ayar_tel =:ayar_tel,
WHERE ayar_id=3
");
$update = $ayarkaydet->execute
(
array(
':ayar_tel' => $_POST['ayar_tel'],
)
);
you have an error in your code
must be like this
if(isset($_POST['iletisim'])){
$ayarkaydet = $db->prepare("UPDATE ayar SET ayar_tel =:ayar_tel WHERE ayar_id=3 ");
$update = $ayarkaydet->execute (array(':ayar_tel' => $_POST['ayar_tel']));
}
I delete two commas in your sql where and in your execute array and add a close } for the if sentence.
This question already has answers here:
Isset expression error
(3 answers)
Closed 6 years ago.
I'm doing an admin panel and I'm doing a form for adding users. My code below:
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Add user</legend>
<!-- Prepended text-->
<div class="form-group">
<label class="col-md-4 control-label" for="newuser">Username</label>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">#</span>
<input id="newuser" name="newuser" class="form-control" placeholder="Username" type="text" required="">
</div>
<p class="help-block">Put the new users username here</p>
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="userpw">New user password</label>
<div class="col-md-4">
<input id="userpw" name="userpw" type="password" placeholder="Password" class="form-control input-md" required="">
<span class="help-block">Enter new user's password here!</span>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="permissions">Choose permissions</label>
<div class="col-md-4">
<select id="permissions" name="permissions" class="form-control">
<option value="1">System administrator</option>
<option value="2">Editor</option>
<option value="3">Developer</option>
<option value="4">Normal user</option>
</select>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="btn_send">Send request to server</label>
<div class="col-md-4">
<button id="btn_send" name="btn_send" class="btn btn-primary">Send it!</button>
</div>
</div>
</fieldset>
</form>
<?php
$newuser = $_GET['newuser'];
$userpw = $_GET['userpw'];
$permission = $_GET['permissions'];
if(isset($newuser and $userpw and $permission) {
$sql = "INSERT INTO users(username,userpw,permission)VALUES('$newuser', '$userpw','$permission')";
mysql_query($sql);
}
else {
echo "error";}
And I Get:
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in C:\xampp\htdocs\lumino\usermanagement.php on line 95
I couldn't fix it anyhow, playing with this for like 5 hours.
It's doing $_GET method, so I get the url like:
mysite.com/usermanagement.php?newuser=Berkay&userpw=18042003&permissions=3&btn_send=
Using isset, you can't have multiple items inside it:
if(isset($newuser and $userpw and $permission) {
Needs to become:
if(isset($newuser) && isset($userpw) && isset($permission)) {
Or:
if(isset($newuser, $userpw, $permission)) {
You just miss a ) and a set of ,:
if(isset($newuser, $userpw, $permission)) {
$sql = "INSERT INTO users(username,userpw,permission)VALUES('$newuser', '$userpw','$permission')";
mysql_query($sql);
}
I am using Rivets to bind my form data. Is there any way to bind my input type file with the help rivet binders.
Like in this example https://jsfiddle.net/steinbring/v29vnLuh/ You can see that we bind text area . But how will we bind over input file .
Let me explain more
here is my form
<form class="product-inputs full-width-inputs" method="post" action="/create/save-manual-products-shopify">
<section id="rivettest">
<ul class="no-bullet">
<li class="product-input-header">
<div class="row no-padding">
<div class="small-2 columns">
<p>Product Name</p>
</div>
<div class="small-2 columns">
<p>Product Detail</p>
</div>
<div class="small-2 columns">
<p>Product Type</p>
</div>
<div class="small-2 columns">
<p>Price</p>
</div>
<div class="small-2 columns floatleft">
<p>Sku</p>
</div>
<div class="small-2 columns floatleft">
<p>Image</p>
</div>
</div>
</li>
<li class="product-input" rv-each-product="products">
<div class="row no-padding">
<div class="small-2 columns" style="position: relative">
<input class="product-name-input" type="text" rv-value="product.name" placeholder="New Product"/>
<span class="icon-error remove-btn" rv-on-click="controller.removeItem"></span>
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.product_detail"/>
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.product_type"/>
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.price">
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.sku">
</div>
<div class="small-2 columns">
<input type="file" rv-value="product.image">
<!-- <input type="file"> -->
<!-- <span class="icon-upload"></span> Upload Image -->
</div>
</div>
</li>
<li class="additem">
<span class="icon-plus"></span>Add Product Manually
</li>
</ul>
</section>
<input type="submit" value="Submit for KF Approval" class="button radius add-product-shopify" >
</form>
And here is my script
var products = [];
var controller = {
addItem: function(e, model) {
model.products.push({name: "New Product", product_detail: "", product_type: "", price: null, sku: null, image: ""});
e.preventDefault();
return false;
},
removeItem: function(e, model) {
var index = model.index;
if (index > -1) {
products.splice(index, 1);
}
},
};
rivets.bind($('#rivettest'), {products: products, controller: controller});
But when i submit my form i got this response
image: ""
name: "a"
price: "12"
product_detail: "b"
product_type: "c"
sku: "12"
Here you see that image param is empty ... please help me .Thanks
Here's a working example written in coffescript
controller = (el, data) ->
that = this
#email_valid = false
#update = ->
if #type == "file"
data[#id] = #files[0]
else
data[#id] = #value
#submit = ->
_data = new FormData()
Object.keys(data).forEach( (key) ->
_data.append(key, data[key])
)
req = new XMLHttpRequest()
req.open('POST', 'addUser', true)
req.onreadystatechange = (aEvt) ->
if req.readyState == 4
if req.status == 200
return req.responseText
else
return "Erreur pendant le chargement de la page.\n"
req.send(_data)
#email_validate = ->
re = /\S+#\S+\.\S+/
return re.test data.email
return this
rivets.components['user'] = {
# Return the template for the component.
template: ->
return tpl
# Takes the original element and the data that was passed into the
# component (either from rivets.init or the attributes on the component
# element in the template).
initialize: (el, data) ->
return new controller(el, data)
}
the form
<form enctype="multipart/form-data" class="form-horizontal" id="userForm">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="picture">Photo</label>
<div class="col-md-4">
<input rv-value="picture" rv-on-change="update" id="picture" name="picture" class="input-file" type="file">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Name</label>
<div class="col-md-4">
<input rv-value="name" id="name" rv-on-input="update" name="name" type="text" placeholder="Name" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="password">Password</label>
<div class="col-md-4">
<input rv-value="password" id="password" rv-on-input="update" name="password" type="text" placeholder="Password" class="form-control input-md">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="password-validate">Password Validate</label>
<div class="col-md-4">
<input rv-value="password-validate" rv-on-input="update" id="password-validate" name="password-validate" type="password" placeholder="Password" class="form-control input-md">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="save">Save</label>
<div class="col-md-4">
<button type="button" rv-on-click="submit" id="save" name="save" class="btn btn-primary">Save</button>
</div>
</div>
</fieldset>
</form>
and the server side
multipart = require('connect-multiparty');
multipartMiddleware = multipart();
app.post '/addUser', multipartMiddleware, (req, resp) ->
console.log(req.body, req.files)
You need to set your form to allow file upload using the enctype attribute.
<form enctype="multipart/form-data">
You can try to bind an onchange event to the file input:
<input type="file" rv-on-change="update" rv-value="product.image">
and create an update method in your controller that update the product.image value with the value of form.
this.update = function(){
model[this.id] = this.value
}