Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Bálint Horváth
Problem solved succesfully after changed the query integer apostrofyless..
and printed the mysql_errno() and mysql_error()...

Remember:
-In the script languages as php the apostrofy ' or " or sg. like these means
the string marker...
-While ure developing show all error codes and messages...
-If ur query contains errors u'll not get the resource id to use just a
false boolean...
-..and always check u don't have empty variables... :D

Let's ride PHP!

Bálint Horváth
(Valentine)
On 25 May 2011 06:57, "Negin Nickparsa"  wrote:
> :D
> tnx very much
> *Notice*: Undefined variable: query in *D:\phpweb\Doctor.php* on line *45*
> 1065:Query was empty


Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Paul M Foster
On Wed, May 25, 2011 at 08:57:18AM +0430, Negin Nickparsa wrote:

> $id=(int)$_POST['txt'];
> $query1="select * from patient where id=".$id."";

You're not *thinking* about what you're doing. The above is silly. Think
about it: you're sending a string to MySQL. If $_POST['txt'] returns a
string which looks like the number 1, then

$query1 = "select * from patient where id = $_POST[txt]";

should suffice. If you like, test $_POST['txt'] first by echoing it.


> echo $query1;
> $result1=mysql_query($query1);

Ideally, you should be calling this function with an added "connection"
parameter. Like this:

$link = mysql_connect($connection_stuff);
$result1 = mysql_query($query1, $link);

It's not *necessary*, but advisable.

mysql_query() returns a "resource" object, unless there is a problem. If
there is a problem, then it returns FALSE. You can check what it returns
this way:

if (is_resource($result1))
print "It's a resource!";
elseif ($result1 === FALSE)
print "It's false!";
else
print "I don't know what the heck it is!";

> 
> echo $result1;

I don't know what you'll get from this "echo" if $result1 truly is a
resource. But if it's false, you won't get much. $result1 should be a
"resource" object, which means it's opaque. You can't know what's in it
unless you use a "helper" function like mysql_num_rows(), etc.

> $num2=Mysql_num_rows($result1);
> $num3=Mysql_num_fields($result1);
> 
> still it has previous error
> 
> Here is my output:select * from patient where id=1
> *Warning*: mysql_num_rows() expects parameter 1 to be resource, boolean
> given in
> 
> *Warning*: mysql_num_fields() expects parameter 1 to be resource, boolean
> given in **

Your error messages clearly mean that 1) you're not getting a proper
resource object back from mysql_query(), or 2) you're somehow changing
$result1 into a boolean before passing it to these other functions. But
I suspect it's #1 above.

Please see the documentation for these functions at php.net. It may
even be available in your native language.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Negin Nickparsa
i recieve nothing not a resource id and nore false


Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Bálint Horváth
If the query is incorrect u get boolean: false, if its correct u get a
resource id...

Bálint Horváth
On 25 May 2011 06:28, "Negin Nickparsa"  wrote:


Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Negin Nickparsa
$result1=mysql_query($query1);

echo $result1;

it can't echo $result1
i don't know why?


Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Negin Nickparsa
Bálint Horváth,
the second post of me is using your idea
your idea is working but why i have error still?


Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Negin Nickparsa
$id=(int)$_POST['txt'];
$query1="select * from patient where id=".$id."";
echo $query1;
$result1=mysql_query($query1);

echo $result1;
$num2=Mysql_num_rows($result1);
$num3=Mysql_num_fields($result1);

still it has previous error

Here is my output:select * from patient where id=1
*Warning*: mysql_num_rows() expects parameter 1 to be resource, boolean
given in

*Warning*: mysql_num_fields() expects parameter 1 to be resource, boolean
given in **


Re: [PHP] simple question abt convert to integer

2011-05-24 Thread Bálint Horváth
Hi,
I've a simply idea...
If you have integer in your mysql, don't use " at that field in the query...
Try this:
$query="select * from patient where id=".$id."";
There isn't apostrofy in the mysql query...

Bálint Horváth
On 25 May 2011 06:06, "Negin Nickparsa"  wrote:
> my code is this:
> $query1="select * from patient where id=".$_POST['txt'];
> it works but
> i think because i have error in next line:
> *Warning*: mysql_num_rows() expects parameter 1 to be resource, boolean
> given
>
> $num2=Mysql_num_rows($result1);
>
> i echoed $ query1 and the result was this=>select * from patient where
id=1
> maybe it can't convert $_POST['txt'] from String to integer and then it
> can't get my $num
> it is int in my mysql
> how can i correct $query1?


