Cannot create a table with php and sql [duplicate] - php

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>";
}

Related

How to properly retrieve unsigned bigint from MySQL column with PHP? [duplicate]

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?

How to get auto_increment particulars using mysqli_fetch_fields? [duplicate]

This question already has an answer here:
how to tell if column is primary key using mysqli?
(1 answer)
Closed 3 years ago.
objectice: to get auto_increment particulars of a field using mysqli_fetch_fields
code:
<?php
require_once("dbc.php");
$query="SELECT id, name, age from student WHERE 1>2";
$result=mysqli_query($dbc, $query);
$metas=mysqli_fetch_fields($result);
foreach($metas as meta){
$col_name=meta->name;
$col_type=meta->type;
$col_length=meta->length;
$col_flags=meta->flags;
echo "col_name: $col_name, col_type: $col_type, col_length: $col_length, col_flags: $col_flags";
}
mysqli_close($dbc);
?>
Observation:
in mysql prompt
mysql> describe student;
Field Type Null Key Default Extra
id int(16) NO PRI NULL auto_increment
but in mysqli
col_name: id, col_type: 3 , col_length: 11, col_flags: 49967
col_flags value 49967 corresponds to primary key.
Please guide me in getting whether a field is auto-increment using mysqli_fetch_fields?
The appropriate flag bit to test for AUTO_INCREMENT is bit 9 (AUTO_INCREMENT_FLAG) (Source). In PHP you just need to add the MYSQLI_ prefix. Something like this:
$auto_increment = $col_flags & MYSQLI_AUTO_INCREMENT_FLAG;

in php this error show when i am inserting the data by form [duplicate]

This question already has answers here:
Incorrect integer value: '' for column error
(2 answers)
Incorrect integer value: '' for column 'id' at row 1
(6 answers)
Incorrect integer value '' for a MySQL column that's integer and allow null?
(3 answers)
Incorrect integer value: '' for column
(1 answer)
Incorrect integer value: '' for column 'ColorHair' at row 1
(1 answer)
Closed 4 years ago.
Error: insert into products (product_cat, product_name, product_pric, product_desc, product_image, product_keyword, product_ingrid) values ('5','','', '','','','')
Incorrect integer value: '' for column 'product_pric' at row 1
what is this error and how to resolve
As the error implies - you are trying to insert an empty string (the "") into a column which defined as an integer.
You are passing an empty string to a integer field. It must be null (if column is nullable) or an integer.

How to decrypt String in mysql by Selecting? [duplicate]

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));

How to delete particular columns data in database using php mysql [duplicate]

This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 7 years ago.
Hi iam trying to delete certain columns data from database.Here is my code for delete query.
//getting column id by comparing the id need to delete the data from that row.
$id=$_GET['id'];
$res = "DELETE rental_annual_rent,
rental_block,
rental_street,
rental_area,
rental_town,
rental_state,
rental_pincode
FROM house_details
WHERE house_details_id='$id'";
$result=mysql_query($res);
if(mysql_affected_rows()){
echo "successfully deleted";
session_start();
header("Location:property.php");
}else{
echo "Failure";
}
First iam inserting house_details data into database but i need to delete only particular data from that columns
What you want is an UPDATE, not a DELETE since you want to keep the row, but just clear/blank/unset certain columns within the row.
$res = "UPDATE house_details SET
rental_annual_rent = NULL,
rental_block = NULL,
rental_street = NULL,
rental_area = NULL,
rental_town = NULL,
rental_state = NULL,
rental_pincode = NULL
WHERE house_details_id='$id'";
Note that you should really be sanitizing your id input before using it in the query, you should parameterize it, and you should also migrate from the mysql library to mysqli or PDO

Categories