admaster Posted November 29, 2006 Share Posted November 29, 2006 I have an sql database with two 'columns'?there's username and passwordand there's values under it.this is an sql tableI want a php script that will display the contents fo the username box...can anyone help me please?I used this:[code]<?$sql = "SELECT username FROM beta";$query = mysql_query($sql);while($row = mysql_fetch_assoc($query)){ echo $row['username'].'<br />';}?>[/code]obviously, its bad...it gives me the errors:[code]Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\xampp\htdocs\php\db_output_test.php on line 3Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Program Files\xampp\htdocs\php\db_output_test.php on line 3Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\php\db_output_test.php on line 4[/code]thanks. Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/ Share on other sites More sharing options...
admaster Posted November 29, 2006 Author Share Posted November 29, 2006 Oh yes...and I forgot.I have a password for my sql database Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132397 Share on other sites More sharing options...
Caesar Posted November 29, 2006 Share Posted November 29, 2006 You need a connection string/class first, before running any queries:http://us3.php.net/mysql_connect Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132400 Share on other sites More sharing options...
admaster Posted November 29, 2006 Author Share Posted November 29, 2006 Okay. I did that. Still doesn't work.Can you fix up my code, please? sorry, i'm a newbie at php Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132403 Share on other sites More sharing options...
Caesar Posted November 29, 2006 Share Posted November 29, 2006 Paste the entire code you have here up to this point, and I will look at it for you. Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132405 Share on other sites More sharing options...
admaster Posted November 29, 2006 Author Share Posted November 29, 2006 [code]<?$link = mysql_connect('localhost', 'root', 'password');if (!$link) { die('Could not connect: ' . mysql_error());}echo 'Connected successfully';$sql = "SELECT username FROM beta";$query = mysql_query($sql);while($row = mysql_fetch_assoc($query)){ echo $row['username'].'<br />';}mysql_close($link);?>[/code]It gives me the connected successfuly, a good thing, but gives this:[code]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\php\db_output_test.php on line 11[/code] Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132408 Share on other sites More sharing options...
admaster Posted November 29, 2006 Author Share Posted November 29, 2006 So, can you help me now? ;) Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132412 Share on other sites More sharing options...
Caesar Posted November 29, 2006 Share Posted November 29, 2006 For this part...try the following:[code]<?php $sql = "SELECT username FROM beta"; $query = mysql_query($sql, $var); while($row = mysql_fetch_row($query)) { echo $row[0].'<br />'; // Note that you need to know what column "username" is. First column/field is "0", next is "1"...etc. }?>[/code] Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132415 Share on other sites More sharing options...
admaster Posted November 29, 2006 Author Share Posted November 29, 2006 [code]Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\xampp\htdocs\php\db_test2.php on line 4Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\php\db_test2.php on line 6[/code]anyway, my sql has a password Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132419 Share on other sites More sharing options...
Caesar Posted November 29, 2006 Share Posted November 29, 2006 I added a note to my last post. Make sure you've changed [color=red]$row['username'][/color] to [color=green]$row[0][/color]. Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132422 Share on other sites More sharing options...
admaster Posted November 29, 2006 Author Share Posted November 29, 2006 Now these erros:[code]Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\xampp\htdocs\php\db_test2.php on line 4Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\php\db_test2.php on line 6[/code] Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132427 Share on other sites More sharing options...
admaster Posted November 29, 2006 Author Share Posted November 29, 2006 So, could someone help me fix up my code? Link to comment https://forums.phpfreaks.com/topic/28913-question-about-outputting-sql-need-help-fixing-up-my-code/#findComment-132443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.