Why Do I Get Function Errors In My Script? - function

I watched a YouTube video on how to make a donate button in Roblox and followed the steps. But then when I used it, it gave me multiple errors.
I have tried changing .connect to :Connect but it gave me more errors, I tried changing end) to end, but it gave me more errors.
Code:
local id = 459818680
script.Parent.TextButton.MouseButton1Click.connect()(function()
game:GetService("MarketplaceService"):PromptProductPurchase
(game.Players.LocalPlayer, id)
end)
I expected to be able to click on it when I tested it and a menu for a purchase would pop up. Nothing happened. I also got errors like this:
Players.ImNotKevPlayz.PlayerGui.ScreenGui.LocalScript:4: bad argument #1 to 'connect' (RBXScriptSignal expected, got no value)
When I tried the debug command in Roblox commands, it gave me this error:
Error in script: '=' expected near ''

Heyo, your script almost works, it just looks like you've just got some syntax errors.
bad argument #1 to 'connect' (RBXScriptSignal expected, got no value)
This means that the MouseButton1:Connect function was expecting an argument, but you didn't give it anything.
Try out this fix :
local id = 459818680
local targetButton = script.Parent.TextButton
local MarketplaceService = game:GetService("MarketplaceService")
targetButton.MouseButton1Click:Connect(function() -- <-- this just needed to be fixed
local player = game.Players.LocalPlayer
MarketplaceService:PromptProductPurchase(player, id)
end)

Related

How to display, why mysql query not working? [duplicate]

This is my PHP SQL statement and it's returning false while var dumping
$sql = $dbh->prepare('INSERT INTO users(full_name, e_mail, username, password) VALUES (:fullname, :email, :username, :password)');
$result = $sql->execute(array(
':fullname' => $_GET['fullname'],
':email' => $_GET['email'],
':username' => $_GET['username'],
':password' => $password_hash));
TL;DR
Always have set PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION in your PDO connection code. It will let the database tell you what the actual problem is, be it with query, server, database or whatever. Also, make sure you can see PHP errors in general.
Always replace every PHP variable in the SQL query with a question mark, and execute the query using prepared statement. It will help to avoid syntax errors of all sorts.
Explanation
Sometimes your PDO code produces an error like Call to a member function execute() or similar. Or even without any error but the query doesn't work all the same. It means that your query failed to execute.
Every time a query fails, MySQL has an error message that explains the reason. Unfortunately, by default such errors are not transferred to PHP, and all you have is a silence or a cryptic error message mentioned above. Hence it is very important to configure PHP and PDO to report you MySQL errors. And once you get the error message, it will be a no-brainer to fix the issue.
In order to get the detailed information about the problem, either put the following line in your code right after connect
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
(where $dbh is the name of your PDO instance variable) or - better - add this parameter as a connection option. After that all database errors will be translated into PDO exceptions which, if left alone, would act just as regular PHP errors.
After getting the error message, you have to read and comprehend it. It sounds too obvious, but learners often overlook the meaning of the error message. Yet most of time it explains the problem pretty straightforward:
Say, if it says that a particular table doesn't exist, you have to check spelling, typos, letter case. Also you have to make sure that your PHP script connects to a correct database
Or, if it says there is an error in the SQL syntax, then you have to examine your SQL. And the problem spot is right before the query part cited in the error message.
You have to also trust the error message. If it says that number of tokens doesn't match the number of bound variables then it is so. Same goes for absent tables or columns. Given the choice, whether it's your own mistake or the error message is wrong, always stick to the former. Again it sounds condescending, but hundreds of questions on this very site prove this advice extremely useful.
Note that in order to see PDO errors, you have to be able to see PHP errors in general. To do so, you have to configure PHP depends on the site environment:
on a development server it is very handy to have errors right on the screen, for which displaying errors have to be turned on:
error_reporting(E_ALL);
ini_set('display_errors',1);
while on a live site, all errors have to be logged, but never shown to the client. For this, configure PHP this way:
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
Note that error_reporting should be set to E_ALL all the time.
Also note that despite the common delusion, no try-catch have to be used for the error reporting. PHP will report you PDO errors already, and in a way better form. An uncaught exception is very good for development, yet if you want to show a customized error page, still don't use try catch for this, but just set a custom error handler. In a nutshell, you don't have to treat PDO errors as something special but regard them as any other error in your code.
P.S.
Sometimes there is no error but no results either. Then it means, there is no data to match your criteria. So you have to admit this fact, even if you can swear the data and the criteria are all right. They are not. You have to check them again. I've short answer that would help you to pinpoint the matching issue, Having issue with matching rows in the database using PDO. Just follow this instruction, and the linked tutorial step by step and either have your problem solved or have an answerable question for Stack Overflow.
Some time ago I had the same problem of not seeing any error messages from mysql. After a research it turned out that the problem has got nothing to do with PHP itself, but with mysql server configuration. The default value of the variable lc_messages_dir pointed to non existing directory. After adding a line in mysqld.cnf, then restarted the mysql server, and finally I was able to see the error messages. For me the following was the right one:
lc_messages_dir=/usr/share/mysql
It is described in the mysql reference manual: https://dev.mysql.com/doc/refman/5.7/en/error-message-language.html

