a65 Posted January 1, 2013 Share Posted January 1, 2013 why i am getting the above error in this code <?php while($row=mysql_fetch_assoc($result)) { ?> Quote Link to comment Share on other sites More sharing options...
unlishema.wolf Posted January 1, 2013 Share Posted January 1, 2013 (edited) You have an error with your mysql query. I would need your query to determine if it is your query or your database. The other option is you can run the following code after adding your info: <?php // Edit below this line $mysql_host="localhost"; $mysql_user="username"; $mysql_pass="password"; $mysql_database="database" $mysql_sql="SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; // Do NOT Edit below this line $conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db($mysql_database)) { echo "Unable to select " . $mysql_database . ": " . mysql_error(); exit; } $result = mysql_query($mysql_sql); if (!$result) { echo "Could not successfully run query ($mysql_sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so I am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row . "</br>"; } mysql_free_result($result); ?> Edited January 1, 2013 by unlishema.wolf Quote Link to comment Share on other sites More sharing options...
Barand Posted January 1, 2013 Share Posted January 1, 2013 add if (!$result) die(mysql_error()); between your query and the while() Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 my coding was <?php mysql_connect("localhost","root",""); mysql_select_db("mydb"); $query="seleect * from table5"; $result=mysql_query($query); ?> <table><tr><td>name</td><td>age</td><td>gender </td><td>language1</td><td>language2</td><td>country </td><td>address</td><td>edit</td><td>delete</td></tr> <?php while($row=mysql_fetch_assoc($result)) { ?> <tr> <td><?php echo($row['name']); ?></td> <td><?php echo($row['age']); ?></td> <td><?php echo($row['gender']); ?></td> <td><?php echo($row['language1']); ?></td> <td><?php echo($row['language2']); ?></td> <td><?php echo($row['country']); ?></td> <td><?php echo($row['myaddress']); ?></td> <td><a href=edit.php?id=<?php echo($row['id']); ?> ?>>edit</a></td> <td><a href=delete.php?id=<?php echo($row['id']); ?>></a></td> <?php } ?> </table> Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 thanks... if (!$result) die(mysql_error()); solved the problem Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 1, 2013 Share Posted January 1, 2013 Looking at the query you have spelt 'SELECT' like 'SELEECT. If you change it to 'SELECT' it should work, I can't see anything else on first glance which could be causing it. Kind regards, AoTb. Quote Link to comment Share on other sites More sharing options...
unlishema.wolf Posted January 1, 2013 Share Posted January 1, 2013 Glad you fixed it. Good luck in the future. 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.