This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

[SOLVED]What is wrong here

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

[SOLVED]What is wrong here

Post by Fire-Fox »

can't read "info": no such variable

Code: Select all

proc infoDel {nick uhost handle chan text} { 
    if {![channel get $chan infoDel]} return 

   variable dbInfo 
   if {[scan $dbInfo %s%s%s%s hostname username password database] != 4} return       
   set info [::mysql::escape $info]
   set con [::mysql::connect -host $hostname -user $username -password $password -db $database] 
   set query [::mysql::query $con "SELECT info FROM info WHERE info = '$info'"] 
   if {[::mysql::fetch $query]==""} {
   putquick "PRIVMSG $chan : Nothing found"
   } else {
   set query [::mysql::query $con "SELECT info FROM info WHERE info = '$info'"]
   putquick "PRIVMSG $chan :Info list $info"
   }
   ::mysql::endquery $con 
   ::mysql::close $con 
	}
Last edited by Fire-Fox on Mon Jul 14, 2014 7:24 pm, edited 1 time in total.
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Believe this would be the problem line...

Code: Select all

   set info [::mysql::escape $info]
You are trying to read $info before it exists.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Hey!

I have tried to put various places but havn't worked yet
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Exactly what information are you trying to send to the ::mysql::escape proc?
I'm sure it's not the contents of $info because that variable does not exist yet.

Maybe you mean something more like...

Code: Select all

   set info [::mysql::escape $dbInfo]
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

What will give me my login to the database :)

I'll post my setup when i get it to work :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

There's no need to escape your dbInfo variable cos that's considered safe so no need to sanitize it but rather the user input.

The error clearly states where's the problem and SpiKe^^ highlighted that in his first post.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Here is the working version

Code: Select all

bind pub -|- !info infolist
proc infolist {nick uhost handle chan text} {
   if {![channel get $chan infoList]} return
 
  variable dbInfo
  if {[scan $dbInfo %s%s%s%s hostname username password database] != 4} return        
  set con [::mysql::connect -host $hostname -user $username -password $password -db $database]
  set query [::mysql::query $con "SELECT info FROM infos"]
  if {[::mysql::fetch $query]==""} {
        putquick "PRIVMSG $chan : \0034Nothing found! :-(\003"
  } else {
        set query [::mysql::query $con "SELECT info FROM infos ORDER BY info"]
        ::mysql::map $query { info } {
        putquick "PRIVMSG $chan :\0037INFO\003: \0039$info\003"
  }
  ::mysql::endquery $con
  ::mysql::close $con
	}
  }
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The:

Code: Select all

  ::mysql::endquery $con
  ::mysql::close $con 
need to be moved one section down cos as are right now are in the else section.

Also, you can replace the first query with the second one that you should remove entirely.

Code: Select all

bind pub -|- !info infolist

proc infolist {nick uhost handle chan text} {
	if {![channel get $chan infoList]} return
	variable dbInfo
	if {[scan $dbInfo %s%s%s%s hostname username password database] != 4} return       
	set con [::mysql::connect -host $hostname -user $username -password $password -db $database]
	set query [::mysql::query $con "SELECT info FROM infos ORDER BY info"]
	if {[::mysql::fetch $query]==""} {
		putquick "PRIVMSG $chan : \0034Nothing found! :-(\003"
  } else {
		::mysql::map $query { info } {
			putquick "PRIVMSG $chan :\0037INFO\003: \0039$info\003"
		}
	}
	::mysql::endquery $con
	::mysql::close $con
}
Once the game is over, the king and the pawn go back in the same box.
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Ahh thanks :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
Post Reply