Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This statement works in pgAdmin but not when run in a php script the php script can select all but can not update why is this?
UPDATE users SET password = '123123' WHERE email = 'random#random.com'
PHP code that doesn't work:
$sql = $dbh->prepare("UPDATE users SET password = '11111111111' WHERE email = 'test#outlook.com')");
$sql->execute(array());
PHP code that does work:
$sql = $dbh->prepare("SELECT * FROM users");
$sql->execute(array());
$fr = $sql->fetchAll(); var_dump($fr);
In your update query you've got ) at the end which will cause syntax error. Check it using eg. $dbh->errorInfo().
Also, don't use prepare() for queries that don't use parameters. Instead use query() for SELECT and exec() for others.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
$sql4 = "SELECT userid, userName FROM $user_table WHERE userName= '$userNames'";
$result = $conn->query($sql4);
$_SESSION['myUser'] = $result['userid'] ;
I have most code I can find but nothing works
Assuming these lines of code come immediately after executing an insert of a new user record and you are using PDO. You could try:
$last_id = $conn->lastInsertId();
$_SESSION['myUser'] = $last_id;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am able to navigation between a php page using ID but not using project name. Can you only use an number and not characters?
Works
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE id=$id";
'.$row['project'].'
page url: https://example.com/project.php?id=1
Doesn't work
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE project=$project";
'.$row['project'].'
page url: https://example.com/project.php?project=Test
Thanks for the help!
MySQL uses single or double quotes for strings. Your second query puts string to a query, resulting in invalid query.
This is not a valid SQL query:
SELECT `name` FROM `cats` WHERE `breed` = ordinary cat
But this is:
SELECT `name` FROM `cats` WHERE `breed` = 'ordinary cat'
Of note, be careful with using any input (including query string) in your query like you did. You should use prepared statement instead to safely escape that string for your query.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I´m trying to insert a current SELECT-Statement into an Database table with an PHP-variable. It works by this way without the variable:
mysql_query("INSERT INTO table (column) SELECT column FROM table1");
Did anyone have a idea how I can fix it?
PHP: 5.3.10 and mysql-databse
try this
$sample="SELECT column FROM table1"; // your select query
$query="INSERT INTO `table` (column) $sample";
mysqli_query('database connection code',$query);
Let me know if any problem arises.
You can use mysql_insert_id() to get the last inserted ID value and try insert query separately.
<?PHP
$lastId = mysql_insert_id();
$query = mysql_query("Your Select Query with $lastId");
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a problem with disappearing my mysql_error and 50% of my website under error...
MySQL_Query("UPDATE table
SET use = '1'
WHERE name = '$code'", $SpojenieWeb) or die(mysql_error());
Why it is disaappearing ? Where is the error ?
Why it is disaappearing?
It's disappearing because most probably your UPDATE query fails and you use die() in case of failure.
Now it's really hard to say exactly since you provided not enough information, but looking at you query you at least have to change
"UPDATE table SET use = '1' WHERE name = '$code' ..."
to
"UPDATE `table` SET `use` = '1' WHERE name = '$code' ..."
^ ^ ^ ^
table and use are reserved words in Mysql
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
"hat is wrong width this MySql and php construction?
$zapytanie = "UPDATE Users
SET usr_premium_expire = '$data'
WHERE usr_login = '$login';
";
You don't need the semi-colon in the MySQL statement.
If any further error occurs, try
mysql_error();
after you've executed the statement.
To validate the data sent try
echo $zapytanie;
When in doubt also escape the variables:
"UPDATE Users SET usr_premium_expire='" . $data . "' WHERE usr_login='" . $login . "'"