Re: Empty Array?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I would advise against using intval if the sql data type is anything greater and/or equal to "int unsigned". PHP on 32 bit systems: intval can only handle values up to 2147483647. sql unsigned int can go up to |4294967295 and bigints even higher....

This could cause serious problems ...

Marek
|
Aleksandar Vojnovic wrote:
$request_id = $_GET['id']; <--- I suppose this would be an int. True? If so then add:

<?php
$request_id = intval($_GET['id']);
?>

Aleksandar

marek wrote:
Even better:

<?php
$request_id = $_GET['id'];
$current_user = substr($_SERVER['AUTH_USER'], 13);

$lock_query = "SELECT id, locked_by_user FROM locked_payments WHERE id =
'$request_id'";
$lock_result = mssql_query($lock_query) or die(mssql_get_last_message());
$lock_row = mssql_fetch_array($lock_result);

if (empty($lock_row)) {
$lock_id = $lock_row['id'];
$lock_user = $lock_row['locked_by_user'];
$set_lock = "INSERT into locked_payments (
    id,
    locked_by_user)
    VALUES
     ('$request_id',
    '$current_user')";
mssql_query($set_lock) or die ("Query failed: <br
/>".mssql_get_last_message());
}
?>



Dan Shirah wrote:
Okay, gotcha!

I changed it to this and it works:


<?php
$request_id = $_GET['id'];
$current_user = substr($_SERVER['AUTH_USER'], 13);

$lock_query = "SELECT id, locked_by_user FROM locked_payments WHERE id =
'$request_id'";
$lock_result = mssql_query($lock_query) or die(mssql_get_last_message());
$lock_row = mssql_fetch_array($lock_result);
$lock_id = $lock_row['id'];
$lock_user = $lock_row['locked_by_user'];

if (empty($lock_row)) {
 $set_lock = "INSERT into locked_payments (
     id,
     locked_by_user)
     VALUES
      ('$request_id',
     '$current_user')";
 mssql_query($set_lock) or die ("Query failed: <br
/>".mssql_get_last_message());
 }
?>

Thanks! :)
On 10/5/07, Aleksandar Vojnovic <muadib@xxxxxxxxxxxxxx> wrote:
I think the $lock_result is just a resource #id you haven't fetched any
data yet. True?

Aleksander

Dan Shirah wrote:
Ah, what a lovely case of the Friday morning brain farts!

I have a query that selects some data from a table based on the current
ID
selected.

If the query does not return any results, I want it to continue to
another
query that will insert a record into the table.

Below is what I have...but it will not insert anything if the first
query
does not find a match.


<?php
$request_id = $_GET['id'];
$current_user = substr($_SERVER['AUTH_USER'], 13);

$lock_query = "SELECT id, locked_by_user FROM locked_payments WHERE id =
'$request_id'";
$lock_result = mssql_query($lock_query) or
die(mssql_get_last_message());
if (empty($lock_result)) {
 $set_lock = "INSERT into locked_payments (
     id,
     locked_by_user)
     VALUES
      ('$request_id',
     '$current_user')";
 mssql_query($set_lock) or die ("Insert failed: <br
/>".mssql_get_last_message());
 }
?>



Any ideas on what I'm doing wrong?  My guess is that
(empty($lock_result))
is probably not the correct way to check if an array is empty?








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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux