Jump to content

[SOLVED] how do i call specifc values with out using while()


jeger003

Recommended Posts

hello everyone,

im trying to call a value from the database so i can use in an if() statement but i dont want to use while() is there another way to do it?

 

here is what i have but of course it dont work

 


				$user_id_cookie = $_COOKIE['user_id'];
				$query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id");
				//$fetch_email = mysql_fetch_array($query_private)
				if(!empty($query_private))
				{
				$this->body .= "<input type=text name=b[email] value=\"".$query_private['private_email']."\" class=details>";
				}
				else
				{

				$this->body .= "<input type=text name=b[email] value=\"".$current_email."\" class=details>";
				}


you have to use mysql_fetch_array on $query_private to get an array from result.

 

i tried that but i keep getting error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result on line 173 "

 

line 173 is  $fetch_email = mysql_fetch_array($query_private);

 

 

$user_id_cookie = $_COOKIE['user_id'];
$query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id_cookie");
$fetch_email = mysql_fetch_array($query_private);
if(!empty($fetch_email['private_email']))
{
$this->body .= "<input type=text name=b[email] value=\"".$fetch_email['private_email']."\" class=details>";
}
else
{
$this->body .= "<input type=text name=b[email] value=\"".$current_email."\" class=details>";
}

 

i tried that but i keep getting error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result on line 173 "

 

line 173 is  $fetch_email = mysql_fetch_array($query_private);

 

This indicates, that the query failed. Try to display mysql_error

 

i tried that but i keep getting error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result on line 173 "

 

line 173 is  $fetch_email = mysql_fetch_array($query_private);

 

This indicates, that the query failed. Try to display mysql_error

 

 

your right.........now the error is

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

 

@dmccabe

i tried your code and it gave me same error as above........i dont understand whats going on

 

 

Change

$query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id_cookie");

to

$sql = "SELECT private_email FROM user WHERE id = $user_id_cookie";
$query_private = mysql_query($sql) or die(mysql_error().": $sql");

Change

$query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id_cookie");

to

$sql = "SELECT private_email FROM user WHERE id = $user_id_cookie";
$query_private = mysql_query($sql) or die(mysql_error().": $sql");

 

 

 

new error says

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1: SELECT private_email FROM user WHERE id =

Well here you are: $user_id_cookie is empty.

 

 

omg your right.......i was calling user id in cookie.....my cookies dont store user ids.......man i would have been at it all day had you not have caught this...

 

thanks so much...

 

in the future how can i use your technique??

 

i can just enter

$query_private = mysql_query($sql) or die(mysql_error().": $sql");

 

$sql can be the query to check?

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.