php and mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Omgzr
Forum Newbie
Posts: 1
Joined: Sun Jul 22, 2012 2:31 pm

php and mysql

Post by Omgzr »

Hey, am trying to make a query that shows me all the mails registered into my database.
My database name is registros
My table name is ingreso
The var for mail is called correo in my program

I tried that but is not working for me, if you guys can help me to find the mistake I would appreciate it

Code: Select all

<html>
<body bgcolor="black">

<b>

<head><title>Administrador</title></head>

<h1 align="center" class="Estilo1"><font face="bell mt cursiva" color="darkred" size="12">
<font face="bell mt cursiva" color="darkred" size="12"> <marquee bgcolor="black">Usuarios registrados en la base de datos</marquee></font>
<center><img src="iupsm.jpg" style="border:15px solid#333300" width="397" height="268"></center>


<?php
$conexion=mysql_pconnect("localhost","root","");
if(!$conexion){
echo "No Se Pudo Conectar";
exit;
}
mysql_select_db("registros");

echo '<h2>Usuarios registrados:</h2>';

$sql = "SELECT correo FROM ingreso";

// run the query. Will return a resource or false
$result = mysql_query($sql);

// if it ran OK
if ($result) {
// while I have more results, loop through them
// returning each result as an array
while ($user = mysql_fetch_array($result)) {
// use the array keys (column names) to output the data
echo $ingreso['correo'], '<br />';
}
}
Last edited by Benjamin on Sun Jul 22, 2012 3:27 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
gooney0
Forum Commoner
Posts: 56
Joined: Fri Jan 21, 2011 1:40 pm
Location: Reston, VA

Re: php and mysql

Post by gooney0 »

This line make no sense:

Code: Select all

echo $ingreso['correo'], '<br />';  
You don't have such a variable. Instead you should use $user.

Try print_r($user) and you'll see the resulting array from mysql_fetch_array.
Post Reply