PHP Programming > Beginners - Learning PHP

Queries question

(1/1)

Elodin:
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 Code: ---$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 "<br>";
  }

mysql_close($con);
--- End code ---


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", "nancyW@cpi.com"),("John", "Test", "1799 Xyz dr Tempe AZ 87907", "johnT@cpi.com"),("Andrew", "Stress", "3459 PQR St Atlanta GA 36890", "andrewS@cpi.com"),("Andrew", "Stress", "3459 PQR St Atlanta GA 36890", "andrewS@cpi.com")).

  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.

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

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

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

I don't see them in your file.

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

Navigation

[0] Message Index

Go to full version