Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am having issues with connecting to my mysql database. I am not getting any error messages but when trying to add records nothing happens. I tried writing a script to see if I could display the database or get the appropriate error messages. My code is as follows:Code: Select all
<?
// Connecting, selecting database
$link = mysql_connect('localhost', 'user', 'pass')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('test') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM addressbook';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>Code: Select all
\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t\n"; foreach ($line as $col_value) { echo "\t\t$col_value\n"; } echo "\t\n"; } echo ""; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?>To my understanding, what it is doing is it is taking the ">" from the first "<table\>" and calling it the ending tag. For some reason it does not want to display the table. I am not sure if there is something wrong with the configuration or what. I am able to get access to my mysql server through phpmyadmin and am able to add databases and all functionality seems to be there. But for some reason it seems I am unable to connect through code on a PHP script I made. can anyone help me with this?
Also one more thing, which I'm not sure is really any kind of issue of concern or not but thought I should mention it is that, when I write php code using "<?php" I get absolutely nothing on the page where when using "<?" seems to be parsing the code fine on a simple "hello world" script as well as with a sendmail script.
I am a newbie at this and would really appreciate any help.
Thanks
Mike
Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]