php


Update a field multiplying another field and a constant in sql with php [closed]


I have to do this:
UPDATE mytable SET value1 = (value2 * X)
Where value1 and value2 are fields of that table, and X is a constant, defined by the user.
How can I make it work?
Here's how to do it using PDO syntax for prepared statements.
$stmt = $pdo->prepare("UPDATE mytable SET value1 = value2 * :x");
$stmt->bindParam(':x', $variable_from_user);
$stmt->execute();
Mysqli syntax is similar.
$stmt = $mysqli->prepare("UPDATE mytable SET value1 = valu2 * ?");
Stmt->bind_param("i", $variable_from_user);
$stmt->execute();

Related Links

Can a variable named as `$something` be referred to by `someting`, that is without the dollar sign?
Cannot login to php page when sql column type is changed from TEXT to varchar
Caesar Cipher not running as expected
User Profile Creation
PHP get time from personal identity number under 1970
Use Product Image as category Image in Virtuemart
Swiftmailer: Missing space in subject email
Implode multidimensional array with different glue in php
Generating a random number not working on live server
How do I use or operator in PHP?
Continuously skip an element in foreach loop
Using interfaces in PHP
Creating a “Numbers Grid” with for() *logic thing*
php - AND with two condition
Allowed memory size greater than required but throwing fatal error
Displaying XML dynamically using PHP and URL variables

Categories

HOME
apache-nifi
gaming
mpdf
vagrant
workflow
swi-prolog
antd
initialization
iverilog
mongoid
twitter-fabric
dronekit-python
azure-data-lake
openfoam
ag-grid
responsive-design
tup
msmq
scrape
locationmanager
jquery-select2-4
grocery-crud
social-tables
neo4j.rb
intel
ini
eclipse-emf
spreadsheetgear
bonita
boolean-logic
guice
publishing
cucumber-junit
overwrite
sca
creation
busboy
uivisualeffectview
sspi
assemblies
sbjson
export-to-pdf
access-denied
httphandler
adblock
realstudio
sonicmq
nusoap
comm
android-sharing
watir-webdriver
aurelia-fetch-client
dex
word-2016
front-camera
adobe-reader
oracle-fusion-apps
yargs
xmlbeans
powerpoint-2013
codecharge
mnesia
accessibilityservice
management-studio-express
flush
deeplink
perceptron
arbre
mousehover
blank-line
search-form
android-handler
darwin
kefir.js
deque
fuseesb
htmltidy
iodocs
jquery-mobile-flipswitch
mobile-country-code
distributed-r
mfmessagecomposeview
reference-counting
thruway
gpu-programming
jomsocial
jms-serializer
vlab
codahale-metrics
getopt-long
image-scanner
type-safety
gwt-celltable
mmc3
differentiation
rtd
django-pagination
aptitude
reliability
aspbutton
parentid

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile