Jump to content

Question about outputting sql - need help fixing up my code


admaster

Recommended Posts

I have an sql database with two 'columns'?

there's username and password
and there's values under it.

this is an sql table

I 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 3

Warning: 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 3

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 4[/code]

thanks.
[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]

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]
[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 4

Warning: 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
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 4

Warning: 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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.