Welcome! Log In Create A New Profile

Advanced

[PHP] show info from mysql db

Posted by Tim Dunphy 
Tim Dunphy
[PHP] show info from mysql db
June 10, 2012 07:20AM
hello list,

I tried designing a very basic couple of web pages tonight that was
solely meant to build some php chops. intentionally cheesy. I got half
the way there by designing a page that grabs some info from an html
form and puts that info into a mysql database.

This part works. You can see that page here:

<html>
<head><title>Starship Crew</title></head>
<body bgcolor="black">
<center><img src="logo.jpg" alt="Star Trek Logo" /> </center>
<font size="3" color="white">
<style>
.box{
font-family:Tahoma, Geneva, sans-serif;
font-size:16px;
text-align: center
}
</style>

<p>Enter your First Name, Last Name, Rank, Division,Ship and Email
address.</p>
<form method="post" action="addcrew.php" >

<tr><td><label for="firstname">First name:</label>
<input type="text" id="firstname" name="firstname" /></td></tr><br />
<tr><label for="lastname">Last name:</label>
<input type="text" id="lastname" name="lastname" /></tr><br />
<tr><label for="rank">Rank:</label>
<input type="text" id="rank" name="rank" /><br /></tr>
<tr><label for="division">Division:</label>
<input type="text" id="division" name="division" /><br /></tr>
<tr><label for="ship">Ship:</label>
<input type="text" id="ship" name="ship" /><br /></tr>
<tr></tr><label for="email">Email:</label>
<input type="text" id="email" name="email" /><br /></tr>
<input type="submit" name="Submit" value="Submit" />
</form>

<a href='showcrew.php'>Show crew manifest</a>


<center><img src="enterprise.jpg" alt="Enterprise" /> </center>
</font>
</body>
</html>

This is the one table in the database:

mysql> describe crew_manifest;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| first_name | varchar(20) | YES | | NULL | |
| last_name | varchar(20) | YES | | NULL | |
| rank | varchar(10) | YES | | NULL | |
| division | varchar(10) | YES | | NULL | |
| ship | varchar(20) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
6 rows in set (0.06 sec)

and this is the corresponding php page that inputs the info:

<?php

$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$rank = $_POST['rank'];
$division = $_POST['division'];
$ship = $_POST['ship'];
$email = $_POST['email'];

$dbc = mysqli_connect('127.0.0.1','admin','secret','trek_db')
or die('Error connecting to MySQL database');


$query = "INSERT INTO crew_manifest VALUES
('$first_name','$last_name','$rank','$division','$ship','$email')";

$result = mysqli_query($dbc,$query)
or die('Error querying database');

echo "crew member added";


mysqli_close($dbc);


?>

But the page that reads the info is the problem:

<html>
<head>
<title>Show Crew</title>
</head>

<body bgcolor="black">
<center><img src="ncc1701.jpg" alt="NCC 1701" /> </center>
<font size="3" color="white">
<style>
.box{
font-family:Tahoma, Geneva, sans-serif;
font-size:16px;
text-align: center
}
</style>
<center>Crew Manifest</center>

<?php

$dbc = mysqli_conect('127.0.0.1','admin','secret','trek_db')
or die ('Could not connect to database');

$query = "SELECT * FROM crew_manifest";

$result = mysqli_query($dbc,$query);

