Queries question

Hello,

I apologize in advance if this is the wrong kind of question to ask here. I’m trying to finish php code that will allow me to post data from a table implemented on a server through sql. The code I’m using is as follows:

[php]$con=mysql_connect(“servername”,“gthomson”,“newpass”);
mysql_select_db(“gthomson”, $con);
$query = “SELECT * FROM PersonInfo”;
$result = mysql_query($query );

while($row = mysql_fetch_array($result))
{
echo $row[‘firstName’] . " " . $row[‘Email’];
echo “
”;
}

mysql_close($con);[/php]

The table, Personinfo, was created through sql using phpmyadmin. The lines I used in phpmyadmin were:

CREATE TABLE PersonInfo (firstName VARCHAR(32), lastName VARCHAR(32), Address VARCHAR(256), Email VARCHAR(64));
INSERT INTO PersonInfo(firstName, lastName, Address, Email)VALUES(“Nancy”, “Williams”, “123 W. Park Ave Chandler AZ 87907”, "[email protected]"),(“John”, “Test”, “1799 Xyz dr Tempe AZ 87907”, "[email protected]"),(“Andrew”, “Stress”, “3459 PQR St Atlanta GA 36890”, "[email protected]"),(“Andrew”, “Stress”, “3459 PQR St Atlanta GA 36890”, "[email protected]")).

I know this code is very basic and nearly identical to that found in the w3schools resource, but when I tried implementing it the expected table of information did not appear when the php file was accessed; simply a blank webpage shows up. I know I’m using the right html address, so I was wondering if I have a syntax error, or if there’s a mistake in how I called certain variables in the code. Thanks in advance for any help that can be provided.

you have to save this file as .php not as .html :slight_smile:

If you have already saved this as php, check whether you are using right servername ? localhost if its in local and dbusername and password
:slight_smile:

Hi. Did you include the opening and closing php tags: <?php....?>

I don’t see them in your file.

Yes, it was a problem with the server name (not using localhost). Thanks for the advice.

Sponsor our Newsletter | Privacy Policy | Terms of Service