vendredi 4 mars 2016

I am looking for help on stopping an entry being added to mysql database if the value = given parameter

Hi there I am looking for some guidance on how to go about stopping an entry being added to mysql database if the value = $parameter ...

I am building a database of latest tracks played on a station and I do not want entries with the station name being added to the database ...

I know that I will need to use if else and else if because of what I want to do as I am already checking if entry exists with if and else so am just looking for some pointers on how to stop entries being added if radio name is in the $trackartist field

I know I need to do something along the lines of if $trackartist = station name do nothing else check if entry exists else if do the insert but just can not seem to find any pointers on this

here is the code I am using to fill the rows any help on this would be greatly appreciated .

include('config.php');

$str = file_get_contents('xxxxxxxx.xxx');
$json = json_decode($str, true);
$artist = $json['now_playing']['artist'];
$track = $json['now_playing']['track']; 
$cover = $json['cover'];

$check = mysqli_query($mysqli,"select * from recent where      trackartist='$artist' and tracktitle='$track' and coverurl='$cover'");
$checkrows=mysqli_num_rows($check);

if($checkrows>0) {
  echo "track exists";
} else {  

  $sql = "INSERT IGNORE INTO recent (trackartist, tracktitle, coverurl)
  VALUES ('$artist', '$track', '$cover')";
  $result = mysqli_query($mysqli, $sql) or die('Error querying   database.');

  mysqli_close($mysqli);
 };

Aucun commentaire:

Enregistrer un commentaire