Display user data from database.

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
User avatar
frankus
 
 
Posts: 38
Joined: Sat Dec 05, 2009 10:04 pm

Display user data from database.

Post by frankus »

Guys, I want to display user data from database after they login. I want the texts to appear in text objects, so I can place them wherever I want on the their profile page. I don't want to use a table. So I need two codes for MySQL and Flat file database (text file). Any help?
wwonderfull
 
 
Posts: 1439
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: Display user data from database.

Post by wwonderfull »

It would need scripts using php to get the data from mysql database and show it dynamically to your web page. Here is an example of how to do it. https://www.w3schools.com/php/php_mysql_select.asp

And If you want to view data in tables then wwb has datatables extension pack maybe you have these extensions, in case you dont have you can get it from here. https://www.wysiwygwebbuilder.com/datapack2.html
User avatar
frankus
 
 
Posts: 38
Joined: Sat Dec 05, 2009 10:04 pm

Re: Display user data from database.

Post by frankus »

Thanks for responding.
wwonderfull wrote: Mon Apr 17, 2023 2:36 am It would need scripts using php to get the data from mysql database and show it dynamically to your web page. Here is an example of how to do it. https://www.w3schools.com/php/php_mysql_select.asp
I know how get the data from mysql database and show it on web page. What I want is to be able to display the user's data via text objects not via a table. In other words, I want to have the freedom to place any of the data at any location on the page with text objects.
And If you want to view data in tables then wwb has datatables extension pack maybe you have these extensions, in case you dont have you can get it from here. https://www.wysiwygwebbuilder.com/datapack2.html
None of the extensions is what I want. I want a similar thing as above.
User avatar
Pablo
 
Posts: 22472
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Display user data from database.

Post by Pablo »

You can use an HTML object and place the data anywhere you want. Just like with other objects.
User avatar
frankus
 
 
Posts: 38
Joined: Sat Dec 05, 2009 10:04 pm

Re: Display user data from database.

Post by frankus »

Pablo wrote: Mon Apr 17, 2023 1:10 pm You can use an HTML object and place the data anywhere you want. Just like with other objects.
I haven't thought of that, I'll try it.

This was how I used to do it. Placing this code on the profile page.

Code: Select all

<?php
error_reporting(0);
session_start();
if($_SESSION['username'] != '')
{

$mysql_server = 'localhost';
$mysql_username = 'username';
$mysql_password = 'password';
$mysql_database = 'databasename';
$mysql_table = 'tablename';

$db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
mysql_select_db($mysql_database, $db);
$sql = "SELECT fullname, email, extra1, extra2, extra3, extra4, extra5, extra6, extra7, extra8, extra9, extra10, extra11, extra12, extra13, extra14, extra15 FROM ".$mysql_table." WHERE username = '".$_SESSION['username']."'";
$result = mysql_query($sql, $db);
if ($data = mysql_fetch_array($result))
{
extract ($data, EXTR_OVERWRITE);
$status = array("Pending", "Active");
$_SESSION['fullname'] = $fullname;
$_SESSION['email'] = $email;
$_SESSION['extra1'] = $extra1;
$_SESSION['extra2'] = $extra2;
$_SESSION['extra3'] = $extra3;
$_SESSION['extra4'] = $extra4;
$_SESSION['extra5'] = $extra5;
$_SESSION['extra6'] = $extra6;
$_SESSION['extra7'] = $extra7;
$_SESSION['extra8'] = $extra8;
$_SESSION['extra9'] = $extra9;
$_SESSION['extra10'] = $extra10;
$_SESSION['extra11'] = $extra11;
$_SESSION['extra12'] = $extra12;
$_SESSION['extra13'] = $extra13;
$_SESSION['extra14'] = $extra14;
$_SESSION['extra15'] = $extra15;

}
mysql_close($db);
}
else{
header("Location: login.php"); // change according to what your login page is.
exit;
}
?>
And inserting this code in the text object, e.g

Code: Select all

'.$extra1.'

