DELETE php mysql doesn't work [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Hello I have little problem with this:
require_once("dbconnect.php");
mysql_query('set names utf8');
$query = ('DELETE FROM `gallery` WHERE `id` = 16') or die("failed");
It not delete record from DB. Can you help me? Thanks. dbconnect.php is correct.

All you did was declare a variable $query, but you did not run it. You have to run it is $query = mysql_query('DELETE FROM `gallery` WHERE `id` = 16')
Edit: Having said that, do not use mysql_ functions. They allow for SQL injection, which is very dangerous. Instead it is better to use
$mysqli = new mysqli(HOST, USERNAME, PASSWORD, DATABASE);
$query = $mysqli->query('DELETE FROM `gallery` WHERE `id` = 16');

Related

Querying a wordpress database [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Can anyone see whats wrong with this syntax? I've consulted the wordpress codex page and the syntax seems to be correct..
$result = $wpdb->query($wpdb->prepare( "SELECT * FROM {$wpdb->prefix}users WHERE username = %s AND password = %s, array( $username, $password )"));
Thanks
try:
$result = $wpdb->query($wpdb->prepare( "SELECT * FROM {$wpdb->prefix}users WHERE username = %s AND password = %s", array( $username, $password )));
your quotes are incorrect.

Where's my issue here? (PHP/PDO) - User exist [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
trying to check whether a user exists or not via pdo
$wantedusrnm = $_POST['new-usrnm'];
$userExist1 = "SELECT * FROM users WHERE username=:wantedusrnm";
$userExist = $handler->prepare($userExist1);
$userExist->execute(array(':username' => $wantedusrnm));
$userExist = ($userExist->rowCount());
for some reason it errors, dunno why, any reasons?
Change:
$userExist->execute(array(':username' => $wantedusrnm));
To:
$userExist->execute(array(':wantedusrnm' => $wantedusrnm));
Because, in your query you've got :wantedusrnm but in your execution array you've got :username.

PHP PDO Wrong numbers of tokens? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Can someone tell me what is wrong with that statement cause I do not see any mistake?
$PrevReleaseModel = $con->prepare("SELECT * FROM model WHERE model_name=:model_name AND model_release:model_release");
$PrevReleaseModel->bindParam('model_name',$model_name);
$PrevReleaseModel->bindParam('model_release',$model_release);
$PrevReleaseModel->execute(array('model_name'=>$model_name,'model_release'=>$model_release));
I am really confused.
WHERE model_name=:model_name AND model_release = :model_release
You missed a equal sign in the last condition.
You may try this out:-
$PrevReleaseModel = $con->prepare('SELECT * FROM model
WHERE model_name = :model_name AND
model_releas = :model_releas'
);
$PrevReleaseModel->bindParam(':model_name', $model_name, PDO::PARAM_STR);
$PrevReleaseModel->bindParam(':model_releas', $model_release, PDO::PARAM_STR);
$PrevReleaseModel->execute();

I have error in folloing code of php for update [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
the below query is not working
$query= mysql_query('SELECT * FROM Registration WHERE name="'.$_POST['Username'].'" & password="'.$_POST['Password']);
Use the word SET once only in your query. And separate each data by comma(,).
You should also consider escaping the string of your variables before using them into your query.
If you are using MySQLi, you can do this:
$username=mysqli_real_escape_string($connection,$_POST['Username']);
$password=mysqli_real_escape_string($connection,$_POST['Password']);
$city=mysqli_real_escape_string($connection,$_POST['City']);
$state=mysqli_real_escape_string($connection,$_POST['State']);
$country=mysqli_real_escape_string($connection,$_POST['Country']);
$userid=mysqli_real_escape_string($connection,$_POST['user_id']);
$query="UPDATE Registration SET name='$username', password='$password', city='$city', state='$state', country='$country' WHERE id='$userid'";
mysqli_query($connection,$query); /* EXECUTE QUERY */
Use , instead of set between each fields. Use this altered query,
('UPDATE Registration SET name="'.$_POST['Username'].'" , password="'.$_POST['Password'].'" , city="'.$_POST['City'].'" , state="'.$_POST['State'].'" , country="'.$_POST['Country'].'" WHERE id='.$_POST['user_id']);

MySql 'or' Operator not working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want to select the user from my database using email or username, my code is:
$sql = "SELECT * FROM `users` WHERE (`Email`='".$User."' OR `Username`='".$User."'') AND `Password`='".$Password."'";
My Code Worked
Code:
$sql = "SELECT * FROM users WHERE (Email = '$User' or Username ='$User') AND Password='$Password'";
Note: I would have posted this in a comment (believe me), because the comment box doesn't show backticks properly (I know there's a trick to it, but I don't know it, yet.)
Use this:
$sql = "SELECT * FROM `users`
WHERE (`Email`='".$User."' OR `Username`='".$User."')
AND `Password`='".$Password."'";
You had one too many quotes in '".$User."''
$sql = "SELECT * FROM `users`
WHERE (`Email`='".$User."' OR `Username`='".$User."'')
----^
AND `Password`='".$Password."'";
And do consider reading this article on how to prevent injection.
Footnote: And if by the slightest chance that you would be using the now-deprecated mysql_* functions, STOP and start using mysqli_* functions with prepared statements and/or PDO.
Try this :
$sql = "SELECT * FROM `users` WHERE (`Email`='".$User."' OR `Username`='".$User."') AND `Password`='".$Password."'";
There was an extra quote after $user variable.

Categories