I Have 2 1064 SQL Errors And Can Not Figure Them Out - mysql-error-1064

This code worked good on ph 5.3. My server got upgraded to php5.6 and now the code no longer works.
Here is the two statements.
$sql = "UPDATE " . FORUM_TOUR_TABLE . "
SET page_subject = '$subject', page_text = '$message', page_access = $page_access
WHERE page_id = $id";
It says :
`SQL Error : 1064 Syntax error near 'WHERE page_id = 1' at line 3
UPDATE SET phpbb_forum_tour page_subject = ' Welcome To The Tower' , page_text = ' Update me please ' = WHERE page_access page_id = 1
Line : 172
File: admin_forum_tour.php`
That happens when I try to update a post.
When I try to add a new post using this code:
$sql = "INSERT INTO " . FORUM_TOUR_TABLE . " (page_id, page_subject, page_text, page_sort, bbcode_uid, page_access)
VALUES ($id, '$subject', '$message', $page, '$bbcode_uid', $page_access)";
This gives me this:
`SQL Error : 1064 Syntax error near ')' at line 2
INSERT INTO phpbb_forum_tour ( page_id , page_subject , page_text , page_sort , bbcode_uid , page_access ) VALUES (3, '2 Word Rule ', ' Hello World I am here ', 30 , ' f4e1be18dc ' )
Line : 198
File: admin_forum_tour.php`
I 100% apologize for asking this as I am more than sure it has been beat to death. I have been searching for a couple hours now and have all but given up. I had it working once but was told I opened my self up to injection. I am not a pro coder. I get lucky sometimes and make things work. I am sure these errors and code is basic to most but I am still learning.
Thanks for helping and understanding my "newbieness".

Related

How do I fix this SQL Syntax error concerning blobs?

i have a new forum up using SMF, and i’m trying to convert the database to UTF-8 now. SMF provides an easy way to do this, but upon doing so, i get this strange sounding error:
you have an error in your sql syntax; check the manual that corresponds to your mariadb server version for the right syntax to use near 'before before blob not null,
change column after after blob not null,
...' at line 6
file: /home/halfmoon/public_html/sources/managemaintenance.php
line: 664
i’m an extreme newbie to coding, especially when it comes to SQL, so i have 0 idea what the error means, other than where to find it and that the line is incorrect. if need be i can also copy and paste the line’s full text here as well- not sure what all is needed!:
line 664 starts at ‘updates_blob’
SQL Vers.:
“
// Change the columns to binary form.
$smcFunc['db_query']('', '
ALTER TABLE {raw:table_name}{raw:updates_blob}',
array(
'table_name' => $table_info['Name'],
'updates_blob' => substr($updates_blob, 0, -1),
)
);
MariaDB Vers.:
// Convert the character set if MySQL has no native support for it.
if (isset($translation_tables[$_POST['src_charset']]))
{
$update = '';
foreach ($table_charsets as $charset => $columns)
foreach ($columns as $column)
$update .= '
' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
$smcFunc['db_query']('', '
UPDATE {raw:table_name}
SET {raw:updates}',
array(
'table_name' => $table_info['Name'],
'updates' => substr($update, 0, -1),
)
);
}port for it.”

Case When Like in Eloquent in Laravel

