News:

Wondering if this will always be free?  See why free is better.

Main Menu

SQL and PHP

Started by xxMaDCaTxx, May 20, 2014, 12:15:48 PM

Previous topic - Next topic

xxMaDCaTxx

Hi guys , i am new to this forum and as good as new to php and mysql , but i managed with the help of google to make something work .
So i have the following code on a dream page ( dream-portal ) :
// Connects to your Database
mysql_connect("db4free.net", "username", "password") or die(mysql_error()); 
mysql_select_db("xsmf") or die(mysql_error());
$data = mysql_query("SELECT * FROM smf_members ")
or die(mysql_error());
Print "<table border cellpadding=5>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info[member_name] . "</td> ";
Print "<th>Unique VIP auth key:</th> <td>".$info[password_salt] . "</td> ";
Print "</tr>";
}
Print "</table>";

Now the Result of that is as following picture :

Now i tried different thing to make it work but no luck .
So here it comes my issue : I wanna display only the name of the user that is actually looking at the page.
I tried things like :

("SELECT * FROM users WHERE member_name = '$member_name")
("SELECT * FROM smf_members WHERE member_name = '$member_name' LIMIT 1")
i tried it with id $user_settings[id] nothing seems to work .
Some times i get a parse error or exception other times i get a correct page but nothing listed in it .

i dont know if i supplied enough information just ask me .

Kind Regards xxMaDCaTxx

margarett

Hi

You should, first of all, use $smcFunc for database interaction. It has very neat features, including several protection ones ;)

Then, there is no table "users" in SMF. "smf_members" is the right one (if your prefix is smf_)

I can see no image...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

xxMaDCaTxx

Quote from: margarett on May 20, 2014, 03:05:59 PM
Hi

You should, first of all, use $smcFunc for database interaction. It has very neat features, including several protection ones ;)

Then, there is no table "users" in SMF. "smf_members" is the right one (if your prefix is smf_)

I can see no image...

Hi and thanks for the reply .
Yea i know i uploaded the correct one now , the code above was sample code.
Now since i use NAS DS211+ with MariaDB which the simple machine forum runs on , does not allow me to remote acces. so i export it to hxxp:db4free.net [nonactive] ( i need remote acces to the DB for my hxxp:vb.net [nonactive] application. ).

Oh and the picture i linked, i guess it was from local computer ip , i changed the link should work now . P.s still learning
My interest in coding is growing and growing i should get some education for it ^^ !

margarett

A way to do that in a query would be something like:
global $smcFunc, $user_info, $db_prefix;

// Do a quick query to make sure this isn't a mistake.
$result = $smcFunc['db_query']('', '
SELECT member_name
FROM {db_prefix}members
WHERE id_member = {int:id_member}
LIMIT 1',
array(
'id_member' => $user_info['id'],
)
);
list ($member_name) = $smcFunc['db_fetch_row']($result);
$smcFunc['db_free_result']($result);

echo $member_name;

But you don't need this!

In a DP block, all variables from SMF are already available... That includes details from current user.
So, if you use just this:
global $user_info;
echo $user_info['name'];

There you have it ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

xxMaDCaTxx

Quote from: margarett on May 21, 2014, 07:11:39 PM


Cheers mate .
You pretty much solved my problem and i learned some nice things here . Very helpfull .
I hope one day i can do something back for this community or to other people in my situation !


Advertisement: