-1

I want to do a trap that if the array has a value the same within the database. they will then proceeded to the if condition I build. So far this is my code.

    $a = $_POST['a'];
    $b = $_POST['b'];
    foreach ($_POST['b'] as $b) 
{              
    $result = mysql_query("select * from ehr_schedule3 where (sched3_time='$b' and sched2_id='$a') ");

            $row = mysql_fetch_array($result);
            $num = mysql_num_rows($result);
}
            if(strpos($b, $result)==true) //$b is the array value I will insert to the db.
{
            header("Location: ../edit_sched2.php?asdfghjkl=".$a."?false");
                $_SESSION["A"] = "E" ;
}

I don't know how to play with array in the mysql_query. I just want to proceed it to if if there is just one of the same value. I originally planning to make it a string so that if the strpos have confirmed it has the same value, it will proceed then to the if

Noobster
  • 93
  • 11

1 Answers1

0

I think one day you could use a DISTINCT clause in your query so you would not get duplicates. By the way, you should use mysqli since mysql_functions are deprecated. I want to comment for clarification so I can help you more but I don't have 50 reputation yet. So for my understanding so far this is what I would do:

    $a = $_POST['a'];
    $b = $_POST['b'];
    $query = "SELECT schedule3_time, schedule2 FROM ehr_schedule3  WHERE sched3_time LIKE $a and sched2_time LIKE $b "
    $key = mysqli_connect($host, $user, $passwd, $database)
     or die(mysql_error); /*your credientials */
    foreach ($_POST['b'] as $b) 
      {              
            $result = mysqli_query($key, $query);

            $row = mysqli_fetch_array($result);
            $num = mysqli_num_rows($result);
            }
            if(strpos($b, $result)==true) {
             $sql = "INSERT INTO tablename (firstname, lastname, email)
            VALUES ('John', 'Doe', 'john@example.com')"; /* put your table here*/

           if (mysqli_query($key, $query)) {
                 echo "New record created successfully";
               } else {
                echo "Error: " . $sql . "<br>" . $conn->error;
               }

             $key->close();
    } //$b is the array value I will insert to the db.
{
            header("Location: ../edit_sched2.php?asdfghjkl=".$a."?false");
                $_SESSION["A"] = "E" ;
} 

Check out this post to help you with your question.

Community
  • 1
  • 1
Venom
  • 27
  • 7