Node.js -> MySQL wont execute JOIN command

I cant seem to get MySQL to spit out the information from my database, I have entered the same query through command line as well as phpmyadmin and the both execute fine, only when I attempt to run it through node server it sends me the error below,
ER_BAD_FIELD_ERROR: Unknown column 'Meetings.user' in 'field list'
This is the code I am running,
var options = {sql:'SELECT users.username, `Meetings`.`user` FROM Meetings INNER JOIN users on `Meetings`.`user` = users.id', nestTables:true};
pool.query(options, function(err, rows) {
if (err) {
console.log(module_name + err)//Debugging purposes
}else{
console.log(rows);//Debugging purposes
}
})
I have tried playing around with the quotes using many variations although I either receive an empty object or an error message.
I have read the documentation available for this module, but have still had no luck.
mysql-Doc
I don't no if i'm missing something or just doing it completely wrong, either way help would be much appreciated, thank you in advanced.
Note: all my other queries work fine, only the JOIN query seems to be giving me issues.

ModX getResource stopped working

I can't get a result with getResource anymore.
For example, I want to query my blog posts:
My articles are created with the Articles plugin.
In my template, I have:
[[!getResources:ifempty=`No Resource`? &parents=`33` &showHidden=`1` ]]
It simply shows "No Resource".
Without the ifempty tag, it simply doesn't show anything.
The weird thing is I know I have those articles in my database. When I try with the parameter debug=true, I see the article objects' dump in place of the template. So the query is working fine, getResource retrieves the articles when debug is set to true!
With debug, I can see the SQL query in my log file:
[2014-02-10 16:58:37] (ERROR # /huayang/index.php) context for 33 is
web
[2014-02-10 16:58:37] (ERROR # /huayang/index.php) SELECT modResource.id, modResource.type, modResource.contentType,
modResource.pagetitle, modResource.longtitle,
modResource.description, modResource.alias,
modResource.link_attributes, modResource.published,
modResource.pub_date, modResource.unpub_date,
modResource.parent, modResource.isfolder,
modResource.introtext, modResource.richtext,
modResource.template, modResource.menuindex,
modResource.searchable, modResource.cacheable,
modResource.createdby, modResource.createdon,
modResource.editedby, modResource.editedon,
modResource.deleted, modResource.deletedon,
modResource.deletedby, modResource.publishedon,
modResource.publishedby, modResource.menutitle,
modResource.donthit, modResource.privateweb,
modResource.privatemgr, modResource.content_dispo,
modResource.hidemenu, modResource.class_key,
modResource.context_key, modResource.content_type,
modResource.uri, modResource.uri_override,
modResource.hide_children_in_tree, modResource.show_in_tree,
modResource.properties FROM modx_site_content AS modResource
WHERE ( modResource.parent IN (33,34,35,36) AND
modResource.deleted = 0 AND modResource.published = 1 ) ORDER
BY publishedon DESC LIMIT 5
When I run this query directly in phpmyadmin, I get the articles!
To be clear, getResource simply won't work whatever the query I try to make, if debug isn't set to true. It won't show my any error at any point..
I have already uninstalled and reinstalled the plugin.
So.. any idea how I can fix this? Any suggestion how I should proceed to debug this?
Edit: getresources-1.6.1-pl
Edit2:
Started debugging, snippet.getresources.php, line 430
$collection = $modx->getCollection('modResource', $criteria, $dbCacheFlag);
$collection is an empt array..
$criteria is a xPDOQuery_mysql Object which looks correct..
I'm gonna sleep through this and will reinstall ModX tomorrow if I can't fix this
The issue was that my template was in Templates instead of Chunks, the snippet started working again after I moved articlePreview into Chunks.
Some kind of output would have helped..
Hope this can help someone.

preventing a specific mysqli_fetch_assoc() from sending a warning

I use a specific query that is acting weird: On my local environment, it works perfect and sends no warning. Online, the query itself works fine, however, mysqli_fetch_assoc($result) is producing the 'mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given' warning.
I never occured a query that was causing this warning AND got the right info from the DB. This is why I tend to believe the problem is not in the code.
Is there a way to shut off the warnings only for this one specific query?
EDIT -
PROBLEM SOLVED.
it is really strange to me, but the problem was an incorrect script src path for dojo.js.
I have no idea what's the connection, but fixing the path prevented mysqli warnings.
You should be checking if $result == false before you call mysqli_fetch_assoc. Generally you catch it first by checking mysqli_connect_errno() but the general idiom is to proactively check before fetching rows

MySQL / SQLite3

I stumbled upon the following:
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
bargain_id = 0
total_price = Decimal(0)
for instance in instances:
if isinstance(instance, BargainProduct):
total_price += instance.quantity * instance.product.price
bargain_id = instance.id
instance.save()
updateTotal = Bargain.objects.get(id=bargain_id)
updateTotal.total_price = total_price - updateTotal.discount_price
updateTotal.save()
This code is working for me on my local MySQL setup, however, on my live test enviroment running on SQLite3* I get the "Bargain matching query does not exist." error..
I am figuring this is due to a different hierarchy of saving the instances on SQLite.. however it seems they run(and should) act the same..?
*I cannot recompile MySQL with python support on my liveserver atm so thats a no go
Looking at the code, if you have no instances coming out of the formset.save(), bargain_id will be 0 when it gets down to the Bargain.objects.get(id=bargain_id) line, since it will skip over the for loop. If it is 0, I'm guessing it will fail with the error you are seeing.
You might want to check to see if the values are getting stored correctly in the database during your formset.save() and it is returning something back to instances.
This line is giving the error:
updateTotal = Bargain.objects.get(id=bargain_id)
which most probably is because of this line:
instances = formset.save(commit=False)
Did you define a save() method for the formset? Because it doesn't seen to have one built-in. You save it by accessing what formset.cleaned_data returns as the django docs say.
edit: I correct myself, it actually has a save() method based on this page.
I've been looking at this same issue. It is saving the data to the database, and the formset is filled. The problem is that the save on instances = formset.save(commit=False) doesn't return a value. When I look at the built-in save method, it should give back the saved data.
Another weird thing about this, is that it seems to work on my friends MySQL backend, but not on his SQLITE3 backend. Next to that it doesn't work on my MySQL backend.
Local loop returns these print outs (on MySQL).. on sqlite3 it fails with a does not excist on the query
('Formset: ', <django.forms.formsets.BargainProductFormFormSet object at 0x101fe3790>)
('Instances: ', [<BargainProduct: BargainProduct object>])
[18/Apr/2011 14:46:20] "POST /admin/shop/deal/add/ HTTP/1.1" 302 0