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.

mysql update

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

mysql update

Post by Madalin »

can anyone help me with a procname for inserting and updating values into a mysql database ?! I have tryed something but it doesnt work.

Code: Select all

set my(host) "..."
set my(user) "...
set my(pass) "..."
set my(db)   "..."

proc mysql:do {nick} {
	global my

	set handle [::mysql::connect -host $my(host) -user $my(user) -password $my(pass) -db $my(db)]

	set check "SELECT player FROM filelist WHERE player = '[::mysql::escape $nick]'"
	if {[set channel [::mysql::sel $handle $check -list]]!=""} {set do -update} {set do -insert}; putlog "$channel $do"

	switch -exact -- $do {
		-insert {
			set query "INSERT INTO `filelist` (id, laston, player, hostname, daily, weekly, monthly, total, cps, fast, qa, qar, rounds, rpoints, teamp, teamr, teamn) VALUES ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17',NOW())"
			set result [::mysql::exec $handle $query]
			if {$result != "1"} {putlog "an error has ocurred with sql: * $result"} {putlog "executing: $query - \00304Ok."}
		}
		-update { set query "UPDATE `web_statistics` SET `manager`='[::mysql::escape $my(manager)]', `valid`='$my(valid)', `time`=NOW()  WHERE channel='$channel'"
			set result [::mysql::exec $handle $query]
			if {$result != "1"} {putlog "an error has ocurred with sql: * $result"} {putlog "executing: $query - \00304Ok."}

		}
		::mysql::close $handle
	}
}
I encounter errors like

Tcl error: ::mysql::exec/db server: Column count doesn't match value count at row 1
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Looks to me because you have 17 Columns listed and are trying to insert 18 values.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Yes... forgot to reply here .. NOW() was being counted like a var to
Post Reply