Jump to content

list mysql items


ngreenwood6

Recommended Posts

I am trying to pull data from my mysql database which looks like this:

 

Database:news

table:users

 

Inside of the table is this:

email

firstname

lastname

 

I have three files:

 

the first one is list.php

<?php

//include the variables
include ("variables.php");
include ("db.php");

//connect to database
$mysql_connect = mysqli_connect($host,$db_user,$db_pass,$db_name)
or die ("Could not connect to database");

//variable to get data to the database
$result = mysqli_query($mysql_connect,$getfrom_db)
or die ("Error: ".mysqli_error($mysql_connect));

$info = mysqli_fetch_array($result);
$email = $info['email'];

echo ("$email");

?>

 

The second one is variables.php:

<?php

//define the variables
$get_email = Trim(stripslashes($_POST['get_email']));
$get_firstname = Trim(stripslashes($_POST['get_firstname']));
$get_lastname = Trim(stripslashes($_POST['get_lastname']));

?>

 

the last one is db.php:

<?php

//database connection settings
$host = "localhost";
$db_name = "news";
$db_table = "users";
$db_user = "root";
$db_pass = "";

//email addresses from database
$putinto_db = "INSERT INTO users (email,firstname,lastname) VALUES ('$get_email','$get_firstname','$get_lastname')";
$getfrom_db = "SELECT email FROM users";

//used for the connection to get email addresses from database
$email = $info['email'];

?>

 

I am trying to have it list all of the email addresses in the database. I have it working but only to a certain extent. It will list one of the email addresses. Can someone please tell me what im doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/117603-list-mysql-items/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.