[PHP] simple question abt convert to integer

2011-05-24 Thread Negin Nickparsa
my code is this:
$query1="select * from patient where id=".$_POST['txt'];
it works but
i think because i have error in next line:
*Warning*: mysql_num_rows() expects parameter 1 to be resource, boolean
given

$num2=Mysql_num_rows($result1);

i echoed $ query1 and the result was this=>select * from patient where id=1
maybe  it can't convert $_POST['txt'] from String to integer and then it
can't get my $num
it is int in my mysql
how can i correct $query1?


[PHP] about php comet

2011-05-24 Thread 李白|字一日
hello,

I am every interested in comet applications recently, and sadly found php is
very weak in this area.

i am just wondering if it is possible to write an extension to extend the
ability of the php to easy the way to comet applications?

if it possible for php to hold the connect from the client when it is in
fast cgi mode or apache mod php mode?

thanks.


Re: [PHP] GnuPG from PHP - Where is the include ??

2011-05-24 Thread Stuart Dallas
On Tue, May 24, 2011 at 8:41 PM, Eli Orr (Office)  wrote:
> Please advise - I'guess it is not a build in and looking for the GnuPG PHP
> include as
> all the GnuPG functions are now considered undefined.

http://php.net/gnupg.installation

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] GnuPG from PHP - Where is the include ??

2011-05-24 Thread Eli Orr (Office)
Please advise - I'guess it is not a build in and looking for the GnuPG 
PHP include as

all the GnuPG functions are now considered undefined.

See below.

Thanks

Eli

//  GnuPG from PHP - Where is the include ??
//  http://www.gnupg.org/gph/en/manual.html
//  http://www.gnupg.org/documentation/howtos.en.html
//  GnuPG allows to encrypt and sign your data and communication,
//  features a versatile key management system as well as access
//  modules for all kinds of public key directories.
//

echo "GNU Encrypt with agreed secret key between sides.";

$secret_key = "8660281B6051D071D94B5B230549F9DC851566DC"; // Only shared 
parties know this
$the_secret_content  = "this is a very secret XML keep the secret key in 
the server and client well hidden from 4rd parties"; // Only shared 
parties know this


echo "Secret Key between Parties: [$secret_key] ";
echo "The sensitive content to keep safe 
 from 3rd parties:  $the_secret_content ";


//Creating the encryption content
$res = gnupg_init();
gnupg_addencryptkey($res, $secret_key);
$enc = gnupg_encrypt($res, $the_secret_content);
echo "This is the sensitive content encrypted by strong shared secret 
key:[".$enc."] ";


echo "Secret Key between Parties: [$secret_key] ";

 $res = gnupg_init();
gnupg_adddecryptkey($res,$secret_key);
$plain = gnupg_decrypt($res, $enc);

echo "This is the sensitive content decrypted by recieving party 
 that has the shared secret key:[".$plain."] ";

_

_


Re: [PHP] strcmp()?

2011-05-24 Thread tedd

At 11:10 AM -0700 5/24/11, David Harkness wrote:

On Tue, May 24, 2011 at 12:48 AM, Vitalii Demianets 
 wrote:



 So. to write compatible scripts one should check "< 0", not "== -1".



Which matches the documentation:

Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2,
and 0 if they are equal.

David


David:

I think the point here is that the documentation says the function 
returns a number greater than zero, or less than zero, or zero.


It's just that many who have responded on this list show that the 
function commonly returns -1, 1, and 0.


It's wise to keep with the documentation.

Cheers,

tedd

--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strcmp()?

2011-05-24 Thread David Harkness
On Tue, May 24, 2011 at 12:48 AM, Vitalii Demianets  wrote:

> So. to write compatible scripts one should check "< 0", not "== -1".
>

Which matches the documentation:

Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2,
and 0 if they are equal.

David


