php - Checking sure data doesn't exist in a table in a database before inserting it -



php - Checking sure data doesn't exist in a table in a database before inserting it -

i trying insert info table of 3 columns using php script. table named event contains these fields , data

id(int) event(varchar) description (text) 1 lorem ipsum sit down dolor amet lorem ipsum dolor sit down amet, consectetur adipiscing elit......

but before insert trying check if info doesn't exist before insert in table. using next php script checking , inserting seems inserting info when info exists. problem , best way go this?

<?php $event = "lorem ipsum sit down dolor amet"; $description = "lorem ipsum dolor sit down amet, consectetur adipiscing elit......"; if ($check = $db->prepare("select event, description event")) { $check->execute(); $check->bind_result($e, $d); $check->fetch(); $check->close(); } else { echo "sql statement not executed."; } if (strcmp($event, $e) && strcmp($description, $d)) { echo "event exists."; } else { if ($insert_event = $db->prepare("insert event (event, description) values (?,?) ")) { $insert_event->bind_param("ss", $event, $description) $insert_event->execute(); $insert_event->close(); } else { echo "sql statement not executed."; } header("index.php"); } ?>

php

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -