I'm writing an online game which need to read/write in mysql db. I test my little test script in an other host and it was ok. Now I moved here because it's free but my program doesen't work correctly!
The code returns the value of variable (1) but write some errors before it.
QUOTE
Notice: Undefined index: val in /www/zzl.org/o/n/l/onlinewm/htdocs/page.php on line 7
Notice: Use of undefined constant w - assumed 'w' in /www/zzl.org/o/n/l/onlinewm/htdocs/page.php on line 28
Notice: Use of undefined constant r - assumed 'r' in /www/zzl.org/o/n/l/onlinewm/htdocs/page.php on line 41
1
Notice: Use of undefined constant w - assumed 'w' in /www/zzl.org/o/n/l/onlinewm/htdocs/page.php on line 28
Notice: Use of undefined constant r - assumed 'r' in /www/zzl.org/o/n/l/onlinewm/htdocs/page.php on line 41
1
This is the address where I send some variables: http://onlinewm.zzl.org/page.php?cmd=r&...0000&key=10
And this is the php code:
CODE
<?php
$cmd=$_GET['cmd'];
$sec=$_GET['sec'];
$key=$_GET['key'];
$val=$_GET['val'];
$ret=1;
// Make a MySQL Connection
mysql_connect("localhost", "*****", "****") or die(mysql_error());
mysql_select_db("onlinewm_zzl_*****") or die(mysql_error());
// Create a MySQL table in the selected database
//netvaron! id,gameid,var,val
$sql = "
CREATE TABLE IF NOT EXISTS `netvaron`
(
`id` int(11) NOT NULL auto_increment,
`gameid` varchar(10) default NULL,
`var` varchar(1000) default NULL,
`val` varchar(1000) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=506
";
mysql_query($sql);
// Insert a row of information into the table "netvaron"
if ($cmd==w){
mysql_query("DELETE FROM netvaron WHERE gameid='".$sec."' AND var='".$key."'")
or die(mysql_error());
mysql_query("INSERT INTO netvaron
(gameid, var ,val) VALUES('".$sec."', '".$key."' ,'".$val."') ")
or die(mysql_error());
echo '1';
}
if ($cmd==r){
// Retrieve all the data from the "netvaron" table
$result = mysql_query("SELECT * FROM netvaron WHERE gameid='".$sec."' AND var='".$key."'
ORDER BY id DESC")
or die(mysql_error());
// store the record of the "netvaron" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo $row['val'];
}
?>
$cmd=$_GET['cmd'];
$sec=$_GET['sec'];
$key=$_GET['key'];
$val=$_GET['val'];
$ret=1;
// Make a MySQL Connection
mysql_connect("localhost", "*****", "****") or die(mysql_error());
mysql_select_db("onlinewm_zzl_*****") or die(mysql_error());
// Create a MySQL table in the selected database
//netvaron! id,gameid,var,val
$sql = "
CREATE TABLE IF NOT EXISTS `netvaron`
(
`id` int(11) NOT NULL auto_increment,
`gameid` varchar(10) default NULL,
`var` varchar(1000) default NULL,
`val` varchar(1000) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=506
";
mysql_query($sql);
// Insert a row of information into the table "netvaron"
if ($cmd==w){
mysql_query("DELETE FROM netvaron WHERE gameid='".$sec."' AND var='".$key."'")
or die(mysql_error());
mysql_query("INSERT INTO netvaron
(gameid, var ,val) VALUES('".$sec."', '".$key."' ,'".$val."') ")
or die(mysql_error());
echo '1';
}
if ($cmd==r){
// Retrieve all the data from the "netvaron" table
$result = mysql_query("SELECT * FROM netvaron WHERE gameid='".$sec."' AND var='".$key."'
ORDER BY id DESC")
or die(mysql_error());
// store the record of the "netvaron" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo $row['val'];
}
?>
help me plz