0

I'm trying to create a really basic like system using auto increment in mysql.

Basically this script inserts the user_id and auto increments the like column to 1, what I need to try and do though is once the the user_id and like has been inserted the first time round I then need to make my script say something like if result already exists update else insert?

Can someone please show me how I could do this thanks:

<?php

require_once('includes/session.php');
require_once('includes/functions.php');
require('includes/_config/connection.php');

session_start();

    confirm_logged_in();

    if (isset ($_GET['to'])) {
    $user_to_id = $_GET['to'];


}


if (!isset($_GET['to']))
    exit('No user specified.');

$user_id = $_GET['to'];




$result1 = mysql_query("INSERT INTO ptb_likes (liked_id) VALUES (".$user_to_id.")");


if($result1) 
{ 

header("Location: {$_SERVER['HTTP_REFERER']}");

}
?>
Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
Joe Dargie
  • 21
  • 1
  • 3

1 Answers1

0

Do a SELECT first to see if ptb_likes contains the row you're thinking about inserting.

Once you know if it does or does not exist you can choose what to do next.

Patashu
  • 21,443
  • 3
  • 45
  • 53