Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Retrieving information from mysql table

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Retrieving information from mysql table

Postby garethkilgo » Tue Jan 29, 2013 2:08 am

Hi, I am a complete newbie to PHP coding:

I cannot retrieve information from the created table and keep getting No database selected:
<?php
echo "Hello World!";
?>

<?php $con = mysql_connect("localhost","ryandb","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM customer") or die(mysql_error());

echo "<table border='1'>
<tr>
<th>firstname</th>
<th>surname</th>
<th>dob</th>
</tr>";


while($row = mysql_fetch_array($result))

{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['dob'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

Any help would be greatly appreciated !
Cheers
garethkilgo
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Jan 29, 2013 1:52 am

Re: Retrieving information from mysql table

Postby dblock » Tue Jan 29, 2013 2:51 am

i am new to html php and mysql

i have been trying to build a registration form too

you are trying to display the stuff in the mysql row ... which is a number of feild arranged in a straight line...


you are querying a database table ... remote or on localhost

then you try to

echo row ['feildname']
User avatar
dblock
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Jan 29, 2013 2:23 am

Re: Retrieving information from mysql table

Postby phpwreker » Tue Jan 29, 2013 2:57 am

learning this is really not that easy .. you have to think through many abstractions and blocks of the default programing code
User avatar
phpwreker
New php-forum User
New php-forum User
 
Posts: 22
Joined: Fri Dec 02, 2011 9:58 am

Re: Retrieving information from mysql table

Postby gether » Tue Jan 29, 2013 2:59 am

you arrange the default programing codes like

echo row ['fieldname']

all part of php language

and hope it works
User avatar
gether
New php-forum User
New php-forum User
 
Posts: 16
Joined: Tue Dec 25, 2012 7:38 pm

Re: Retrieving information from mysql table

Postby garethkilgo » Thu Jan 31, 2013 5:46 am

Hi,
I don't really get this - sorry!!!! :(
i still keep getting an error message-Parse error: syntax error, unexpected '[', expecting ',' or ';' in C:\wamp\www\mytest2.php on line 35
Do you mean:
$result = mysql_query("SELECT * FROM customer");

echo "<table border='1'>
<tr>
<th>firstname</th>
<th>surname</th>
<th>dob</th>
</tr>";


echo "<tr>";
echo row['firstname'] . "</td>";
echo row['surname'] . "</td>";
echo row['dob'] . "</td>";
echo "</tr>";

echo "</table>";

Thanks in advance
garethkilgo
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Jan 29, 2013 1:52 am

Re: Retrieving information from mysql table

Postby ashaman » Thu Jan 31, 2013 8:32 am

try
Code: Select all
mysql_connect('localhost', 'ryandb', '') or die("no");
    mysql_select_db('my_db') or die("not");
$result = mysql_query("SELECT * FROM customer");
while($row = mysql_fetch_assoc($rs)){
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['dob'] . "</td>";
echo "</tr>";

}
ashaman
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Jan 31, 2013 4:03 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 12 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.