while ($row = mysqli_fetch_array($result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$rank = $row['rank'];
$division = $row['division'];
$ship = $row['ship'];
$email = $row['email'];

echo $rank . '<br />';
}

mysqli_close($dbc);


?>
</font>
</html>

What I'd like to find out is why the while loop does not display info
from the database? The page does show up, but not any info from the
db.

Thanks in advance.

tim

--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Dunphy
[PHP] Re: show info from mysql db
June 10, 2012 02:30PM
wow! this fixed it..

$dbc = mysqli_connect('127.0.0.1','admin',secret','trek_db')
or die ('Could not connect to database');

used to be...

$dbc = mysqli_conect('127.0.0.1','admin','Duk30fZh0u','trek_db')
or die ('Could not connect to database');


d'oh!! spelling counts!!! :)

On Sun, Jun 10, 2012 at 1:15 AM, Tim Dunphy <[email protected]> wrote:
> hello list,
>
>  I tried designing a very basic couple of web pages tonight that was
> solely meant to build some php chops. intentionally cheesy. I got half
> the way there by designing a page that grabs some info from an html
> form and puts that info into a mysql database.
>
> This part works.  You can see that page here:
>
> <html>
> <head><title>Starship Crew</title></head>
> <body bgcolor="black">
> <center><img src="logo.jpg" alt="Star Trek Logo"  /> </center>
> <font size="3" color="white">
> <style>
>        .box{
>                font-family:Tahoma, Geneva, sans-serif;
>                font-size:16px;
>                text-align: center
>        }
> </style>
>
>  <p>Enter your First Name, Last Name, Rank, Division,Ship and Email
> address.</p>
>  <form method="post" action="addcrew.php" >
>
>    <tr><td><label for="firstname">First name:</label>
>    <input type="text" id="firstname" name="firstname" /></td></tr><br />
>    <tr><label for="lastname">Last name:</label>
>    <input type="text" id="lastname" name="lastname" /></tr><br />
>    <tr><label for="rank">Rank:</label>
>    <input type="text" id="rank" name="rank" /><br /></tr>
>    <tr><label for="division">Division:</label>
>    <input type="text" id="division" name="division" /><br /></tr>
>    <tr><label for="ship">Ship:</label>
>    <input type="text" id="ship" name="ship" /><br /></tr>
>    <tr></tr><label for="email">Email:</label>
>    <input type="text" id="email" name="email" /><br /></tr>
>    <input type="submit" name="Submit" value="Submit" />
>  </form>
>
>   <a href='showcrew.php'>Show crew manifest</a>
>
>
> <center><img src="enterprise.jpg" alt="Enterprise"  /> </center>
> </font>
> </body>
> </html>
>
> This is the one table in the database:
>
> mysql> describe crew_manifest;
> +------------+-------------+------+-----+---------+-------+
> | Field      | Type        | Null | Key | Default | Extra |
> +------------+-------------+------+-----+---------+-------+
> | first_name | varchar(20) | YES  |     | NULL    |       |
> | last_name  | varchar(20) | YES  |     | NULL    |       |
> | rank       | varchar(10) | YES  |     | NULL    |       |
> | division   | varchar(10) | YES  |     | NULL    |       |
> | ship       | varchar(20) | YES  |     | NULL    |       |
> | email      | varchar(20) | YES  |     | NULL    |       |
> +------------+-------------+------+-----+---------+-------+
> 6 rows in set (0.06 sec)
>
> and this is the corresponding php page that inputs the info:
>
> <?php
>
> $first_name = $_POST['firstname'];
> $last_name = $_POST['lastname'];
> $rank = $_POST['rank'];
> $division =  $_POST['division'];
> $ship = $_POST['ship'];
> $email = $_POST['email'];
>
> $dbc = mysqli_connect('127.0.0.1','admin','secret','trek_db')
>   or die('Error connecting to MySQL database');
>
>
> $query = "INSERT INTO crew_manifest VALUES
> ('$first_name','$last_name','$rank','$division','$ship','$email')";
>
> $result = mysqli_query($dbc,$query)
>  or die('Error querying database');
>
>  echo "crew member added";
>
>
>  mysqli_close($dbc);
>
>
> ?>
>
> But the page that reads the info is the problem:
>
> <html>
> <head>
> <title>Show Crew</title>
> </head>
>
> <body bgcolor="black">
> <center><img src="ncc1701.jpg" alt="NCC 1701"  /> </center>
> <font size="3" color="white">
> <style>
>        .box{
>                font-family:Tahoma, Geneva, sans-serif;
>                font-size:16px;
>                text-align: center
>        }
> </style>
> <center>Crew Manifest</center>
>
> <?php
>
>    $dbc = mysqli_conect('127.0.0.1','admin','secret','trek_db')
>     or die ('Could not connect to database');
>
>    $query = "SELECT * FROM crew_manifest";
>
>    $result = mysqli_query($dbc,$query);
>
>    while ($row = mysqli_fetch_array($result)) {
>    $first_name = $row['first_name'];
>    $last_name = $row['last_name'];
>    $rank = $row['rank'];
>    $division = $row['division'];
>    $ship = $row['ship'];
>    $email = $row['email'];
>
>    echo  $rank . '<br />';
>  }
>
>   mysqli_close($dbc);
>
>
> ?>
> </font>
> </html>
>
> What I'd like to find out is why the while loop does not display info
> from the database? The page does show up, but not any info from the
> db.
>
> Thanks in advance.
>
> tim
>
> --
> GPG me!!
>
> gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B



--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Adam Richardson
Re: [PHP] Re: show info from mysql db
June 10, 2012 06:20PM
On Sun, Jun 10, 2012 at 8:25 AM, Tim Dunphy <[email protected]> wrote:
> $dbc = mysqli_connect('127.0.0.1','admin',secret','trek_db')
>     or die ('Could not connect to database');
>
> used to be...
>
> $dbc = mysqli_conect('127.0.0.1','admin','Duk30fZh0u','trek_db')
>     or die ('Could not connect to database');

You had been keeping the password secret, but it looks like you
accidentally leaked it, so a replacement might be in order :)

Glad you got it fixed. Typos can be little buggers to find sometimes.

Adam

--
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Dunphy
Re: [PHP] Re: show info from mysql db
June 10, 2012 07:00PM
> You had been keeping the password secret, but it looks like you
> accidentally leaked it, so a replacement might be in order :)
>

oh wow.. gotta hate when you do that!!! on it!


> Glad you got it fixed. Typos can be little buggers to find sometimes.

me too.. fell back to the old 'echo hello' test strategy .. have to
try to remember that strategy before i go running for help.. :)

