mysql - Check if entry is available in database -
i have generated 10 digit number, added database after purchase.
now want make php page give users input box, ask them enter 10 digit number, , click submit. after click submit should return if pin used or has not been used it. (used if not available - not used if in table)
i got following code:
<?php require_once 'db.php'; function validated_pin($pin) { $pin = mysql_real_escape_string($pin); // security! $result = mysql_query("select pins pins pin='$pin' limit 1"); if (mysql_fetch_row($result)) { return 'this pin has been used'; } else { return 'this pin available use'; } } echo '<html><center> <form action="' . $_server['script_name'] . '" method="post"> <table style="border:0px solid black;"> <tr> <td>pin*:</td><td><input type="text" name="pin" value="" class="bginput"/></td> </tr> <tr> <td></td><td><input type="submit" id ="submit" name="submit1" value="check pin>>" class="button"></td> </tr> </table>'; echo validated_pin($pin); echo '</center></html>'; ?>
and phpmyadmin looks this: http://gyazo.com/67c3df7171c83c677cb221c04d644ed7.png
it's located in _donation , in table name pins
i don't know whats going on tried looking everywhere
the current code return error
warning: mysql_fetch_row() expects parameter 1 resource, boolean given in /home/website/public_html/directory/example.php on line 8
your query failing fetch data, resulting in false
returned.
firstly - should catch false
value , not assume $result
has data.
secondly - var_dump()
query running, run in phpmyadmin
Comments
Post a Comment