This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?
(3 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
2 fields in my table are encrypted (email, name) and the other not.
I use the function $email = decrypt('email'); to get the original String.
How to use the function into mysql?
the question: how can I insert this function : decrypt('email') into this query below ? :
$query = mysqli_query($con, "select 'name', 'tel', 'adress', 'email' from users where id = 10");
for Encrypting works :
INSERT INTO `users` (`name`, `tel`, `adress` , `email`) VALUES (encrypt($name),$tel, $adress, encrypt($email));
Related
This question already has answers here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 1 year ago.
When I run this code with PHP it doesn't create a table.
$sqltablecreate = "CREATE TABLE userbase.'$username' ( ID int, category varchar(100), content varchar(1000), PRIMARY KEY (ID) )";
if(mysqli_query($conn, $sqltablecreate)){
echo "<script>alert('Table Created Successfully')</script>";
} else {
echo "<script>alert('Errors with Table creating')</script>";
}
This question already has answers here:
Display binary(16) column as hex in mysql
(4 answers)
PHP mysql bigint issue
(3 answers)
Closed 2 years ago.
I'm not sure if it's PHP or MySQL that's messing me up.
Say, I have a table with BIGINT UNSIGNED column (let's name it flgs). I read data from that table with PHP as such:
$query = "SELECT * FROM `$tbl_nm` ORDER BY `$colID` ASC";
$res = mysqli_query($link, $query);
if($res)
{
while($aRow = mysqli_fetch_assoc($res))
{
echo("flags=0x".dechex($aRow['flgs'])."<br>");
}
}
if the flgs column has value with bit-63 reset, then I get the correct result. But if bit-63 is set, the return value is 0x7fffffffffffffff. Hmmmm?
For instance, if flgs is set to 0x8000000000000000 in the database, my code above prints:
flags=0x7fffffffffffffff
Why, PHP, why?
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 5 years ago.
MySQLi line like this:
$sqlQuery = "INSERT INTO '$this->dbTable' (url, name_surname, phone, city, category) VALUES('$contents[0]', '$contents[1]', '$contents[2]', '$contents[3]', '$contents[4]')";
Not:
$this->dbTable = 'crawler_data';
But above line does not work. MySQL does not accept. When I change line like this:
$sqlQuery = "INSERT INTO crawler_data(url, name_surname, phone, city, category) VALUES('$contents[0]', '$contents[1]', '$contents[2]', '$contents[3]', '$contents[4]')";
It's working!
How can I set MySQL table name from out?
single or double quotes use for string.when we use '$this->table' it identify like string.change like this.
$sqlQuery = "INSERT INTO $this->dbTable (url, name_surname, phone, city, category) VALUES('$contents[0]', '$contents[1]', '$contents[2]', '$contents[3]', '$contents[4]')";
This question already has answers here:
Inserting NOW() into Database with CodeIgniter's Active Record
(11 answers)
Closed 7 years ago.
I'm trying to do an update in MySQL from PHP with CodeIgniter, but, how can I insert a now() method?
I mean, I'm using an array to insert my information, but, how can I insert the date?
This is an example of my array:
$data = array(
'name' => $inputName,
'lastname' => $inputLast,
'DOBirth' => now()
);
NOW() is part of MySQL, not PHP, so you need to put into the query.
Try this way, which is how you handle it using PDO. This should work:
$stmt = $pdoDb->prepare('INSERT INTO tablename (name, lastname, dobirth) VALUES (:name, :lastname, NOW())');
// either bind each parameter explicitly
$stmt->bindParam(':name', $name);
$stmt->bindParam(':lastname', $lastname);
$stmt->execute();
source: Datetime NOW PHP mysql (+ PDO variant)
This question already has answers here:
Can PHP PDO Statements accept the table or column name as parameter?
(8 answers)
Closed 8 years ago.
Why this line doesn't work:
$db_Table = "myTable";
$pdo->prepare("INSERT INTO :db_Table VALUES (...
$query->execute(array(
':db_Table' => $db_Table,
Whereas this one works:
$pdo->prepare("INSERT INTO myTable VALUES (...
How can I solve it ?
Tablenames can not be replaced in a PDO Query.
Further information you can find in the following thread
Can PHP PDO Statements accept the table or column name as parameter?
unfortunately there are no builtin function for binding table names, you have to do it yourself:
$db_Table = "myTable";
$query = $pdo->prepare("INSERT INTO `$db_Table` VALUES (...)");
$query->execute();
But that is still not being escaped, one workaround is to have an array of table, then check if it exist:
$list_of_tables = array('myTable1', 'myTable2', 'myTable3');
if(!in_array($db_Table, $list_of_tables){
//table does not exist !
}