blackenedheart Posted March 22, 2013 Share Posted March 22, 2013 (edited) Hi Everyone, This is my first post so please let me know if this is not the appropriate place for this. Also, I would like to thank anyone who is willing to help me in advance. My server is running the newest versions of phpMyAdmin and MySQL. I am trying to perform a simple task of pulling data from my database and I am almost 100% sure the code is perfect. So I think there is a problem with my phpMyAdmin settings. But what could it be? What I have is 3 records in a table called "registration" and I am trying to format those into an HTML table. Here is my code. <html> <title>Search The Database</title> <body bgcolor="#000000" text="#FF0000" link="#00FF00"> <p> </p> <p> </p> <p> </p> <table width="81%" height="92" border="0" align="center" cellpadding="10" cellspacing="10" bordercolor="#FF0000" bgcolor="#FF0000"> <tr bgcolor="#000000"> <td width="15%" height="45"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">FIRST NAME </font></strong></div></td> <td width="14%"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">LAST NAME</font></strong></div></td> <td width="7%"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">CITY</font></strong></div></td> <td width="9%"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">STATE</font></strong></div></td> <td width="12%"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">COUNTRY</font></strong></div></td> <td width="9%"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">EMAIL</font></strong></div></td> <td width="14%"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">PASSWORD</font></strong></div></td> <td width="20%"><div align="center"><strong><font size="3" face="Courier New, Courier, mono">PASSWORD TWICE </font></strong></div></td> </tr> <?php $host="XXX"; $username="XXX"; $password="XXX"; $database="XXX"; $connection=mysql_connect("$host", "$username", "$password"); $selectdatabase=mysql_select_db($database); $databasequery = "SELECT * FROM registration"; $result = @sqli_query($connection, $databasequery); if ($result) { while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $firstname = $row ['firstname']; $lastname = $row ['lastname']; $city = $row ['city']; $state = $row ['state']; $country = $row ['country']; $email = $row ['email']; $password = $row ['password']; $passwordverify = $row ['passwordverify']; echo "<tr>"; echo '<td> .$firstname. </td>'; echo '<td> .$lastname. </td>'; echo '<td> .$city. </td>'; echo '<td> .$state. </td>'; echo '<td> .$country. </td>'; echo '<td> .$email. </td>'; echo '<td> .$password. </td>'; echo '<td> .$passwordverify. </td>'; echo "</tr>"; } } ?> </table> </body> </html> Edited March 23, 2013 by ignace Added code tags Quote Link to comment Share on other sites More sharing options...
Barand Posted March 22, 2013 Share Posted March 22, 2013 (edited) You cannot mix mysql and mysqli - completely different libraries edit Turn on error reporting and check for db errors with mysql_error() or mysqli_error() (whichever you choose, but it should be mysqli nowadays) Edited March 22, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 22, 2013 Share Posted March 22, 2013 Also, this has absolutely nothing to do with PhpMyAdmin... Quote Link to comment Share on other sites More sharing options...
blackenedheart Posted March 22, 2013 Author Share Posted March 22, 2013 Okay thanks. How would I change the above to mysqli? Is it just the connections? Quote Link to comment Share on other sites More sharing options...
blackenedheart Posted March 22, 2013 Author Share Posted March 22, 2013 I was under the impression that all my code was in mysqli Quote Link to comment Share on other sites More sharing options...
DavidAM Posted March 22, 2013 Share Posted March 22, 2013 And forget you ever heard of the error suppression operator ("@"). $connection=mysql_connect("$host", "$username", "$password"); $selectdatabase=mysql_select_db($database); $databasequery = "SELECT * FROM registration"; $result = @sqli_query($connection, $databasequery); if ($result) { while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) Your connection and database selection are using the mysql extension.Your fetch is using the mysqli extension Your query is calling a function that does not exist, but you have suppressed the error -- looks like you tried to use mysqli. But as Barand said you can't mix them. Use one or the other, and since the mysql (no "i") extension is deprecated, you should use mysqli Quote Link to comment Share on other sites More sharing options...
blackenedheart Posted March 22, 2013 Author Share Posted March 22, 2013 Ahh I get it now... I have a lot of books on MySQL but not MySQLi... Also, can I ask while I have some attention here, where can I learn more about PDO? I have not been able to find a book that really describes PDO. I am also trying to learn ColdFusion, but can't figure out why so many people are "abandoning" ColdFusion... Quote Link to comment Share on other sites More sharing options...
blackenedheart Posted March 22, 2013 Author Share Posted March 22, 2013 (edited) I updated with this, but again no luck... <?php $host="XXX"; $username="XXX"; $password="XXX"; $database="XXX"; $mysqli = new mysqli("$host", "$username", "$password", "$database"); $query = "SELECT firstname, lastname, city, state, country FROM registration ORDER by ID DESC LIMIT 50,5"; if ($result = $mysqli->query($query)) { while ($row = $result->fetch_assoc()) { printf ("%s (%s)\n", $row["First Name"], $row["Last Name"]); } $result->free(); } $mysqli->close(); ?> Edited March 23, 2013 by ignace Added code tags Quote Link to comment Share on other sites More sharing options...
blackenedheart Posted March 22, 2013 Author Share Posted March 22, 2013 And again, I appreciate all the help, but I must be doing something wrong here... Quote Link to comment Share on other sites More sharing options...
Barand Posted March 23, 2013 Share Posted March 23, 2013 SELECT firstname, lastname .... So the results will be $row['firstname'], $row['lastname'] Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 23, 2013 Share Posted March 23, 2013 1. Don't put variables in strings. $host, not "$host". 2. check for errors. See my signature on debugging SQL. 3. print_r($row) will show you what's in the row. You will not have an array key of "First Name" when you selected "first_name" (And you should never have an array key or column name with spaces.) Quote Link to comment Share on other sites More sharing options...
blackenedheart Posted March 23, 2013 Author Share Posted March 23, 2013 Hi Guys... Thanks for your help so far. What I am trying to do unfortunately still is not working, but that's my issue for now. I am coming over from being an iPhone/Objective-C programmer and MySQL is kicking my ass. PHP is a lot like Objective-C but dealing with phpMyAdmin is driving me crazy. I'm looking into DHTML as well as ColdFusion because at this rate, nothing will ever get done! Frankly, I am having my doubts about the phpMyAdmin MySQL combination. Data retrieval on the web should not be this difficult or unreliable. Quote Link to comment Share on other sites More sharing options...
blackenedheart Posted March 23, 2013 Author Share Posted March 23, 2013 I wanted to update this again by saying that some of the people that "hardcode" for MYSQL should consider trying a backend like MURA. It's quite different than WORDPRESS and it's COLDFUSION powered. Again, not trying to lead anyone astray here, but sometimes "hardcoding" is just plain to "hard." Why stunt your creativity when it's all handed to you on a silver platter? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 23, 2013 Share Posted March 23, 2013 Frankly, I am having my doubts about the phpMyAdmin MySQL combination. Data retrieval on the web should not be this difficult or unreliable. Why do you keep blaming phpMyAdmin for your coding? Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 23, 2013 Share Posted March 23, 2013 What are you talking about?? Quote Link to comment Share on other sites More sharing options...
ignace Posted March 24, 2013 Share Posted March 24, 2013 He thinks phpMyAdmin = PHP, he actually means PHP. Quote Link to comment Share on other sites More sharing options...
ignace Posted March 24, 2013 Share Posted March 24, 2013 (edited) I have a lot of books on MySQL but not MySQLi...MySQLi extension (mysqli_* functions) is the successor of the MySQL extension (mysql_* functions), this is merely a PHP thing and has nothing to do with the actual database. You are however encouraged to use these new functions as the mysql_* functions are deprecated and will be removed in future versions of PHP. Edited March 24, 2013 by ignace Quote Link to comment Share on other sites More sharing options...
haku Posted March 24, 2013 Share Posted March 24, 2013 He thinks phpMyAdmin = PHP, he actually means PHP. That sure clears things up! I think we were all a little lost as to what he was talking about. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.