This is my code. I'm unable to execute it.
This is the error message I get on the $db->execute(); line:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'
$query = "UPDATE gateway_devices "
."SET coin_lat=:coin_lat, coin_lng=:coin_lng"
."WHERE nick_name=:nick_name AND gateway_id=:g_id AND device_id=:d_id";
$db->query($query);
$db->bind(':coin_lat', $coin_lat);
$db->bind(':coin_lng', $coin_lng);
$db->bind(':nick_name', $nick_name);
$db->bind(':g_id', $g_id);
$db->bind(':d_id', $d_id);
$db->execute();
all i had to do was add a space on line 2 before closing the double quote.
this is how the query looks like before and after adding the whitespace.
before - "UPDATE gateway_devices SET coin_lat=:coin_lat, coin_lng=:coin_lngWHERE nick_name=:nick_name AND gateway_id=:g_id AND device_id=:d_id"
after - "UPDATE gateway_devices SET coin_lat=:coin_lat, coin_lng=:coin_lng WHERE nick_name=:nick_name AND gateway_id=:g_id AND device_id=:d_id"
Related
I have a long Perl script that in other places returns MySQL table data successfully using binds:
$query2 = "SELECT tblExportFiles.CompID, CompEmail, export_id, export_name, query, num_records, sample_rate, record_startnum, Description, Pull_Type, remote_CompID FROM tblExportFiles INNER JOIN tblCustomers USING(CompID) WHERE done=0 ORDER BY export_id ASC ;";
$sqlQuery2 = $dbh->prepare( $query2 );
$sqlQuery2->execute or die "can't execute the query: " . $sqlQuery2->errstr;
$sqlQuery2->bind_columns(
\$CompID, \$CompEmail, \$export_id, \$fileName,
\$queryFile, \$numRecords, \$sampleRate, \$recStartNum,
\$description, \$qType, \$remote_CompID
);
while ( $sqlQuery2->fetch ) { ... }
But when I do the same sort of query here, it fails to return any values but doesn't throw an error:
my $ftpQuerySQL = "SELECT tblResellersData.http_address ,ftp_address, ftp_username, ftp_password, ftp_dir, http_name, tblResellerCustomers.CompEmail FROM tblResellersData, tblResellerCustomers WHERE tblResellerCustomers.User_ID = '$remote_CompID' AND tblResellersData.CompID = '$CompID' ; ";
print "FTP SQL = $ftpQuerySQL\n\n";
$QueryFTP = $dbh->prepare( $ftpQuerySQL );
$QueryFTP->execute() or die "can't execute the query: " . $QueryFTP->errstr;
$QueryFTP->bind_columns(
\$http_address, \$ftp_address, \$ftp_username, \$ftp_password,
\$ftp_dir, \$remote_name, \$CompEmail
);
$QueryFTP->fetch();
It throws warnings
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 302.
Use of uninitialized value $ftp_dir in concatenation (.) or string at ./Cron_file_output.pl line 302.
Use of uninitialized value $ftp_username in concatenation (.) or string at ./Cron_file_output.pl line 302.
is a located in
Use of uninitialized value $ftp_dir in scalar chomp at ./Cron_file_output.pl line 303.
Use of uninitialized value $http_address in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_username in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_password in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_dir in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $remote_name in concatenation (.) or string at ./Cron_file_output.pl line 304.
RETURNED VALUES......., , , , , , j#adki87.com
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 310.
But when I ran the same SQL under phpMyAdmin, it gave this result:
http_address website's url ftp_address ftp_username ftp_password ftp_dir http_name
http://www.highpeaksbyway.com/ highpeaksbyway.com data#highpeaksbyway.com dataUUU666##) pulls/ TEST ME
What are lines 302, 304, and 310?
It looks like your criteria (the WHERE conditions) are failing, and the statement returns no records
What does $QueryFTP->fetch return? You need to check its status before you use it. That is the major difference between the code that you think "works" and your problem case
You need to check the values of $CompID and $remote_CompID before the execute. You should also use placeholders in the prepare call, and supply the values in execute
I'm getting the error in my code. I'm sure this means there is something wrong with the column=:variable section of my code, but I've gone over it and can't see what's wrong.
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in F:\...
Here is the code (long first line):
$stmt = $dbh->prepare("UPDATE item_list SET quantity=:quantity, new_price=:newprice, image_link=:image_link, market_hash_name=:markethashname, last_update='1000-01-01 00:00:00', is_tradable='TEST', old_price=:oldprice WHERE item_name=:itemname AND (image_link IS NULL OR quantity IS NULL OR new_price IS NULL OR market_hash_name IS NULL OR last_update IS NULL OR is_tradable IS NULL OR old_price IS NULL)");
$sql->bindParam(':quantity', $json2->quantity);
$sql->bindParam(':newprice', $json2->lowest_price);
$sql->bindParam('image_link', $image_link_full);
$sql->bindParam(':markethashname', urlencode($mydata->market_hash_name));
$sql->bindParam(':oldprice', $json2->lowest_price);
$stmt->bindValue(':itemname', $mydata->market_name);
$stmt->execute();
EDIT: image_link needed to be :image_link, still getting the same error
EDIT 2: Had a lot wrong, was using two names $sql and $stmt, using bindValue instead of bindParam
you are missing a colon ':' before the 'image_link' in the bindParam statement.
I'm trying to create a procedure from the MySQL API in C. My query string is as follows (in the C code):
"CREATE PROCEDURE clockOut (taskID INT UNSIGNED) "
"BEGIN "
"DECLARE #username VARCHAR(8);"
"SELECT #username = userID FROM TaskItem WHERE id=taskID;"
"UPDATE TaskItem SET onClock=0,stopTime=NOW() "
"WHERE id=taskID AND userID=#username;"
"END"
This string will ultimately be transmitted with mysql_query(), which returns error code 1064, a syntax error. What have I done wrong?
As #alk suggested, I removed the # syntax from my variables, and it worked fine.
I try to capture lines with calculations in my text document
and execute them.
I use this in my function:
for i in range(startline,endline)
let calculation = getline(i)
...
let out = eval(calculation)
...
endfor
sometimes something goes wrong and I receive this message:
Error detected while processing function....
Line ...
E488: Trailing Characters
Line .. is the line-nr in my function.
I would like to know also which calculation it concerns (which line in my text doc):
If Error detected = echo calculation
How can I check if there is an error message and echo the variable "calculation"?
There are two ways to handle script errors inside a function:
The first is suppressing the error via :silent!. Two downsides: You have to manually check for success, and any normal output from the evaluated script is suppressed, too (unless you do contortions with :unsilent).
let v:errmsg = ''
silent! let out = eval(calculation)
if v:errmsg != ''
" error
endif
I would recommend the second way via try...catch, which avoids the issues with the output and having to explicitly check for an error:
try
let out = eval(calculation)
catch /^Vim\%((\a\+)\)\=:E/
" v:exception contains what is normally in v:errmsg, but with extra
" exception source info prepended, which we cut away.
let v:errmsg = printf("Line: %d\nCalculation: %s\nError: %s", i, calculation, substitute(v:exception, '^Vim\%((\a\+)\)\=:', '', ''))
echohl ErrorMsg
echomsg v:errmsg
echohl None
endtry
error ::
System.Data.SqlClient.SqlException:
Incorrect syntax near '='.
source code :
cn.Open();
Line 27: cmd = new SqlCommand("updat product set status ='" + s + "'", cn);
Line 28: cmd.ExecuteNonQuery();
Line 29: cn.Close();
Line 30: }
You realize you spelled update wrong?
Does s possibly have any apostrophe's in it's value? If so, you need to escape them, i.e., s.Replace("'", "''") (or better yet, use parameterized queries)
You have a possible SQL Injection vulnerability.
Are you sure you intend to update all of the products in the entire table?