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
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...

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.