i'm new with eloquent laravel
curently i have working mysql query below to transform data
select * from `dsa_data_realisasi_resolver` where (CASE WHEN akun LIKE '%51%' THEN 51 ELSE 0 END ) and year(`tanggal`) = 2020 and `kdsatker` = 412772 group by `akun`
when i try to use eloquent with something like this
$realisasi=Realisasi::whereRaw('(CASE WHEN akun LIKE '%51%' THEN 51 ELSE 0 END )')
->whereYear('tanggal','2020')
->where('kdsatker','412772')
->groupby('akun')
->get();
dd($realisasi);
there are errors
ErrorException
A non-numeric value encountered
when i try to remove single quotes '
$realisasi=Realisasi::whereRaw('(CASE WHEN akun LIKE %51% THEN 51 ELSE 0 END )')
->whereYear('tanggal','2020')
->where('kdsatker','412772')
->groupby('akun')
->get();
dd($realisasi);
the errors are
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%51% THEN 51 ELSE 0 END ) and year(`tanggal`) = ? and `kdsatker` = ? group by `a' at line 1 (SQL: select * from `dsa_data_realisasi_resolver` where (CASE WHEN akun LIKE %51% THEN 51 ELSE 0 END ) and year(`tanggal`) = 2020 and `kdsatker` = 412772 group by `akun`)
is there any solution with eloquent for query with case when like '%data%'
Thanks
Try with "(CASE WHEN akun LIKE '%51%' THEN 51 ELSE 0 END )" Notice the double quote to contain the whereRaw statement.
And to send dynamic data you can try "(CASE WHEN akun LIKE '%".data."%' THEN 51 ELSE 0 END )"
So your query should look like this:
$realisasi=Realisasi::whereRaw("(CASE WHEN akun LIKE '%".$data."%' THEN 51 ELSE 0 END )')
->whereYear('tanggal','2020')
->where('kdsatker','412772')
->groupby('akun')
->get();
MySQL requires the like pattern to be inside single quotes. For more reference: https://dev.mysql.com/doc/refman/8.0/en/pattern-matching.html

perl bash script don't insert sql query

i want to insert a query but not work :
my $query1 = $db1->prepare("SELECT host, name, severity FROM XX");
my $query2 = $db2->prepare('UPDATE worldmap_table' . ' SET severity = ?, name = ? WHERE HOST = ?');
$query1->execute;
while (my #row = $query1->fetchrow_array) {
$query2->execute($row[2]);
print "$row[2]\n";
}
preparation query 3
my $query3 = $db1->prepare("SELECT host, name, severity
FROM XX);
preparation query 4
my $query4 = $db2->prepare('UPDATE worldmap_table' . ' SET severity = 6, name = ? WHERE HOST = ?');
$query3->execute;
this part not work
while (my #row2 = $query3->fetchrow_array) {
$query4->execute($row2[2], $row2[1], $row2[0]);
print "$row2[2], $row2[1], $row2[0] \n";
}
i have this error:
DBD::mysql::st execute failed: called with 3 bind variables when 2 are needed at worldmap2.pl line 103.
DBD::mysql::st execute failed: called with 3 bind variables when 2 are needed at worldmap2.pl line 103.
There are two placeholders in query 4:
my $query4 = $db2->prepare(
'UPDATE worldmap_table' . ' SET severity = 6, name = ? WHERE HOST = ?'
# ~ ~
);
But you're calling it with only one argument:
$query4->execute($row2[2]);
# ~~~~~~~~
The error message mentions different numbers, so I guess you simplified the code.

CT_FETCH error in PowerBuilder Program

I'm still learning PowerBuilder and trying to get familiar with it. I'm receiving the following error when I try to run a program against a specific document in my database:
ct_fetch(): user api layer: internal common library error: The bind of result set item 4 resulted in an overflow. ErrCode: 2.
What does this error mean? What is item 4? This is only when I run this program against a specific document in my database, any other document works fine. Please see code below:
string s_doc_nmbr, s_doc_type, s_pvds_doc_status, s_sql
long l_rtn, l_current_fl, l_apld_fl, l_obj_id
integer l_pvds_obj_id, i_count
IF cbx_1.checked = True THEN
SELECT dsk_obj.obj_usr_num,
dsk_obj.obj_type,
preaward_validation_doc_status.doc_status,
preaward_validation_doc_status.obj_id
INTO :s_doc_nmbr, :s_doc_type, :s_pvds_doc_status, :l_pvds_obj_id
FROM dbo.dsk_obj dsk_obj,
preaward_validation_doc_status
WHERE dsk_obj.obj_id = :gx_l_doc_obj_id
AND preaward_validation_doc_status.obj_id = dsk_obj.obj_id
using SQLCA;
l_rtn = sqlca.uf_sqlerrcheck("w_pdutl095_main", "ue_run_script", TRUE)
IF l_rtn = -1 THEN
RETURN -1
END IF
//check to see if document (via obj_id) exists in the preaward_validation_doc_status table.
SELECT count(*)
into :i_count
FROM preaward_validation_doc_status
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF i_count = 0 THEN
//document doesn't exist
// messagebox("Update Preaward Validation Doc Status", + gx_s_doc_nmbr + ' does not exist in the Preaward Validation Document Status table.', Stopsign!)
//MC - 070815-0030-MC Updating code to insert row into preaward_validation_doc_status if row doesn't already exist
// s_sql = "insert into preaward_validation_doc_status(obj_id, doc_status) values (:gx_l_doc_obj_id, 'SUCCESS') "
INSERT INTO preaward_validation_doc_status(obj_id, doc_status)
VALUES (:gx_l_doc_obj_id, 'SUCCESS')
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number ' + gx_s_doc_nmbr + ' has been inserted and marked as SUCCESS for PreAward Validation.')
return 1
Else
//Update document status in the preaward_validation_doc_status table to SUCCESS
Update preaward_validation_doc_status
Set doc_status = 'SUCCESS'
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number '+ gx_s_doc_nmbr + ' has been marked as SUCCESS for PreAward Validation.')
End IF
update crt_script
set alt_1 = 'Acknowledged' where
ticket_nmbr = :gx_s_ticket_nmbr and
alt_2 = 'Running' and
doc_nmbr = :gx_s_doc_nmbr
USING SQLCA;
Return 1
ElseIF cbx_1.checked = False THEN
messagebox("Update Preaward Validation Doc Status", 'The acknowledgment checkbox must be selected for the script to run successfully. The script will now exit. Please relaunch the script and try again . ', Stopsign!)
Return -1
End IF
Save yourself a ton of headaches and use datawindows... You'd reduce that entire script to about 10 lines of code.
Paul Horan gave you good advice. This would be simple using DataWindows or DataStores. Terry Voth is on the right track for your problem.
In your code, Variable l_pvds_obj_id needs to be the same type as gx_l_doc_obj_id because if you get a result, it will always be equal to it. From the apparent naming scheme it was intended to be long. This is the kind of stuff we look for in peer reviews.
A few other things:
Most of the time you want SQLCode not SQLDbCode but you didn't say what database you're using.
After you UPDATE crt_script you need to check the result.
I don't see COMMIT or ROLLBACK. Autocommit isn't suitable when you need to update multiple tables.
You aren't using most of the values from the first SELECT. Perhaps you've simplified your code for posting or troubleshooting.

Doctrine QueryBuilder "andWhere" query

I am using this code:
$queryBuilder
->add('select', 'd.type')
->add('from', 'Entities:TypeDetail d')
->add('where', 'IDENTITY(d.typeName) = ' . $typeName->getId())
->add('andWhere', 'd.dateValue > ' . $dates['start'])
->add('andWhere', 'd.dateValue < ' . $dates['end']);
But I get this error: Notice: Undefined index: andWhere in...
I figure "andWhere" is not the correct name to use, but everywhere I read online suggests it is. But that is using the form ->andWhere(), not using ->add() like I am.
What am I doing wrong? Thanks
Have you tried this? -
$queryBuilder
->add('select', 'd.type')
->add('from', 'Entities:TypeDetail d')
->add('where', $queryBuilder->expr()->andx(
$queryBuilder->expr()->eq('IDENTITY(d.typeName)', $typeName->getId()),
$queryBuilder->expr()->gt('d.dateValue', $dates['start']),
$queryBuilder->expr()->lt('d.dateValue', $dates['end'])
));
Links here -
Doctrine Query Builder

Resources