php? Posted January 1, 2008 Share Posted January 1, 2008 The code below should take all usernames in the database and put them on a page... problem is it won't work and it comes up with these errors: Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\xampp\htdocs\tests\index.php on line 15 <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $result = mysql_query("SELECT * FROM users"); while($row = mysql_fetch_array($result)) { echo $row['username'] echo "<br />"; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/ Share on other sites More sharing options...
PHP_PhREEEk Posted January 1, 2008 Share Posted January 1, 2008 Missing semi-colon <?php while($row = mysql_fetch_array($result)) { echo $row['username']; echo "<br />"; } PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427177 Share on other sites More sharing options...
MikeDXUNL Posted January 1, 2008 Share Posted January 1, 2008 another solution, use a syntax highlighting program when coding Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427179 Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Okay, lol thanks for that dummy mistake.. but now I get this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\tests\index.php on line 12 Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427180 Share on other sites More sharing options...
PHP_PhREEEk Posted January 1, 2008 Share Posted January 1, 2008 Replace <?php $result = mysql_query("SELECT * FROM users"); with <?php if ( !$result = mysql_query("SELECT * FROM users") ) { die('MySQL Error: ' . mysql_error()); } PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427182 Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Okay that worked.. and now MySQL Error: No database selected isn't this selecting the database? mysql_select_db("username", $con); Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427184 Share on other sites More sharing options...
PHP_PhREEEk Posted January 1, 2008 Share Posted January 1, 2008 Okay that worked.. and now MySQL Error: No database selected isn't this selecting the database? mysql_select_db("username", $con); That is indeed a db selection statement, but which one are we going to use? Here you say "username", above you used "login". What's the db name? PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427186 Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Oops, indeed it should be login. But now *sigh* it comes up blank. The data I want to withdraw is in database 'login', table 'users', and field 'username'. Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427189 Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Oh wait caught it... should of had it echo $row['1']; As you can see i'm fairly newby.. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427191 Share on other sites More sharing options...
PHP_PhREEEk Posted January 1, 2008 Share Posted January 1, 2008 You can test for data being present, then dumping the data (for testing) if any records do exist: <?php if ( !$result = mysql_query("SELECT * FROM users") ) { die('MySQL Error: ' . mysql_error()); } if ( mysql_num_rows($result) > 0 ) { while ( $row = mysql_fetch_assoc($result) ) { echo "<pre>"; print_r($row); echo"</pre><br>"; } } else { echo "No results from query!"; } PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83944-solved-withdraw-help/#findComment-427193 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.