我需要有关此代码的帮助。我的朋友和我创建了一个网站,但我们坚持:
代码在这里:
<?php
$servern = $_GET['server'];
$vownerid = $mybb->user['uid'];
$i1 = mysql_query("SELECT * FROM serversNew WHERE servername ='$servern'");
if(mysql_num_rows($i1) == 0) {
return;
} else {
while($row = mysql_fetch_assoc($i1)) {
$servername = $row['servername'];
$votes = $row['votes'];
$port = $row['port'];
$ip = $row['ip'];
$status = $row['status'];
$owner = $row['owner'];
$ownerid = $row['ownerid'];
$loader = $row['loader'];
$desc = $row['desc'];
}
if(($ownerid != $vownerid) && ($vownerid != 1)) {
return;
} else {
}
}
?>
<?php
if(isset($_POST['update'])) {
$servername1 = htmlspecialchars($_POST['servername']);
$ip1 = htmlspecialchars($_POST['ip']);
$port1 = $_POST['port'];
$owner1 = htmlspecialchars($_POST['owner']);
$loader1 = $_POST['loader'];
$desc1 = $_POST['desc'];
if($loader1 == "no") {
$loader1 = $loader;
}
if($loader1 == "custom") {
$loader1 = htmlspecialchars($_POST['jar']);
}
if($loader1 == 1) {
$loader1 = "";
} else if($loader1 == 2) {
$loader1 = "";
} else if($loader1 == 3) {
$loader1 = "";
} else if($loader1 == 4) {
$loader1 = "";
} else if($loader1 == 5) {
$loader1 = "";
}
if($port1 == "no") {
$port1 = $port;
}
mysql_query("UPDATE serversNew SET ip='$ip1', loader='$loader1', port='$port1', owner='$owner1', desc='$desc1' WHERE servername='$servername'");
?><script>window.location = "/member.php"</script><?php
}
?>
我们想要更新MYSQL查询,但它不会更新它。
希望有人可以帮助我们。答案 0 :(得分:2)
在SQL查询中,将all these reserved words放入反引号中:
mysql_query("UPDATE serversNew SET ip='$ip1', loader='$loader1', port='$port1', owner='$owner1', `desc`='$desc1' WHERE servername='$servername'");
另见:
答案 1 :(得分:0)
不用担心。在这里,我发布了一些用于数据库操作的自定义类。
Check this.
**Config.php**
<?php
if(!isset($_SERVER['DOCUMENT_ROOT'])){
if(isset($_SERVER['SCRIPT_FILENAME'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/',
substr($_SERVER['SCRIPT_FILENAME'], 0,
0-strlen($_SERVER['PHP_SELF']))); }; };
if(!isset($_SERVER['DOCUMENT_ROOT'])){
if(isset($_SERVER['PATH_TRANSLATED'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/',
substr(str_replace('\\\\', '\\',
$_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
# Define DB local
define('DBHOST','localhost'); // host name//192.168.1.20
define('DBUSER','xxxxxx'); // mysql user name
define('DBPASS','xxxxxxx'); // mysql pasword//142536
define('DBNAME','xxxxx'); // databse name
define('SITE_NAME','www.xxxxxx.co.in');
?>
Save this as config.php
Next For DB operations Like Insert, Update, Select, Delete
**db_class.inc**
> <?php
class db_mysql
{
var $database;
var $hostname;
var $username;
var $password;
var $link;
function db_mysql($hostname, $username, $password, $database)
{
$this->hostname = $hostname;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}
function connect()
{
if(!$this->link = @mysql_connect($this->hostname,$this->username,$this->password) )
{
echo "Cannot Connect to host: ".$this->hostname;
exit;
return false;
}
else
{
return true;
}
}
function select_db()
{
if(!@mysql_select_db($this->database, $this->link) )
{
echo "Cannot select database: ".$this->database;
exit;
return false;
}
else
{
return true;
}
}
function query($query)
{
$result = @mysql_query($query, $this->link) or die($query.'--<font color=red>'.mysql_error().'</font>');
return $result;
}
function fetch_one_row($query)
{
$result = @mysql_query($query, $this->link) or die($query.'--<font color=red>'.mysql_error().'</font>');
$array = @mysql_fetch_row($result);
if(is_array($array)) {
foreach($array as $key => $val)
$fetch_array[$key] = stripslashes($val);
}
return $fetch_array;
}
function fetch_array($result)
{
$array = @mysql_fetch_array($result);
if(is_array($array)) {
foreach($array as $key => $val)
$fetch_array[$key] = stripslashes($val);
}
return $fetch_array;
}
function fetch_row($result)
{
$array = @mysql_fetch_row($result);
if(is_array($array)) {
foreach($array as $key => $val)
$fetch_array[$key] = stripslashes($val);
}
return $fetch_array;
}
function fetch_assoc($result)
{
$array = mysql_fetch_assoc($result);
if(is_array($array)) {
foreach($array as $key => $val)
$fetch_array[$key] = stripslashes($val);
}
return $fetch_array;
}
function delete_id($id, $field, $table)
{
if( is_array($id) )
{
foreach( $id AS $i )
{
$this->query("DELETE FROM $table WHERE $field = '$i'");
}
}
else
{
$this->query("DELETE FROM $table WHERE $field = '$id'");
}
}
function delete_sel_value($table,$field,$value)
{
$result=$this->query("SELECT $field FROM $table WHERE $field='$value'");
$count = $this->fetch_row($result);
return $count;
}
function num_rows($result)
{
return @mysql_num_rows($result);
}
function affected_rows()
{
return @mysql_affected_rows();
}
function insert_id()
{
return @mysql_insert_id();
}
function value_exists($array, $table)
{
/*array contains values of the field name and field value*/
foreach($array as $key => $value)
{
$condition .= $key." = '".$value."' and ";
}
$condition = substr($condition,0,-5);
$result = $this->query("SELECT COUNT(*) as cnt FROM ".$table." WHERE ".$condition);
$count = $this->fetch_row($result);
return $count[0];
}
function get_count($table,$condition='')
{
if($condition) $condition = " WHERE " . $condition;
$result = $this->query("SELECT COUNT(*) as cnt FROM ".$table . $condition);
$count = $this->fetch_row($result);
return $count[0];
}
function update_from_array($array, $table, $field, $id)
{
$query = "UPDATE $table SET ";
while(@list($key,$value) = @each($array))
{
if((strpos($value,'now()') === false ) and (strpos($value,'date()')=== false) and (strpos($value,'DATE_ADD')=== false))
{
$fields[] = "$key='$value'";
}
else
{
$fields[] = "$key=$value";
}
}
$query .= implode(', ', $fields);
$query .= " WHERE ".$field." = '$id'";
$this->query($query);
return true;
}
function insert_from_array($array, $table)
{
while( @list($key,$value) = @each($array) )
{
$field_names[] = "$key";
if((strpos($value,'now()') === false ) and (strpos($value,'date()')=== false) and (strpos($value,'DATE_ADD')=== false) )
$field_values[] = "'$value'";
else
$field_values[] = "$value";
}
$query = "INSERT INTO $table (";
$query .= implode(', ', $field_names);
$query .= ') VALUES (' . implode(',', $field_values) . ')';
$this->query($query);
return true;
}
}
// END CLASS
?>
//Read by GET method, if URL like WWW.x.com/index.php?Get_par=req_Operation&count=1
//Use can use post method for getting **form** values
> if(function_exists($_GET['Get_par'])) {
>
> $_GET['Get_par']();
>
>
> }
//if get parameter value becomes **req_Operation**
> function req_Operation() {
> require('config.php');
> require('db_class.inc.php');
> $db = new db_mysql(DBHOST,DBUSER,DBPASS,DBNAME);
> $db->connect();
> $db->select_db();
>
> $var1 =$_POST['encrypt1'];
>
> $var2 =$_POST['encrypt2'];
>
>
> $query = "SELECT X FROM table_details where
> trim(table_key)='$var1'";
>
> $result = mysql_query($query) or die("Couldn't execute query.because:
>
> ".mysql_error());
>
>
> }
>
> ?>