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>";
				}


Link to comment
Share on other sites

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>";
}

Link to comment
Share on other sites

 

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

 

 

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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 =

Link to comment
Share on other sites

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?

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.