Jump to content

Can't Connect and Select.


zechdc

Recommended Posts

I am trying to connect to my database and select the infromation from one column then displaying it in the web browser. I have done this before but there is something wrong in my code and I cant figure out what it is. When I run the code it just displays "Connected to MySQL" Please take a look and let me know what is wrong. Thanks.

 

<?php

$username = "Test_user";
$password = "Test_pas";
$hostname = "localhost";
$table = "test_tbl";
$column1 = "EventDate";	
$connectdb = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";

$result = mysql_query("SELECT $column1 FROM $table");
print $result;

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/77059-cant-connect-and-select/
Share on other sites

I put that in the code and I get an error that says

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/p/o/g/pogotic/html/test.php on line 45

 

<?php

$username = "PogoticTest";
$password = "Tiffaney1";
$hostname = "p41mysql81.secureserver.net";
$table = "info";	
$dbh = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";

$result = mysql_query("SELECT * FROM $table");	
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))     //Line 45 
print $line
?>

The $line is an array you must now print out the elements of the array.  I do not know your field names so I will make up generic ones.

 

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {//Loop to display all turnover for given parameters
echo $line["FIELD_NAME"];
so on
and 
so on
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.