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
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 to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
The image above is my sql database. what I want to do is load the names and echo in json but the thing is though, I want to show one of each name. Like see how there are 4 assassinshadow entries? I want php to echo only one of em. not making much sense am I? haha
You can use DISTINCT in your mysql query:
$mysqli = mysqli_connect("example.com", "user", "password", "database");
$query = "SELECT DISTINCT name from yourtable";
$res = mysqli_query($mysqli, $query);
$row = mysqli_fetch_assoc($res);
Two ways to do that:
SELECT distinct name FROM my_table
or
SELECT name FROM my_table group by name
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 have some code here for a song request program. And it works just fine other than the user has to use surrounding quotes for an exact match. I am wondering how I would go about having the php add the quotes so the user can type a band or song title as normal without having to read the small help notice saying to use quotes?
You can concate quotes in after if you like.
$termToSearch = '"' . $termFromUser . '"';
$query = 'SELECT * FROM table WHERE song = :song'
$statement = $this->db->prepare($query);
$statement->bindValue(':song', $termToSearch);
$statement->execute();
$statement->closeCursor();
Just use "=" instead of "LIKE"
SELECT * FROM table WHERE column = '$searchterm'
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.
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 . "'"