But it stopped working. (viewtopic.php?p=419295#p419295)
User avatar
Pablo
 
Posts: 22472
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Display user data from database.

Post by Pablo »

Note that this code is not compatible with PHP8.
So that is probably why it stopped working...
User avatar
frankus
 
 
Posts: 38
Joined: Sat Dec 05, 2009 10:04 pm

Re: Display user data from database.

Post by frankus »

Oh, good to know. Any suggestion?
mixextra
 
 
Posts: 95
Joined: Sat Mar 21, 2020 11:45 pm

Re: Display user data from database.

Post by mixextra »

Hello
maybe a quick Bing AI answer will help:

The `mysql_connect()` function was marked as deprecated in PHP 5.5.0 and removed in PHP 7.0.0. It is recommended to use the MySQLi or PDO_MySQL interface instead. In PHP 8, it is no longer possible to use the libmysql.dll library to access the MySQL database. Instead, it is recommended to use the MySQLi or PDO_MySQL interface.

If you want to use the `mysql_connect()` function in PHP 8, you can try the following solutions:
- Use the `mysqli_connect()` function instead of the `mysql_connect()` function.
- If you still want to use the `mysql_connect()` function, you can copy the libmysql.dll file to the system directory C:/Windows/SysWOW64 and add the line `extension=php_mysqli.dll` to the php.ini file.

It may be useful to switch to newer MySQLi or PDO_MySQL interfaces for your applications to avoid compatibility issues in the future.
mixextra
 
 
Posts: 95
Joined: Sat Mar 21, 2020 11:45 pm

Re: Display user data from database.

Post by mixextra »

one more answer with an example:

Your code does not work because the `mysql_connect()` function was removed in PHP 7.0.0 and replaced by `mysqli_connect()`⁷. If you are using PHP 8, this feature is no longer supported[^10^]. You should use the PDO interface or the MySQLi⁷¹³ interface instead.

If you want to use the MySQLi interface, you can try the following code:

Code: Select all

<?php
error_reporting(0);
session_start();
if($_SESSION['username'] != '')
{

$mysql_server = 'localhost';
$mysql_username = 'username';
$mysql_password = 'password';
$mysql_database = 'databasename';
$mysql_table = 'tablename';

$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password, $mysql_database);
$sql = "SELECT fullname, email, extra1, extra2, extra3, extra4, extra5, extra6, extra7, extra8, extra9, extra10, extra11, extra12, extra13, extra14, extra15 FROM ".$mysql_table." WHERE username = '".$_SESSION['username']."'";
$result = mysqli_query($db,$sql);
if ($data = mysqli_fetch_array($result))
{
extract ($data, EXTR_OVERWRITE);
$status = array("Pending", "Active");
$_SESSION['fullname'] = $fullname;
$_SESSION['email'] = $email;
$_SESSION['extra1'] = $extra1;
$_SESSION['extra2'] = $extra2;
$_SESSION['extra3'] = $extra3;
$_SESSION['extra4'] = $extra4;
$_SESSION['extra5'] = $extra5;
$_SESSION['extra6'] = $extra6;
$_SESSION['extra7'] = $extra7;
$_SESSION['extra8'] = $extra8;
$_SESSION['extra9'] = $extra9;
$_SESSION['extra10'] = $extra10;
$_SESSION['extra11'] = $extra11;
$_SESSION['extra12'] = $extra12;
$_SESSION['extra13'] = $extra13;
$_SESSION['extra14'] = $extra14;
$_SESSION['extra15'] = $extra15;

}
mysqli_close($db);
}
else{
header("Location: login.php"); // change according to what your login page is.
exit;
}
Ak chcete použiť rozhranie PDO:

Code: Select all

<?php
error_reporting(0);
session_start();
if($_SESSION['username'] != '')
{

$mysql_server = 'localhost';
$mysql_username = 'username';
$mysql_password = 'password';
$mysql_database = 'databasename';
$mysql_table = 'tablename';

try {
    $db_conn_string="mysql:host=$mysql_server;dbname=$mysql_database;charset=utf8mb4";
    $db= new PDO($db_conn_string,$mysql_username,$mysql_password);
    $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);

    $sql="SELECT fullname,email,
    extra1,
    extra2,
    extra3,
    extra4,
    extra5,
    extra6,
    extra7,
    extra8,
    extra9,
    extra10,
    extra11,
    extra12,
    extra13,
    extra14,
    extra15
FROM ".$mysql_table." WHERE username=:username";
    
$stmt=$db->prepare($sql);
$stmt->bindParam(':username', $_SESSION['username'], PDO::PARAM_STR);
$stmt->execute();
$data=$stmt->fetch(PDO::FETCH_ASSOC);

if ($data)
{
extract ($data, EXTR_OVERWRITE);
$status=array("Pending","Active");
$_SESSION['fullname']=$fullname;
$_SESSION['email']=$email;
$_SESSION['extra1']=$extra1;
$_SESSION['extra2']=$extra2;
$_SESSION['extra3']=$extra3;
$_SESSION['extra4']=$extra4;
$_SESSION['extra5']=$extra5;
$_SESSION['extra6']=$extra6;
$_SESSION['extra7']=$extra7;
$_SESSION['extra8']=$extra8;
$_SESSION['extra9']=$extra9;
$_SESSION['extra10']=$extra10;
$_SESSION[
User avatar
frankus
 
 
Posts: 38
Joined: Sat Dec 05, 2009 10:04 pm

Re: Display user data from database.

Post by frankus »

Thank you mixextra, I'll try them out.
A lot have changed since I left website creation. I need to familiarize myself with all these once again.
Post Reply