Jump to content

cornacum

Members
  • Posts

    12
  • Joined

  • Last visited

cornacum's Achievements

Member

Member (2/5)

0

Reputation

  1. I wasn't aware that you can create unique index with multiple columns. Thank you Barand
  2. The table has 3 columns. No there are no constraints on user_id and timestamp, so I assume insert ignore will not work. id - primary, unique user_id timestamp Is there any other way around this? The only thing I can think of is, before I run Insert Query, run "SELECT * from table_name WHERE user_id = user_id AND timestamp = timestamp", if I get row count > 0, there is a duplicate and do not insert ?
  3. @Barand I provided poor example. It will be user ID and timestamp. They will not be unique fields.
  4. Hi I need to insert the data in the database but on the condition that the values of two columns combined do not already exist in the table? Is it possible to use inset ignore for this? example Current data in the table for id and timestamp. id | timestamp 57 | 2023-08-15 09:07:13 It should not be possible to insert again the same values combined; 57 | 2023-08-15 09:07:13 But it should be fine to insert: 58 | 2023-08-15 09:07:13 57 | 2023-08-16 09:07:13 etc. If that makes sense?
  5. I am running a php curl postman API in a procedural php script curl_setopt_array($curl, array( CURLOPT_URL => API_SERVER.'/url/SaveUser', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{"user":"user01","name":"John Doe","card":"0","password":"","privilege":"14","deviceSerial":"xxxxxxxxxxx"}', CURLOPT_HTTPHEADER => array( API_TOKEN , 'Content-Type: text/plain' ), )); The post above works normally, but I need to POST a value into the CURLOPT_POSTFIELDS. I tried using variable name, but the value that is sent is the actual variable name, and not the value that the variable holds. $user_id = $_POST[user_id]; CURLOPT_POSTFIELDS =>'{"user":"$user_id","name":"John Doe","card":"0","password":"","privilege":"14","deviceSerial":"xxxxxxxxxxx"}', Can anyone please advise? Many Thanks
  6. Thank you for prompt response. I have just found that the postman platform provides code samples it self, which comes in very useful.
  7. Hi all I am pretty new to php and API, and would appreciate any help or at least if you can forward me in the right direction with this. I have a working php file and I need to request some data from API. The third part who is handling API, has sent me the following code... What I am looking for is a basic sample code to understand how to get the data. Any help is highly appreciated. { "info": { "_postman_id": "3699c117-da38-4c11-93fe-451bae0bf8e4", "name": "AClock", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "ListDevicesDB", "request": { "method": "GET", "header": [ { "key": "token", "type": "text", "value": "X1h36&YOoiKR" } ], "url": { "raw": "http://193.123.123.123:6600/iclock/ListDevicesDB", "protocol": "http", "host": [ "193", "123", "123", "123" ], "port": "6600", "path": [ "iclock", "ListDevicesDB" ], "query": [ { "key": "deviceSerial", "value": "BJ2C193661559", "disabled": true } ] }, "description": "it provides a list of all devices that connected to the server. it is sorted by the time each device connected to server last time.\r\nyou can pass the \"deviceSerial\" to find a specific device OR skip this parameter to list all devices." }, "response": [] },
  8. I will give that a try. Thank you all for helping out.
  9. This is the loop within a function that populates the array at the bottom then returns it. $users[$uid] at the end. while ( strlen($userdata) > 72 ) { $u = unpack( 'H144', substr( $userdata, 0, 72) ); //$uid = hexdec( substr($u[1], 0, 4) ).' '; $u1 = hexdec( substr($u[1], 2, 2) ); $u2 = hexdec( substr($u[1], 4, 2) ); $uid = $u1+($u2*256); $cardno = hexdec( substr($u[1], 78, 2).substr($u[1], 76, 2).substr($u[1], 74, 2).substr($u[1], 72, 2) ).' '; $role = hexdec( substr($u[1], 4, 4) ).' '; $password = hex2bin( substr( $u[1], 8, 16 ) ).' '; $name = hex2bin( substr( $u[1], 24, 74 ) ). ' '; $userid = hex2bin( substr( $u[1], 98, 72) ).' '; //Clean up some messy characters from the user name $password = explode( chr(0), $password, 2 ); $password = $password[0]; $userid = explode( chr(0), $userid, 2); $userid = $userid[0]; $name = explode(chr(0), $name, 3); $name = utf8_encode($name[0]); $cardno = str_pad($cardno,11,'0',STR_PAD_LEFT); if ( $name == "" ) $name = $uid; $users[$uid] = array($userid, $name, $cardno, $uid,intval( $role ), $password); $userdata = substr( $userdata, 72 ); } return $users; And this is the loop fetching the array. while(list($uid, $userdata) = each($user)): if ($userdata[2] == LEVEL_ADMIN) $role = 'ADMIN'; elseif ($userdata[2] == LEVEL_USER) $role = 'USER'; else $role = 'Unknown';
  10. Can you actually help me and rewrite this in foreach loop? I can't figure out what I am doing wrong. while(list($uid, $userdata) = each($user)): if ($userdata[2] == LEVEL_ADMIN) $role = 'ADMIN'; elseif ($userdata[2] == LEVEL_USER) $role = 'USER'; else $role = 'Unknown';
  11. Hi everyone Can someone help me to re-write in a loop that works in PHP 8. I tried it myself but wasn't able to make it work. This is the code: if ( is_array( $u ) ) { while( list( $key ) = each( $u ) ) { $u = $u[$key]; break; } } Thanks
×
×
  • 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.