|
-
Jun 17th, 2009, 10:13 AM
#1
Thread Starter
Frenzied Member
[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> </p>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 17th, 2009, 10:18 AM
#2
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.
-
Jun 17th, 2009, 10:47 AM
#3
Thread Starter
Frenzied Member
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> </p>
<?php
}
mysql_close($conn);
?>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 17th, 2009, 10:50 AM
#4
Re: View my emial address's in php
What does $newsletter contain? have you assigned it a proper table name?
-tg
-
Jun 17th, 2009, 11:00 AM
#5
Thread Starter
Frenzied Member
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> </p>
<?php
}
mysql_close($conn);
?>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 17th, 2009, 11:03 AM
#6
Re: View my emial address's in php
You're doing
Code:
echo $rows['address'];
When your variable is row, not rows.
-
Jun 17th, 2009, 11:11 AM
#7
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.
-
Jun 17th, 2009, 11:15 AM
#8
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
-
Jun 17th, 2009, 11:16 AM
#9
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.
-
Jun 17th, 2009, 11:54 AM
#10
Thread Starter
Frenzied Member
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
-
Jun 17th, 2009, 01:54 PM
#11
Re: [RESOLVED] View my emial address's in php
That'll almost work. Just change this...
...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.
-
Jun 17th, 2009, 03:18 PM
#12
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|