php-general Digest 10 Jun 2012 12:26:05 -0000 Issue 7848

Topics (messages 318206 through 318207):

show info from mysql db
        318206 by: Tim Dunphy
        318207 by: Tim Dunphy

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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 <bluethu...@gmail.com> 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

--- End Message ---

Reply via email to