tim

On Sun, Jun 10, 2012 at 12:15 PM, Adam Richardson <[email protected]> wrote:
> On Sun, Jun 10, 2012 at 8:25 AM, Tim Dunphy <[email protected]> wrote:
>> $dbc = mysqli_connect('127.0.0.1','admin',secret','trek_db')
>>     or die ('Could not connect to database');
>>
>> used to be...
>>
>> $dbc = mysqli_conect('127.0.0.1','admin','Duk30fZh0u','trek_db')
>>     or die ('Could not connect to database');
>
> You had been keeping the password secret, but it looks like you
> accidentally leaked it, so a replacement might be in order :)
>
> Glad you got it fixed. Typos can be little buggers to find sometimes.
>
> Adam
>
> --
> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> http://nephtaliproject.com



--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Mihamina Rakotomandimby
Re: [PHP] Re: show info from mysql db
June 11, 2012 07:10AM
On 06/10/2012 07:50 PM, Tim Dunphy wrote:
>> Glad you got it fixed. Typos can be little buggers to find sometimes.
> me too.. fell back to the old 'echo hello' test strategy .. have to
> try to remember that strategy before i go running for help..:)

I dont agree: If you used exceptions (with real meanings to messages)
you would have saved time.

Use exceptions.

--
RMA.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Re: show info from mysql db
June 11, 2012 05:10PM
On 06/10/2012 09:50 AM, Tim Dunphy wrote:
>> You had been keeping the password secret, but it looks like you
>> accidentally leaked it, so a replacement might be in order :)
>>
>
> oh wow.. gotta hate when you do that!!! on it!
>
>
>> Glad you got it fixed. Typos can be little buggers to find sometimes.
>
> me too.. fell back to the old 'echo hello' test strategy .. have to
> try to remember that strategy before i go running for help.. :)

FYI: When developing, make sure to have "error_reporting = E_ALL" and
"display_errors = On" or be sure to tail your error_log file.

>
> tim
>
> On Sun, Jun 10, 2012 at 12:15 PM, Adam Richardson<[email protected]> wrote:
>> On Sun, Jun 10, 2012 at 8:25 AM, Tim Dunphy<[email protected]> wrote:
>>> $dbc = mysqli_connect('127.0.0.1','admin',secret','trek_db')
>>> or die ('Could not connect to database');
>>>
>>> used to be...
>>>
>>> $dbc = mysqli_conect('127.0.0.1','admin','Duk30fZh0u','trek_db')
>>> or die ('Could not connect to database');
>>
>> You had been keeping the password secret, but it looks like you
>> accidentally leaked it, so a replacement might be in order :)
>>
>> Glad you got it fixed. Typos can be little buggers to find sometimes.
>>
>> Adam
>>
>> --
>> Nephtali: A simple, flexible, fast, and security-focused PHP framework
>> http://nephtaliproject.com
>
>
>


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login