Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Please i dont know how to remove this error on line 7 onto this $rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$timestamp = round(microtime(true) * 1000);
$login = ‘username’;
$password = ‘password’;
$hash = md5(md5($password).$timestamp);
$rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$post_data = array(
‘range’ => ‘LAST_7_DAYS’,
‘groupBy’ => ‘PLACEMENT’
);
/* Options of HTTP request; http key should be used when posting to https url */
$options = array(
‘http’ => array(
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
‘method’ => ‘POST’,
‘content’ => http_build_query($post_data)
)
);
/* Actual call to REST URL */
$context = stream_context_create($options);
$result = file_get_contents($rest_url, false, $context);
echo($result);
Your string starting and ending characters are incorrect.
You are using ‘ and “ ... replace them with ' and " to make your code valid.
since file_get_contents() is not reliable in remote connections,
You have to use CURL to overcome this http error.
For more info on curl_init read this
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I set the following PHP Code:
if($motherFirst == 'yes')
{$motherBool = true;}
else
{$motherBool = false;}
if($fatherFirst == 'no')
{$fatherBool = true;}
else
{$fatherBool = false;}
I have checked that I'm obtaining Yes or No as a value for both $motherFirst and $fatherFirst by doing an echo.
I am then using $motherBool and $fatherBool to post boolean (true or false) not as string in an API call.
However it appears that they are being assigned true or false of type string. What can I do to convert them to Boolean?
Above has been corrected, but now have issue with following:
I'm also sending the json as follows:
$data_string = '{
"motherData": false,
"fatherData": true
}';
Which works, but when I put as follows, it doesn't work:
$data_string = '{
"motherData": '.$motherBool.',
"fatherData": '.$fatherBool.'
}';
Can you let me know?
Already answered but here is a simplification.
$motherBool = ($motherFirst == 'yes');
$fatherBool = ($fatherFirst == 'no');
In your second question you're echoing a bool as if its a string which will print 0 or 1, not true/false as your expecting. You need to convert the bool to a string. for example,
$data_string = '{
"motherData": '.($motherBool ? 'true' : 'false').',
"fatherData": '.($fatherBool ? 'true' : 'false').'
}';
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Trying to follow the examples here, but it gives me
Fatal error: Uncaught Error: Call to undefined function sodium_randombytes_buf()
On top of that, the key pairs seems to be generating weird strings like:
kÿòjƒFDú{î—4]F◊߈u…®_•A∞+.
Is that normal?
Here's my code
<?php
// send
$message = 'Hi, this is Alice';
$alice_to_bob_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
file_get_contents('./keys/sec-user-1_box_key.txt'),
file_get_contents('./keys/pub-user-2_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$ciphertext = sodium_crypto_box(
$message,
$nonce,
$alice_to_bob_kp
);
// receive
$bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
// $bob_box_secretkey,
// $alice_box_publickey
file_get_contents('./keys/sec-user-2_box_key.txt'),
file_get_contents('./keys/pub-user-1_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$plaintext = sodium_crypto_box_open(
$ciphertext,
$nonce,
$bob_to_alice_kp
);
if ($plaintext === false) {
die("Malformed message or invalid MAC");
}
die($plaintext);
There is no such function as sodium_randombytes_buf() the code in the example uses \Sodium\randombytes_buf().
Edit:
From the bug history:
"The sodium_randombytes_* symbols have been removed a while back, as PHP now provide similar functions without this extension"
Bug #74896 sodium's .h defines some functions without .c implementation
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
i have little problem with inserting data to my database.
I get this error but i have no idea way. I have almost identical query on other script and it works fine but this one does not. I check the POST data on chrome inspector it shows fine.
if you have idea whats wrong with it, let me know.
Thanks in Advance.
$fact_total = (float)$_POST['precio'];
$fact_btax = (float)$_POST['precio_sin'];
$fact_tax = (float)$_POST['impuestos'];
$fact_name = e($_POST['fact_name']);
$fact_tipo = e($_POST['fact_serv']);
$fact_tax_rate = 21;
try{
$handler = $db->prepare('INSERT INTO fact_info
(id_client, cl_name, cl_last_name, cl_last_name_2, cl_email, cl_tel, cl_doc_type, cl_doc, cl_via, cl_street, cl_number, cl_level, cl_stairs, cl_door, cl_provincia, cl_city, cl_cod_postal, fact_urgencia, fact_name, fact_tipo, fact_total, fact_btax, fact_tax, fact_tax_rate, created ) VALUES (:id_client, :cl_name, :cl_last_name, :cl_last_name_2, :cl_email, :cl_tel, :cl_doc_type, :cl_doc, :cl_via, :cl_street, :cl_number, :cl_level, :cl_stairs, :cl_door, :cl_provincia, :cl_city, :cl_cod_postal, :fact_urgencia, :fact_name, :fact_tipo, :fact_total, :fact_btax, :fact_tax, :pres_tax_rate, NOW())');
$handler->execute(array(
':id_client' => $client_ids,
':cl_name' => e($_POST['fact_cl_name']),
':cl_last_name' => e($_POST['fact_lastname']),
':cl_last_name_2' => e($_POST['fact_lastname_2']),
':cl_email' => e($_POST['fact_email']),
':cl_tel' => e($_POST['fact_tel']),
':cl_doc_type' => e($_POST['fact_document_type']),
':cl_doc' => e($_POST['fact_document_number']),
':cl_via' => e($_POST['fact_dir_via']),
':cl_street' => e($_POST['fact_dir_calle']),
':cl_number' => (int)$_POST['fact_dir_number'],
':cl_level' => e($_POST['fact_dir_level']),
':cl_stairs' => e($_POST['fact_dir_stairs']),
':cl_door' => e($_POST['fact_dir_door']),
':cl_provincia' => e($_POST['fact_dir_provincia']),
':cl_city' => e($_POST['fact_dir_localidad']),
':cl_cod_postal' => (int)$_POST['fact_dir_cod_postal'],
':fact_urgencia' => '1',
':fact_name' => $fact_name,
':fact_tipo' => $fact_tipo,
':fact_total' => $fact_total,
':fact_btax' => $fact_btax,
':fact_tax' => $fact_tax,
':fact_tax_rate' => $fact_tax_rate
));
$fact_id = $db->lastInsertId();
foreach ($_POST['inv_desc'] as $key => $value) {
$handler4 = $db->prepare('INSERT INTO fact_content (id_fact, fact_desc, fact_qty, fact_price, fact_subtotal) VALUES (:id_fact, :fact_desc, :fact_qty, :fact_price, :fact_subtotal)');
$handler4->execute(array(
':id_fact' => $fact_id,
':fact_desc' => e($_POST['inv_desc'][$key]),
':fact_qty' => (float)$_POST['inv_qty'][$key],
':fact_price' => (float)$_POST['inv_precio'][$key],
':fact_subtotal' => (float)$_POST['inv_subtotal'][$key]
));
}
header('Location: fact_confirm.php?fact_id='.$fact_id.'');
exit();
I'll explain you why this error occurs.
SQLSTATE[HY093]: Invalid parameter number
This error basically occurs because of the following reasons.
Reason1
As the error name suggests, there is some difference between the number of parameters in your prepared query. What I mean is, take a look at the following example:
$s = $conn->prepare("INSERT INTO table(column1,column2) values(:column1)
$s->bindParam(':column1', $column1Value);
$s->bindParam(':column2', $column2Value);
Now, this will generate the error you mentioned because you're trying to insert into 2 columns, but are only providing value for 1.
Reason2
$s = $conn->prepare("INSERT INTO table(column1) values(:column1,:column2)
$s->bindParam(':column1', $column1Value);
$s->bindParam(':column2', $column2Value);
Now this would generate an error because you're trying to insert value into one column, but providing 2 values inside the VALUE section of the query.
Reason3
$s = $conn->prepare("INSERT INTO table(column1,column2) values(:column1,:column2)
$s->bindParam(':column1', $column1Value);
In this case, you've written the query part correct. However, you missed binding the parameters for the second value, the :column2.
These are the reasons why this error bumps up. Check your code and you'd find out what error out of these 3 you've made.
It appears that there is no :fact_tax_rate. Looks like a typo. Your last insert statement column inserts :pres_tax_rate.
Your first insert has the wrong variable name for the second to last value. Change :pres_tax_rate to :fact_tax_rate
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I declared one variables like this
echo $OPTIONS="500=>250.00, 1000=>500.00,2500=>1100.00,5000=>2250.00";
and
I got this variables through file_get_contents() functions.
$contents = file_get_contents(SERVICE_URL."options_config.php?options=".$OPTIONS);
$package=array($contents)
foreach($package as $pack=>$price)
{
echo $pack;
}
But I got 0 values. What is the problem?
print_r($package);
The result is :
Array ( [0] => 500=>250.00, 1000=>500.00,2500=>1100.00,5000=>2250.00 )
I want the result like this
500 as 250.00
1000 as 500.00
I think what you are looking for is serialize and unserialize
Example: test.php
<?php
// Handle Get Request
// This portion of your code can be on another file
//
if (isset($_GET['getOptions']))
{
$myOptions = array(
500 => 250.00,
1000 => 500.00,
2500 => 1100.00,
5000 => 2250.00
);
exit(serialize($myOptions));
}
// Sample Usage
$options = file_get_contents('http://localhost/test.php?getOptions');
$options = unserialize($options);
// Debug
var_dump($options);
?>
Outputs:
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Parse error: syntax error, unexpected T_IF, expecting ')'
What should I do?
$show_smileys = true;
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
if ($show_smileys == true) {
,'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
}
);
You can't include an if condition inside an array. Define the primary portion of your array like this:
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
);
And then use a condition to merge the rest:
if ($show_smileys == true) {
$smiles = array(
'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
);
$final = array_merge($find, $smiles);
}
You can't put if in the middle of an array, it can only be used where statements are allowed. Do it this way:
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
);
$smileys = array(
'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
);
if ($show_smileys) {
$find = array_merge($find, $smileys);
}