Re: [PHP] WHERE field = a range of values (value

2011-05-24 Thread Paul S
On Tue, 24 May 2011 21:09:34 +0700, "Richard S. Crawford"  
 wrote:



On Tue, May 24, 2011 at 6:51 AM, Paul S  wrote:

I'd like to check a table to retrieve rows for which one field equals  
one

of a set of values


#get products(fields) in category list
   while ($row = $db_connect->fetch_array($productsincategory_list)) {
  $product = $row ['selection'];
  $fields = "$fields" . " $product,";
   }
   $fields = substr($fields,'',-1);

## echo "$fields";
## $fields = Prod1, ProD2, Prod3

This ...

$db_connect->fetch_array($sql_result);

$store_result = $db_connect->query("select * from $sql_usertable WHERE
(($sql_usertable.product1 = '($fields)')||( $sql_usertable.product2 =
'($fields)')||($sql_usertable.product3 = '($fields)')) order by id desc
limit $entry, $entries_per_page");

doesn't work. It selects nothing (obviously because no single field  
equals

' (Prod1, Prod2, Prod3) '). But it's the idea. Can I change the:

= '($fields)'

syntax I'm trying?

The actual select checks more fields for this or that and gets more
complicated so I'd like to keep this as simple
as possible. I would like to do this without UNIONS (in one pass) if
possible (my
dbsql.php doesn't seem to go beyond regular query).



Try "in":

where productx in (Prod1, Prod2, Prod3)





THANKS. You saved me another day of frustration trying UNION! :-)

In addition your answer also got me here:
http://dev.mysql.com/doc/refman/4.1/en/comparison-operators.html

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] WHERE field = a range of values (value

2011-05-24 Thread Richard S. Crawford
On Tue, May 24, 2011 at 6:51 AM, Paul S  wrote:

> I'd like to check a table to retrieve rows for which one field equals one
> of a set of values
>
> 
> #get products(fields) in category list
>while ($row = $db_connect->fetch_array($productsincategory_list)) {
>   $product = $row ['selection'];
>   $fields = "$fields" . " $product,";
>}
>$fields = substr($fields,'',-1);
>
> ## echo "$fields";
> ## $fields = Prod1, ProD2, Prod3
>
> This ...
>
> $db_connect->fetch_array($sql_result);
>
> $store_result = $db_connect->query("select * from $sql_usertable WHERE
> (($sql_usertable.product1 = '($fields)')||( $sql_usertable.product2 =
> '($fields)')||($sql_usertable.product3 = '($fields)')) order by id desc
> limit $entry, $entries_per_page");
>
> doesn't work. It selects nothing (obviously because no single field equals
> ' (Prod1, Prod2, Prod3) '). But it's the idea. Can I change the:
>
> = '($fields)'
>
> syntax I'm trying?
>
> The actual select checks more fields for this or that and gets more
> complicated so I'd like to keep this as simple
> as possible. I would like to do this without UNIONS (in one pass) if
> possible (my
> dbsql.php doesn't seem to go beyond regular query).
>

Try "in":

where productx in (Prod1, Prod2, Prod3)



-- 
Sláinte,
Richard S. Crawford (rich...@underpope.com)
http://www.underpope.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)


[PHP] WHERE field = a range of values (value

2011-05-24 Thread Paul S

I'd like to check a table to retrieve rows for which one field equals one
of a set of values


#get products(fields) in category list
while ($row = $db_connect->fetch_array($productsincategory_list)) {
   $product = $row ['selection'];
   $fields = "$fields" . " $product,";
}
$fields = substr($fields,'',-1);

## echo "$fields";
## $fields = Prod1, ProD2, Prod3

This ...

$db_connect->fetch_array($sql_result);

$store_result = $db_connect->query("select * from $sql_usertable WHERE
(($sql_usertable.product1 = '($fields)')||( $sql_usertable.product2 =
'($fields)')||($sql_usertable.product3 = '($fields)')) order by id desc
limit $entry, $entries_per_page");

doesn't work. It selects nothing (obviously because no single field equals
' (Prod1, Prod2, Prod3) '). But it's the idea. Can I change the:

= '($fields)'

syntax I'm trying?

The actual select checks more fields for this or that and gets more  
complicated so I'd like to keep this as simple
as possible. I would like to do this without UNIONS (in one pass) if  
possible (my

dbsql.php doesn't seem to go beyond regular query).




--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strcmp()?

2011-05-24 Thread Vitalii Demianets
On Monday 23 May 2011 15:00:27 tedd wrote:
> >Are you absolutely certain about that?
> >
> >    echo strcmp('These are nearly equal', 'These are almost equal'), "\n";
> >    echo strcmp('different', 'unequal'), "\n";
> >    echo strcmp('b', 'a'), "\n";

My result is:
13 -17 1

I'm runninng PHP 5.2.14 on the ARM Linux with uClibc.
Certainly the result depends on architecture and/or libc, because PHP just 
calls system strcmp, nothing more.
So. to write compatible scripts one should check "< 0", not "== -1".

-- 
With Best Regards,
Vitalii Demianets
Head engineer
Factor-SPE
Kiev, Ukraine
tel/fax: +380(44)249-21-63

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php