2010-11-23 93 views
0

我试图编辑此代码,以便不仅仅插入信息 - 而是检查数据库中是否已存在该文件,如果它插入了现在的值。如果它确实存在......它应该只更新信息,将“价值”金额添加到已有的金额中而不是替换它。但是这对我来说是非常新的,我迷失了,所以任何帮助,真的很感激!更新mysql并将值添加到现有值

<?php 
define('JPATH_BASE',$_SERVER['DOCUMENT_ROOT']); 
require_once($_SERVER['DOCUMENT_ROOT']."/b2/configuration.php"); 

require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/factory.php"); 
require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/base/object.php"); 
require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/database/database.php"); 
require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/database/database/mysql.php"); 

$config = new JConfig; 
$options = array(); 
$options['host'] = $config->host; 
$options['user'] = $config->user; 
$options['password'] = $config->password; 
$options['database'] = $config->db; 
$options['prefix'] = $config->dbprefix; 
$options['select'] = true; 


$db = new JDatabaseMySQL($options); 

//$user = JFactory::getUser(); 
$userId = 0; 
//($user->id > 0) ? $user->id : 0; 
$numbervote = $_REQUEST['w']; 
$folder = $_REQUEST['w2']; 
$name = $_REQUEST['w1']; 
    $date = date('Y-m-d H-i-s'); 
    $sql = "INSERT INTO jos_image_ratetting (id,userid,datecreated,value,filename,folder,md5name) VALUES(NULL,'".$userId."','".$date."','".$numbervote."','".$name."','".$folder."',MD5('".$name."'))"; 
    $db->setQuery($sql); 
    if($db->query()){ 
    $msg = "Thanks for rate!"; 
    }else{ 
    $msg = mysql_error(); 
    } 
    echo $msg; 
//echo 'Hello'; 

?> 

回答