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
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
?>

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.