0

I have a script which takes data, and write in MySQL:

ID   Time    Data
1    10:20   Orange
2    10:21   Apple
3    10:22   Strawberry
4    10:23   Strawberry
5    10:24   Peach

How can I not enroll the code if the previous data the same, like this:

ID   Time    Data
1    10:20   Orange
2    10:21   Apple
3    10:22   Strawberry
4    10:24   Peach

This is my code to insert into th MYSQL database

$sql = "INSERT INTO MyTable (Time, Data) 
    VALUES ('$time', '$data');";

if ($conn->mysql_query($sql) === TRUE) {
    echo "New records created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

But this script does not have this exception :/

How I can make this?

ahmed_max
  • 5
  • 7
  • 1
    why are you using multi_query when you have one single query statement? and if this script is doing multiple sequentials inserts, you should be able to trivially check what was previously inserted and simply NOT do the insert for any "dupes". – Marc B Aug 22 '16 at 16:38
  • **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST` or `$_GET` data directly into a query, it can be very harmful if someone seeks to exploit your mistake. – tadman Aug 22 '16 at 16:41

0 Answers0