Results 1 to 12 of 12

Thread: [RESOLVED] View my emial address's in php

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] View my emial address's in php

    I'm having trouple viewing my emial address that have been saved in to mysql database how can i sort this here is my code there is no error showing in this code.

    http://www.prksoft.com/testview.php

    mysql info

    PHP Code:
    <?php
    $dbhost
    ='localhost';
    $dbuser='USERNAME';
    $dbpass='PASSWORD';

    $conn=mysql_connect($dbhost$dbuser$dbpass)
        or die(
    'Could not connect to mysql');

    $dbname='prksoft_newsletter';
    mysql_select_db($dbname);
    ?>

    This is the textview code

    PHP Code:
    <?php
    include "db_connect.php";

    $conn=mysql_connect($dbhost$dbuser$dbpass)
        or die(
    'Could not connect to mysql');


    $sql "select * from $newsletter";
    $result mysql_query($sql);

    while(
    $row=mysql_fetch_array($result)){
    ?>

    <table width="400" border="1" align="center">
     <tr>
      <td width="63"><strong>Email Address</strong></td>
      <td width="8"><strong>:</strong></td>
      <td width="307"><? echo $rows['address']; ?></td>
    </tr>
    </table>

    <p>&nbsp;       </p>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: View my emial address's in php

    Well for starters, you don't have a close brace for your while loop.

    Place

    Code:
    ERROR_REPORTING(E_ALL);
    At the top of your code, chances are the server you're running off of has error reporting turned off.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: View my emial address's in php

    here is the proper testview.php code.

    I put ERROR_REPORTING(E_ALL); at the top and it still shows no errors.

    PHP Code:
    <?php
    include "db_connect.php";

    $conn=mysql_connect($dbhost$dbuser$dbpass)
        or die(
    'Could not connect to mysql');


    $sql "select * from $newsletter";
    $result mysql_query($sql);

    while(
    $row=mysql_fetch_array($result)){
    ?>

    <table width="400" border="1" align="center">
     <tr>
      <td width="63"><strong>Email Address</strong></td>
      <td width="8"><strong>:</strong></td>
      <td width="307"><? echo $rows['address']; ?></td>
    </tr>
    </table>

    <p>&nbsp;       </p>

    <?php
    }
    mysql_close($conn);
    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: View my emial address's in php

    What does $newsletter contain? have you assigned it a proper table name?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: View my emial address's in php

    I sorted that problem now it wont show the email address's?

    Code:
    <?php
    
    include "db_connect.php";
    
    $conn=mysql_connect($dbhost, $dbuser, $dbpass)
    	or die('Could not connect to mysql');
    
    
    $sql = "select * from newsletter";
    $result = mysql_query($sql);
    
    while($row=mysql_fetch_array($result)){
    ?>
    
    <table width="400" border="1" align="center">
     <tr>
      <td width="63"><strong>Email Address</strong></td>
      <td width="8"><strong>:</strong></td>
      <td width="307"><? echo $rows['address']; ?></td>
    </tr>
    </table>
    
    <p>&nbsp;       </p>
    
    <?php
    }
    mysql_close($conn);
    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: View my emial address's in php

    You're doing

    Code:
    echo $rows['address'];
    When your variable is row, not rows.

  7. #7
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: View my emial address's in php

    Also are you selecting the database? You have a select statement in your original post, but I don't see it in the testview.php code.

    If db_connect.php is connecting and selecting, you may be overwriting your connection object when you do it again in testview.php

    Code:
    include "db_connect.php";
    
    $conn=mysql_connect($dbhost, $dbuser, $dbpass)
    	or die('Could not connect to mysql');
    Last edited by SambaNeko; Jun 17th, 2009 at 11:15 AM.

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: View my emial address's in php

    samba - yes... presumably these lines here take care of that:
    Code:
    include "db_connect.php";
    
    $conn=mysql_connect($dbhost, $dbuser, $dbpass)
    	or die('Could not connect to mysql');
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: View my emial address's in php

    tg - Sorry, edited my post for more clarity on what I meant... db_connect.php is making $conn, selecting a db, but then testview.php makes a new connection right after that into the same variable $conn... If you put the included code of db_connect.php into testview.php, you get this:

    Code:
    $dbhost='localhost';
    $dbuser='USERNAME';
    $dbpass='PASSWORD';
    
    $conn=mysql_connect($dbhost, $dbuser, $dbpass)
        or die('Could not connect to mysql');
    
    $dbname='prksoft_newsletter';
    mysql_select_db($dbname);
    
    $conn=mysql_connect($dbhost, $dbuser, $dbpass)
    	or die('Could not connect to mysql');
    mysql_connect is happening twice, and the second time isn't selecting a database.
    Last edited by SambaNeko; Jun 17th, 2009 at 11:22 AM.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: [RESOLVED] View my emial address's in php

    Now that i got that sorted when i try to signup it dosent save the address in to the mysql database this is the code?

    address http://www.prksoft.com/signup.php

    Code:
    <html>
    <head></head>
    <body>
    <form action="signup.php" method="POST">
    <input type="text" size="35" name="address">   <input type="submit" value="Get Special Offers!" name="submit">
    </form>
    
    <?php
    if ($submit)
    {
    include "db_connect.php";
    $address = $_POST['address'];
    mysql_query("INSERT INTO newsletter (address)
    			VALUES ('$address')");
    echo "$address has been added.";
    }
    ?>
    Last edited by Jamie_Garland; Jun 17th, 2009 at 12:25 PM.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  11. #11
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: [RESOLVED] View my emial address's in php

    That'll almost work. Just change this...

    Code:
    if ($submit)
    ...to this...

    Code:
    if (isset($_POST['submit']))
    But you should also never insert to a database without sanitizing the input first - look up "SQL injection" for the troubles that can cause. So, do something like this here:

    Code:
    $address = mysql_real_escape_string(stripslashes($_POST['address']));
    You can look up both of these - mysql_real_escape_string() and stripslashes() - on PHP.net for more info.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: [RESOLVED] View my emial address's in php

    How would i do error checking for duplicate email or blank text box?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width