By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

php and mysql issues

P: 2
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 some code I found online to see if I could at least access my database but what I get is boggling me. My code is as follows:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. // Connecting, selecting database
  3. $link = mysql_connect('localhost', 'user', 'pass')
  4.     or die('Could not connect: ' . mysql_error());
  5. echo 'Connected successfully';
  6. mysql_select_db('test') or die('Could not select database');
  8. // Performing SQL query
  9. $query = 'SELECT * FROM addressbook';
  10. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  12. // Printing results in HTML
  13. echo "<table>\n";
  14. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  15.     echo "\t<tr>\n";
  16.     foreach ($line as $col_value) {
  17.         echo "\t\t<td>$col_value</td>\n";
  18.     }
  19.     echo "\t</tr>\n";
  20. }
  21. echo "</table>";
  23. // Free resultset
  24. mysql_free_result($result);
  26. // Closing connection
  27. mysql_close($link);
  28. ?>
  30. and what I get is a page that displays this:
  32. \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); ?>

[Please use CODE tags when posting source code. Thanks! --pbmods]

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 unable 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.

Jun 4 '07 #1
Share this Question
Share on Google+
1 Reply

P: 2
Issue solved no longer need help on this, I'll probably be back for more issues sometime thought.


[REMOVED. --pbmods]
Jun 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.