There is such a task:

  1. There is a form with two inputs. Document number and Document date.
  2. There is a database with a table in which there are 2 columns: in one document number, in another document dates.
  3. How to make so that the combination of the data from the form and the combination from the table is checked (and it is the combination, otherwise I got it so that the number is checked and the date passes any of the second column)
$link = mysql_connect("localhost", "root", "") or die("Ошибка соединения с БД: " . mysql_error()); mysql_select_db('reestr', $link) or die ('Ошибка в выборе БД : ' . mysql_error()); $blankid = $_POST['blankid']; $blankdate = $_POST['blankdate']; $query = mysql_query("SELECT * FROM blanki WHERE blank_id=$blankid"); if(mysql_num_rows($query)){ echo "GOOD"; } else echo "shit"; 
  • Add your code - MihailPw
  • Give a sample code, specify which database you are using - Darth
  • Here's the code I use mySQL <? php $ link = mysql_connect ("localhost", "root", "") or die ("Error connecting to the database:". mysql_error ()); mysql_select_db ('reestr', $ link) or die ('Error in database selection:'. mysql_error ()); $ blankid = $ _POST ['blankid']; $ blankdate = $ _POST ['blankdate']; $ query = mysql_query ("SELECT * FROM blanki WHERE blank_id = $ blankid"); if (mysql_num_rows ($ query)) {echo "GOOD"; } else echo "shit"; ?> - Ilya Zarhart
  • Do you really want to check the combination ? Or, maybe you really want that after selecting in one of the lists in the second there are only those options (pairs of values) that are present in the table? - Akina
  • I need the entered data pair: Number and Date to find or not match from the database, also a pair: from one column number, from another date - Ilya Zarhart

1 answer 1

Generally solved the question like this, all thanks

 <?php $link = mysql_connect("localhost", "root", "") or die("Ошибка соединения с БД: " . mysql_error()); mysql_select_db('reestr', $link) or die ('Ошибка в выборе БД : ' . mysql_error()); $blankid = $_POST['blankid']; $blankdate = $_POST['blankdate']; $query = mysql_query("SELECT * FROM blanki WHERE blank_id='".$blankid."' AND blank_data='".$blankdate."' "); $numrows = mysql_num_rows($query); if($numrows!=0) { if($row=mysql_fetch_assoc($query)){ $db_blankid = $row['blank_id']; $db_blankdate = $row['blank_data']; } else echo "UZHAS"; if($blankid == $db_blankid && $blankdate == $db_blankdate) echo "GOOD"; else echo "govno"; } else echo "polnoe dermo"; ?> 
  • Brrrrrrrrrrrrrrrr ... - Qwertiy