logo
down
shadow

PDO query to mysql with a numeric name for mysql column. How to execute properly


PDO query to mysql with a numeric name for mysql column. How to execute properly

By : user2956035
Date : November 22 2020, 10:48 AM
hope this fix your issue PDO does not permit you to use a bound parameter as a column or table identifier so it is not directly possible to use :category with prepare()/execute() and successfully substitute a numeric column name.
But if you can safely validate the numeric column name from your dropdown menu to prove it is in an acceptable range and is indeed an integer, then it is safe to use a variable in the query. You will need to quote it with backticks as you are already aware.
code :
// Validate $cateogry
// Assuming it came from $_POST['category']
$category = isset($_POST['category']) ? $_POST['category'] : null;

// And assuming the possible range was 1 - 4
// Ensure the input value was an integer with ctype_digit()
if (ctype_digit($category) && $category >= 1 && $category <=4) {
  // Execute the query with a backtick-quoted $category
  // Since you aren't going to bind any params, you can skip the overhead of
  // prepare()/bindParam()/execute() and just call query() instead
  $result = $conn->query("SELECT * FROM account where `$category` = '1' order by rand()");
  if ($result) {
    // Fetch rows and do whatever you planned with them
    $rows = $result->fetchAll(PDO::FETCH_ASSOC);
  }
}
else {
  // Invalid value, don't perform your query, show an error, etc....
}
if (in_array($category, range(1, 4))) {
  // $category is valid - go ahead and query with it as above
} 


Share : facebook icon twitter icon
setup a Mysql query to display a numeric column in particular order?

setup a Mysql query to display a numeric column in particular order?


By : Eric Hill
Date : March 29 2020, 07:55 AM
Does that help I have a user input box, querying a column of numbers in my SQL database, which, for example are:
code :
SELECT  *
FROM    mytable
ORDER BY
        ABS(value - 4.0), SIGN(value - 4.0)
PHP MYSQL Couldn't execute query: Unknown column

PHP MYSQL Couldn't execute query: Unknown column


By : pranav dhingra
Date : March 29 2020, 07:55 AM
may help you . Please help me to figure out this. The first query would return a message saying that , replace this:
code :
$result = mysqli_query($con, "DELETE FROM Tools WHERE PartNumber = {'$_POST['pnumber']'}") or die ("Couldn't execute query: " .mysqli_error($con));
$result = mysqli_query($con, "DELETE FROM Tools WHERE PartNumber = '" . $_POST['pnumber'] ."'") or die ("Couldn't execute query: " .mysqli_error($con));
$sql= 'DELETE FROM Tools WHERE PartNumber= ?';      

$stmt = $con->prepare($sql); 
$stmt->bind_param('i', $_POST['pnumber']);
$stmt->execute();
Query to copy 5 numeric characters from a string to a separate column in MySQL

Query to copy 5 numeric characters from a string to a separate column in MySQL


By : JesseM
Date : March 29 2020, 07:55 AM
I wish this help you In a specific column in my database, I have a lot of strings like , Tables:
code :
CREATE TABLE table2 (`text` varchar(49));

INSERT INTO table2 (`text`)
VALUES
    ('sometext sometext 12345 some more text 33'),
    ('some 12345 text then some random characters 12-13'),
    ('text text text 3 text');
select
t.text,
substring_index(substring_index(t.text, ' ', n.number), ' ', -1) as 'extracted_number'
from
table2 as t,
(select 1 as 'number' union select 2 union select 3 union select 4 union select 5 union select 6  union select 7 union select 8)  as n
where 
t.text REGEXP '[0-9]{5}'
and substring_index(substring_index(t.text, ' ', n.number), ' ', -1) REGEXP '^[0-9]{5}$'
text                                                extracted_number
some 12345 text then some random characters 12-13   12345
sometext sometext 12345 some more text 33           12345
How to exclude non-numeric column results from MySQL query?

How to exclude non-numeric column results from MySQL query?


By : Eoin Horgan
Date : March 29 2020, 07:55 AM
To fix the issue you can do According to this:
code :
... AND value REGEXP ('[0-9]')
... AND value REGEXP ('^[0-9]+$')
^      "From the begining of the string..."
[0-9]  "There should be a number..."
+      "actually exactly 1 or more of those numbers"
$      "and the the string should just end."
How to execute a query which is stored in a table column MySQL?

How to execute a query which is stored in a table column MySQL?


By : 曹海生
Date : March 29 2020, 07:55 AM
I wish this help you You can use a cursor to get each REPORT_QUERY on CT table, and execute that using prepared statements:
Related Posts Related Posts :
  • PHP combobox not showing in HTML table
  • MySql PHP row request to variable
  • Join two tables with one table has multiple rows matching
  • Looping through users with Instagram API requests is REALLY slow
  • Unable to add 30 days to date within loop
  • Return from mysqli_query() into array
  • php rename() function returns "No such file or directory" error
  • form submit inside navigation menu
  • PHP: reasons to use GET and POST request at the same time?
  • Is break; required after die() php
  • little depth of session in php
  • Authentication Logon page not working using PHP and Oracle on Apache / Windows 2008
  • Magento reindexing error product flat data
  • Laravel 4: Running composer when deploying to Heroku
  • Long Polling or WebSockets
  • How to use mysqli_stmt_bind_param for integers, boolean, etc
  • Determining the content of a link
  • MYSQL and PHP update events?
  • PHP explode all square bracket
  • Transparent hexagon-masked collage using PHP GD
  • Plugins or text do NOT show up on custom wordpress template
  • inserting data into mysqli database
  • Two arguments to closure function laravel
  • UnClear image exported by ffmpeg from mp4 file
  • is the time of computer and localhost same?
  • change custom data- value after ajax post success
  • Can We Restrict PHP Variables to accept only certain type of values
  • csv file is inserting a blank row in the last of other rows into mysql table
  • How to convert special characters in xml using php?
  • Mcrypt are very confusing
  • Dynamic image for user's ID
  • How to only upload specific parts of HTML form with PHP?
  • Dynamic PHP string as MySQL table name
  • What is the error in my query?
  • PHP Upstart on Amazon EC2 Linux (Elasticbeanstalk)
  • how to print dynamic variable value in php
  • php mysql insert values and select
  • uploading image in codeigniter controller
  • Converting htaccess to nginx for counter
  • how can I show my signal transaction data as project name
  • php raspberry pi trying to change pi date
  • PHP and mysql, SELECT query return null
  • Unable to store Date values in php mysql table that are existing in excel file
  • Can we include 2 Mail() functions in 1 Page?
  • Problems with chinese characters
  • How to apply a function to every foreach result?
  • Use of CONCAT in FROM clause
  • Tag endpoint combined with user endpoint with Instagram API
  • create dynamic time in php and mysql
  • How to break zero index comma separated value into individual string in php
  • PHP Login session and echoing username
  • PHP : Difference b/w new self and new object()
  • Turkish character issue while inserting into MySQL database with PHP
  • Insert data from one DB into another on a different server - servers not linked
  • Sorting an array of strings using values alphabetically and considering the cases of values in PHP
  • Unable to solve .htaccess url rewriterule, gives 404 for all pages
  • Dual URL Rewrite In PHP
  • How to change value of cdata inside a .xml file and then again save it using php
  • Using filters from other classes within rules method in Yii 2?
  • json_decode syntax error from valid json
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org