Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: mysql update table how to

by VC (Novice)
on Mar 19, 2019 at 00:54 UTC ( [id://1231412]=note: print w/replies, xml ) Need Help??


in reply to mysql update table how to

this the error i am getting: DBD::mysql::st execute failed: 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 '<> 'Yes'' at line 6 at admin.pl line 2316.

this is the code i am using

use strict; use warnings; use DBI; my $userid = DB::trim( param('Userid') ); # ?? my $username = DB::trim( param('Username') ); my $password = DB::trim( param('Password') ); my $DISABLED = ucfirst ( DB::trim( param('Disabled') ) || '' ); $DISABLED = 'No' unless $DISABLED eq 'Yes'; my $sql = 'SELECT ID,Disabled FROM EmployerJobs WHERE Username = ? AND Password = ? AND USERID = ? AND Disabled = <> ?'; my $dbh = DB::connect(); my $tbl_info = DB::TableInfo->get ($dbh, "EmployerJobs"); my $sth = $dbh->prepare($sql); $sth->execute($username, $password, $userid, $DISABLED); while ( my $row = $sth->fetchrow_hashref() ){ param (-name => "Disabled", -value => $DISABLED); param (-name => "ID", -value => $row->{ID}); $tbl_info->update_record ($dbh, "ID"); #print "Content-Type: text/html\n\n"; #printf "Updated ID '%s' from '%s' to '%s'\n",$row->{ID},$row->{DISA +BLED},$DISABLED; };

Any help would be greatly appreciated, Thanks.

Replies are listed 'Best First'.
Re^2: mysql update table how to
by huck (Prior) on Mar 19, 2019 at 02:42 UTC

    near '<> '

    what is near <>? Right before it is an equals sign. So you are asing for "Disabled equals-to not-equals-a-value". so which is it, equals or not-equals that you want?

      That is the code poj gave me so I don't know?

        Nonsense. poj wrote

        my $sql = 'SELECT ID,DISABLED FROM EmployerJobs WHERE Username = ? AND UserPassword = ? AND Userid = ? AND Disabled <> ?';

        which is valid SQL. Whereas you wrote

        my $sql = 'SELECT ID,Disabled FROM EmployerJobs WHERE Username = ? AND Password = ? AND USERID = ? AND Disabled = <> ?';

        which is not.

      what you see in the code

        let me be clear as to what I want to do, I want to update only one field (Disabled) among 27 fields and I am not sending info (param())for the other 26 fields at the same time.

        I did notice when I used the code below that worked once, that it deleted the information other fields, except the Disabled, Username, Password and ID which were in the current param(). The user has multiple ads that need to be Disabled & re enabled when the administrator wants, can this be done and How? I was thinking that I should not use the tbl_info to do it, as it uses all the fields to update using the param() to do it, Please help!

        use strict; use warnings; use DBI; my $userid = DB::trim( param('Userid') ); # ?? my $username = DB::trim( param('Username') ); my $password = DB::trim( param('Password') ); my $DISABLED = ucfirst ( DB::trim( param('Disabled') ) || '' ); $DISABLED = 'No' unless $DISABLED eq 'Yes'; my $sql = 'SELECT ID,Disabled FROM EmployerJobs WHERE Username = ? AND Password = ? AND USERID = ? AND Disabled = <> ?'; my $dbh = DB::connect(); my $tbl_info = DB::TableInfo->get ($dbh, "EmployerJobs"); my $sth = $dbh->prepare($sql); $sth->execute($username, $password, $userid, $DISABLED); while ( my $row = $sth->fetchrow_hashref() ){ param (-name => "Disabled", -value => $DISABLED); param (-name => "ID", -value => $row->{ID}); $tbl_info->update_record ($dbh, "ID"); #print "Content-Type: text/html\n\n"; #printf "Updated ID '%s' from '%s' to '%s'\n",$row->{ID},$row->{DISA +BLED},$DISABLED; };

        This is the correct code to do the JOB

        use strict; use warnings; use DBI; my $userid = DB::trim( param('USERID') ); my $DISABLED = DB::trim( param('Disabled')); my $sql= "UPDATE EmployerJobs SET Disabled = ". "'$DISABLED' where USERID = '$userid'"; $dbh = DB::connect (); $dbh->prepare($sql); $dbh->do($sql); $dbh->disconnect ();

        Thanks everyone!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1231412]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 17:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found