0

I am trying to edit this code so that instead of just inserting the info - it checks to see if the file already exists in the database, if it does it inserts as it does now. If it does exist... it should just update the info, adding the "value" amount to the value amount already in there instead of replacing it. But this is very new to me and I am lost so any help with really be appreciated!

<?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';

?>

1 Answer 1

2

Take a look at the ON DUPLICATE KEY UPDATE syntax for MySQL

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.