A
A
Andrey Denisov2020-03-04 20:20:12
PHP
Andrey Denisov, 2020-03-04 20:20:12

How to get a row from the database by id?

How to display a line from the database by id from the url, which I have already been able to get using this code.

<?php
$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
parse_str (parse_url ( $url, PHP_URL_QUERY ), $arr);
$obj3 = (object)$arr;
$id = $obj3->id;
print_r($id);
?>

Then I tried to display the login using this
<?php 
$db = mysql_connect ("хост","логин","пароль");
 mysql_select_db ("база",$db);
mysql_set_charset (utf8);
$result = mysql_query ("SELECT * FROM `users` WHERE `id` =",$id);
$myrow = mysql_fetch_array ($result);
?>

and in the place I need, but it doesn't work. Please tell me how to do this or where to read about it. Thanks in advance.
<?php echo $myrow ['login']; ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-03-04
@DenisovPlay

$result = mysql_query ("SELECT * FROM `users` WHERE `id` =",$id);
put a dot instead of a comma.

D
Dmitry, 2020-03-05
@WotKievlanin

("SELECT * FROM `users` WHERE `id` =$id" )
In general, in phpmyadmin, check requests for errors, such as this syntax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question