Pass string with AJAX and find in database with PHP [closed] - php

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 passing a string with AJAX and trying to find the mySQL db entry that contains the string in one of its columns. I think the string passing is OK but perhaps the mySQL code is incorrect?
$id = ($_POST['video_id']);
$text_result = mysql_query("SELECT * FROM `wmtwDB` WHERE `url` LIKE (" . $id . ") LIMIT 1");

LIKE syntax is failing. Try with:
$text_result = mysql_query("SELECT * FROM `wmtwDB` WHERE `url` LIKE %" . $id . "% LIMIT 1");

Related

I am trying to get the user id which is created automatically [closed]

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;

how to add quotes to a search string for an exact match? [closed]

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'

How to display row from page ID [closed]

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 9 years ago.
Improve this question
I am very new and trying to get from the url ie
device.php?id=2
and use the id number multiple times.
can anyone tell me how to display this?
Thanks in advance
1) Get the ID.
$id = $_GET["id"];
2) Search for $id in your database, using MySQL functions like mysqli_fetch_array() etc.
3) Echo the values you fetched, using simple HTML and PHP.
$id = $_GET['id'];
$sql= mysql_query("select * from tableName where id = $id ");
while($row = mysql_fetch_array($sql))
{
echo $row['columnName'];
}
The variable should be in $_GET["id"].
<?php
echo $_GET['id'];
?>

All under MySQL_Error() are disappear [closed]

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

Mysql and php wrong construction? [closed]

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 . "'"

Categories