Jump to content

[SOLVED] how do i write this simple code?


mybluehair

Recommended Posts

im making a login file, and it sayes "welcome to $name chatroom". well, at setup, a admin creates a table in mysql called settings. (threw a php file ofcourse) in this table, there are 3 feilds. in order:

"password

chatroomname

websiteaddress"

 

well so apparently i want to make a mysql query in login.php to grab whatever is in "chatroomname". here is what i tryed:

 

$query1="SELECT * FROM settings";

        $result=mysql_query($query1);

 

$name=mysql_result($result, '', 'chatroomname', '');

 

but i just get a mysql error. so how would i write that?

 

Link to comment
https://forums.phpfreaks.com/topic/77061-solved-how-do-i-write-this-simple-code/
Share on other sites

First you need to connect to the db (*use your own details here:

//	CONNECT TO MYSQL
$conn = mysql_connect($db_host, $db_uname, $db_pass);
$res = mysql_select_db($db_dbname, $conn);

Then try something like this:

$query1="SELECT * FROM settings";
$result=mysql_query($query1);

$name=mysql_result($result, 0, ''chatroomname");

See http://uk3.php.net/manual/en/function.mysql-result.php, for details...

 

Also, when posting it's usually good to post the actual error...

First you need to connect to the db

see accually im not that stupid. that was only a snipet of the code.

 

 

but i still need help. here is my new code:

$result = mysql_query('SELECT chatname FROM settings');

if (!$result) {

    die('Could not query:' . mysql_error());

}

echo mysql_result($result, 2);

 

and error:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 2 on MySQL result index 3 in /home/gotdrake/public_html/tutorial/test.php on line 15

 

First you need to connect to the db

see accually im not that stupid. that was only a snipet of the code.

 

We don't know that if you don't post the error do we?

 

but i still need help. here is my new code:

$result = mysql_query('SELECT chatname FROM settings');

if (!$result) {

    die('Could not query:' . mysql_error());

}

echo mysql_result($result, 2);

 

and error:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 2 on MySQL result index 3 in /home/gotdrake/public_html/tutorial/test.php on line 15

 

What is line 15?

Insert this code, and post back the results:

 

$result = mysql_query('SELECT chatname FROM settings');
if (!$result) {
    die('Could not query:' . mysql_error());
}
$row = mysql_fetch_array($result);
echo "<pre";
print_r($row);
die("</pre>");

 

PhREEEk

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.