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
Ok so I am having issues selecting the data I want from the table in MySQL. The database connection is successful and active, I started a session before anything else, and the Session is created on login and working. The issue is this pice of code and I can't seem to figure it out.
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE ('.$_SESSION['id'].')';
Any help would be appreciated.
I would do like so:
<?php
$session = $_SESSION['id'];
$sql = "SELECT * FROM Authentication WHERE `id` LIKE '%$session%'";
?>
However, as #nody says, if your id is an integer use equal to operator instead of LIKE.
Try this:
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE '".$_SESSION['id']."'';
first of all check ur table name correct or not.
Check your Authentication table id column data type.
if it is varchar ,it should be
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE "'.$_SESSION['id'].'"';
if it is Integer
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE '.$_SESSION['id'];
see this for more
http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html
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
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
how i can make example: post.php and when somebody goes to post.php to show all posts and when somebody click on one post to show in URL post.php?id=1(id=1 by id in database? and when it types post.php?id=2 to go to id 2 in database and show all datas from row of table by id 2)
Use the $_GET method to pass the url. At the top of the php file you can access the information posted in the url using the global $_GET['id']. You can check if it is set, and depending on whether or not it is, show information regarding that id from the database.
It might look something like this:
if (isset($_GET["id"])) {
$id = $_GET["id"];
$query = "SELECT * table WHERE id = {$id} LIMIT 1;";
$result = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($result)){
echo $row["id"];
echo $row["name"];
echo $row["someOtherAttribute"];
}
}
Make sure you have your connection and your database set up and whatnot, but thats how you would accomplish this.
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 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
This is the site that I am trying to create the script for http://facechat.louisdickinson.com/
The idea is people can save there email to my database, and another button called "Start Call" will randomly select a email and call it using:
facetime://email#email.com
Effectively this will create a "omegle" style web-based facetime chat site.
I am new to MySQL and PHP and don't know where to start, any help will be appreciated!
I don't know, what kind of help do you need.. First of all, you should have a php script, witch can take the posted name/e-mail pair.
In this script, you should sanitize the posted values, than you can add it to your database with the following:
$query = "INSERT INTO <tableName> (`name`, `e-mail`) VALUES ( '".$postedName."', '".$postedMail."' )";
On button press, you should have another php script, for selecting the random e-mail:
$query = "SELECT COUNT(*) FROM <tableName>";
$max should be the query result.
$random = rand( 0 , $max - 1 );
$query = "SELECT `e-mail` FROM <tableName>" LIMIT $random, 1";
With this query you got a random e-mail.
Do you need more exact code? Please be more exact on what you need!
Kind regards,
hotzu
In php:
mysql_connect("host", "user", "password") or die(mysql_error());
mysql_selectdb("database"); // '' for an auto increment column
mysql_query("INSERT INTO TABLE VALUES ('$email', ''));
And for more info http://www.w3schools.com/php/php_mysql_intro.asp
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 a registration system , username, password, email id are stored in a table, how can i export or get all email ids of all my registered users in Phpmyadmin itself (or any other way).
Run query
select email_id from users
Then use export feature of phpmyadmin.After you run the query, click the export link and you can export the query result in many different formats (e.g CSV, Excel, Word...)
Please change table and column names according to you.
try this>>
$sql = "select email_id from table_name";
$result = mysql_query($sql);
$email_collector = array();
while( $row = mysql_fetch_assoc($result) ){
//store email in array
$email_collector[] = $row['email_id'];
}
print_r($email_collector);
Change email_id and table_name according to your database
If you want to get list of users and their email in a text file try the below query
SELECT username, email INTO OUTFILE 'data.txt'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM table2;