Jump to content

Recommended Posts

Now, here's what I'm trying to do:

First, I have a file filled with data like such:

  • title
  • tag
  • 1
  • 2
  • Title
  • Description
  • Etc

Next, I upload that file to my site which then proceeds to make an array with said data and then inserts it into my database. But this is not the intended behavior. Right now, if I upload the same file again, it will re-insert everything and duplicate all entries.

What I want to do is check if the data in the file has already been added, do nothing. If it's been modified, I want to update the database where changes have been made and not duplicate anything.

Currently, my code does all that except one thing whre I'm really stuck: it won't update the changes from the file to the database. I've tried echoing everything and it's to be working except for the query so I take it the error is in there but I can't find it... I'm still learning PHP and MySQL so I thought maybe somebody could help indicate where or what I'm doing wrong in the query. Thanks in advance !

Here's my attempt at doing so:

$register_ep_data = array(
			'show' => $name,
			'season' => $srNum,
			'ep' => $epNum,
			'app_name' => $epName,
			'tag' => $tag,
			'app_about' => $desc,
			'app_website' => $imdb,
			'app_release' => $release,
			'type' => $type,
			'app_code' => $Frame 
			);

array_walk($register_ep_data, 'array_fu');

$fields = '`' . implode('`, `', array_keys($register_ep_data)) . '`';
$data = '\'' . implode('\', \'', $register_ep_data) . '\'';

$epFound = false;
$id = 0;
	 
while ($ep_list_data = mysql_fetch_array($turtle)) {

     $id = $ep_list_data['app_id'];

     $currentNAME = $ep_list_data['app_name'];
     $SERIES = $ep_list_data['show'];

     if ($SERIES == $name) {

        if ($currentNAME == $epName) {
              $epFound = true;
              break;
	}

      }

   }

   if ($epFound) {
      mysql_query("UPDATE `games` SET ($fields) VALUES ($data) WHERE `app_id` = '$id'");
   } else {
      mysql_query("INSERT INTO `games` ($fields) VALUES ($data)");
   }

A few explanations:

 

$fields would equal to something like: `show`, `season`, `ep`, etc...

and $data to 'example', '1', '2', 'etc'

Link to comment
https://forums.phpfreaks.com/topic/290322-mysql-update-mutliple-fields-from-array/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.