I'm running Kohana stable release 3.2.0, just downloaded.
My database configuration is done and bootstrap contains orm and database modules enabled. So is my model created.
My request looks like this:
$user = ORM::factory('user',$post)->find();
if($user->count_all()){
echo '<pre>';
print_r($user);
echo '</pre>';
}
Basically it should return some data, but it gives me an error.
Database_Exception [ 1103 ]: Incorrect table name '' [ SELECT COUNT(*) AS `records_found` FROM `` ]
Is this normal, that it displays empty table?
If I update configuration with table prefix, it displays prefix, but does not show table.
If I update model with protected variable $table_name='user'; it still does not see it.
$user = ORM::factory('user',$post)->find();
if($user->loaded()){
echo '<pre>';
print_r($user);
echo '</pre>';
}
Use loaded() method to check that user was successfully loaded from DB.
Related
I am in a group project with three other members where we are trying to connect to an API, store the data from that API into a shared database, and display it on a web page by accessing our code file through a server. For our project, we are connecting to four different music streaming API's, mine being Spotify. Individually, we wrote our own code in Python to connect to each of our API's and extract data to be stored in our own database. In my code, I searched the name of a particular musician, and when running the code, I connected to Spotify's API and received an output of that musician's top 20 tracks. Those 20 tracks were stored in a table in my own database in MySQL Workbench, with the columns 'tracks' and 'items'.
Now, each of my members and I have our data tables for our individual API's stored into one shared database in MySQLHosting.net. Currently, my group is struggling to print and display the data from each of our tables onto a web page. I have written a PHP file attempting to display my table for Spotify's data, and I saved the file on my server and ran chmod 755, but when I search for my PHP file in the browser, I am left with a
403 Error ("Forbidden: You don't have permission to access this
resource").
Can anyone help me figure out if it is an error in my code, or if I need to run a different chmod command? Below is the code I used to display my data.
<!DOCTYPE html>
<html>
<body>
<?php
$servername = "sql5.freemysqlhosting.net";
$username = "[removed for question]";
$password = "[removed for question]";
$dbname = "[removed for question]";
$port = "[removed for question]";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $port);
$mysqli = mysqli_connect($servername, $username, $password, $dbname, $port);
if (!$mysqli)
{
echo 'Connection failed<br>';
echo 'Error number: ' . mysqli_connect_errno() . '<br>';
echo 'Error message: ' . mysqli_connect_error() . '<br>';
die();
}
echo 'Successfully connected!<br>';
$sql = "SELECT tracks, items FROM spotify";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo "tracks: " . $row["tracks"]. "<br>" . "items: " . $row["items"]. "<br>";
}
}
else
{
echo "0 results";
}
$conn->close();
?>
</body>
</html>
I have a custom table with serial numbers in WordPress. I have successfully got the serial number to appear on both Order received page after testing with Stripe:
https://prnt.sc/9tz8i3BW7lJR
and it also appears on WooCommerce Admin Orders Page:
https://prnt.sc/jLyb5CQqSAH5
I am using the woocommerce_email_before_order_table action. (on customer_completed_order)
I have the code below and I have echoed the Order ID and the Custom TableName and they BOTH appear in the Thanks for shopping with us email.
It seems the $license query returns nothing and I just can't see why it won't appear.
If I exchange the $woo_order_id for the previous order no, like EMS-0051 the serial number appears.
Is this query too early and it hasn't been populated in the custom table before the query is run?
I cannot get it to work..can anyone see what I have done wrong, please?
The Thanks email and CODE are below.
https://prnt.sc/38wa50jTyr3U
<?php
add_action( 'woocommerce_email_before_order_table', 'add_serial_to_email', 25, 4 );
function add_serial_to_email( $order, $sent_to_admin, $plain_text, $email ) {
global $wpdb;
$ipn_tables = $wpdb->prefix ."ipn_data_tbl";
///////BELOW is using 'seq Order No' plugin..this checks if WOO O/N or plugins O/N.
if (empty($order->get_id)) {
$woo_order_id = $order->get_order_number();
}
elseif (empty($order->get_order_number)) {
$woo_order_id = $order->get_id();
}
///check order ID and Table name are there:
if (!empty($woo_order_id && $ipn_tables )) {
echo '<b>ORDER ID:</b> '.$woo_order_id.'<br>'; // echos the Order ID - appears on "Thanks for shopping with us" email
echo '<b>TABLE NAME:</b> '.$ipn_tables.'<br>'; // echo my Custom table name - appears on "Thanks for shopping with us" email
////But the below $license variable doesn't. I think it's a timing thing.
//$license = $wpdb->get_var(" SELECT serial_no FROM $ipn_tables WHERE woo_order_id = $woo_order_id " );
$license = $wpdb->get_var( $wpdb->prepare( "SELECT * FROM {$ipn_tables} WHERE woo_order_id = %s", $woo_order_id ) );
}
if ( $email->id == 'customer_completed_order' ){
printf( '<p class="custom-text">' .__( 'Your Software Serial Number: '.'<span style="color:red;font-weight:bold;font-size:15px">'.$license ));
}
}//function-END
?>
Forgot to show the MyPHPAdmin table:
https://prnt.sc/A4DH1v2STWrL
edit:
I should have mentioned that I put that license check for orderID and table just to see if it was being checked..it appears my get_var query isn't working (empty?) but that same query is used in the other PHP pages I edited.
Looks like I found the issue. It was the fact that 'woocommerce_payment_complete' hook
was too early BUT the hook 'woocommerce_pre_payment_complete' is called first after payment is made but before order status change and before the email is sent. :)
So all I changed in the add_action was change:
woocommerce_payment_complete' TO woocommerce_pre_payment_complete that's it.
And it worked.
part of the add_action updated code
I'm trying to implement Stripe Checkout into my website. I am using Composer, everything seems to go right, but when I add my private key into init.php line 17:
Stripe::setApiKey($stripe['private']);
PHP shows me the following error:
Fatal error: Class 'Stripe' not found in/Applications/MAMP/htdocs/stripe_payment/app/init.php on line 17
Here is the full file:
<?php
session_start();
//composer auto load
require_once 'vendor/autoload.php';
$_SESSION['user_id'] = 3;
$stripe = [
'publishable' => '..... my test key.....',
'private' => '..... my test key.....'
];
//when added brakes the code
Stripe::setApiKey($stripe['private']);
$db = new PDO('mysql:host=localhost;dbname=stripe_custom;','root','root');
$userQuery = $db->prepare("
SELECT id, username, email, premium
FROM users
WHERE id = :user_id
");
$userQuery->execute(['user_id' => $_SESSION['user_id']]);
$user = $userQuery->fetchObject();
?>
I presume that this is something small, but I'm a beginner and I can't figure it out. What am I doing wrong?
The latest releases of Stripe's PHP bindings (2.*) are now using Namespaces. This means that most of the API calls have now changed and for example:
Stripe::setApiKey("sk_test_XXX");
Stripe_Customer::create();
would become:
\Stripe\Stripe::setApiKey("sk_test_XXX");
\Stripe\Customer::create();
Otherwise, if you don't want to have to update your code you need to make sure that you download the legacy version (1.18.0).
I'm new to Couchdb just a few week back I git clone the couchdb app called sofa [what and app] . Over the week It was going great but suddenly today I stumble upon something.
Here what I meant
when I browse the Sofa app and try to create a Post without the title
it prompt with and alert box "The document could not be saved: The database could not be created, the file already exists." which was weird as looking at the source I found that the require (in validate_doc_update.js return its custom json error) something like in this format {"forbidden" : message }) with forbidden as key
v.forbidden = function(message) {
throw({forbidden : message})
};
v.require = function() {
for (var i=0; i < arguments.length; i++) {
var field = arguments[i];
message = "The '"+field+"' field is required.";
if (typeof newDoc[field] == "undefined") v.forbidden(message);
};
};
in validate_doc_update.js
if (newDoc.type == 'post') {
if (!v.isAuthor()) {
v.unauthorized("Only authors may edit posts.");
}
v.require("created_at", "author", "body", "format", "title");
inspecting the response state that the json returned was found to be different from the json had it would have been return by the above require function in validate_doc_update.js
here is the json
{"error":"file_exists","reason":"The database could not be created, the file already exists."}
This make be believe that the validation in validation_doc_update.js only execute during updating of document
to Prove this point I try to update a document without the title, expecting that it would return the error but surprisingly the document just got saved
so Here are my Question regarding all the Point I mention above
Does validate_doc_update.js "validate" work only during updation of document
if YES
then
how can I manage to succeed in updating a post without the error [Weird bypassing the Validation Completely] . + How can execute validation on create of a document
if NO
then
What is the Error {"error":"file_exists","reason":"The database could not be created, the file already exists."} that is prevent a document to be saved
Can anyone please share light on all the questions listed here
Yes, the validate_doc_update functions are run only when updating documents (include creation and deletion).
The function you show here will allow a document without a title as long as its type is not "post". If you could include the actual request you attempted, I could confirm it.
Finally, the ""The database could not be created" is because you are attempting to create the database (by doing PUT /dbname/ instead of PUT /dbname/docid, I would guess) when it already exists. Again, if you would include the actual request, I could confirm that too.
I'm working with MODx revo. I wrote a snippet called putBoxId with the following content:
<?php
$id = isset($_GET['id']) ? $_GET['id'] : null;
if (!is_null($id)) {
return $modx->getChunk($tpl, array('id' => $id));
}
return '';
I use it like this: [[~3[[!putBoxId? &tpl='boxIdUrl']] ]] (with backticks, of course), where boxIdUrl is the chunk with the following content:
? &id=`[[+id]]`
The problem is, for some reason it gets cached. I tried putting '!' In all combinations, still gets cached. How can this be fixed?
The [[~3 is being cached, so your putBoxId is actually called only the first time.
In Revo - any *[[* (tag) can start with a ! (non-cacheable flag). So, in your case - [[!~3[[!putBoxId? &tpl='boxIdUrl']] ]] (note: there's a typo here and in your original question, see comment below. this should work: [[~3]][[!putBoxId? &tpl='boxIdUrl']])
more info here
Even better - unless there's a good reason, get rid of that chunk, as the $modx->getChunk call wouldn't be cached in your scenario (goes to db to get template, etc...).
Do it all in the snippet itself using modx->makeUrl (see link for more options)
<?php
$resourceId = $modx->getOption('resourceId', $properties, $modx->resource->get('id')); // get resourceId from snippet, default to current
$args = (!empty($_REQUEST['id']))? array('id'=>$_REQUEST['id']) : '';
return $modx->makeUrl($resourceId, '', $args);
Call like this:
[[!putBoxId]] or [[!putBoxId? &resourceId=`3`]]