jonasgalileo Posted November 10, 2008 Share Posted November 10, 2008 i have a whole script that can limit database entries coming from user inputs or data. but i have encountered an error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Thesis Lc Advance Black Version\reservation_monday.php on line 30.. is my code for limiting entries correct near the mysql_numr_rows()part? <?php //Database connection require_once("connection.php"); if(isset($_POST['submitmondaystudent'])) { $fullname = addslashes(strip_tags($_POST['fullname'])); //field name title $email = addslashes(strip_tags($_POST['email'])); //field name title $reasons = addslashes(strip_tags($_POST['reasons'])); //field name title $hour1 = addslashes(strip_tags($_POST['hour1'])); //field name title $hour2 = addslashes(strip_tags($_POST['hour2'])); //field name title $sched1 = addslashes(strip_tags($_POST['sched1'])); //field name title $minutes = addslashes(strip_tags($_POST['minutes'])); //field name title $programs = addslashes(strip_tags($_POST['programs'])); //field name title $instructor = addslashes(strip_tags($_POST['name'])); //field name title $date = addslashes(strip_tags($_POST['date'])); //field name title // insert items to database; $insert = "INSERT into monday_students(startingtime,endingtime,sched,minutes,programs,instructor,fullname,email,reasons,date) values('$hour1','$hour2','$sched1','$minutes','$programs','$instructor','$fullname','$email','$reasons',('$date'))"; $result = mysql_query($insert) or die(mysql_error()); $limit = 4; if ($result) { if(mysql_num_rows($result) == 4) { ?> <script type="text/javascript"> alert("Your only allowed to register 4 subjects."); self.location="monday_reservation.php" </script> <?php } else { ?> <?php $sendto = $email; $ccto = "[email protected]"; $subject = "Monday Schedule Confirmation"; $message = "Welcome " . $_POST['fullname'] . " Thank you for registering in our Site. Your Monday Schedule information : Time : ".$_POST['hour1'].":".$_POST['minutes']." - ".$_POST['hour2'].":".$_POST['minutes']." ".$_POST['sched1']." Subject : " . $_POST['programs'] . " Instructor : " . $_POST['name'] . " Visit our tutorial center for more details or contact us at 305-4355"; $header = "From: www.lcadvancedavao.com\r\n"; $header .= "[email protected]\r\n"; mail($sendto, $subject, $message, $header); echo" Your Reservation has been sent to our staff database,<br/>Check your email address for more updates.<br/> <a href=tutorial_reservation.php>Return to Registration page</a> | <a href=schedule_reservation.php>Return to Previous Page</a> <br/><br/> "; } } } Link to comment https://forums.phpfreaks.com/topic/132124-limiting-database-entries-in-phpmysql/ Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 The only thing I can think of is that an INSERT doesn't return a result. Are you looking to limit a particular email address from inserting more then 4 entries? If so, you should do a SELECT first, then the insert if there are less then 4 entries Link to comment https://forums.phpfreaks.com/topic/132124-limiting-database-entries-in-phpmysql/#findComment-686624 Share on other sites More sharing options...
waterssaz Posted November 10, 2008 Share Posted November 10, 2008 Hi, mysql_num_rows() will not work when your sql query $result comes from an insert statement. You need to use mysql_affected_rows() instead. Hope this helps :-) PS. I will assume that you have already set the link identifier for the second parameter for your mysql_query() elsewhere in your script in a mysql_connect(). Link to comment https://forums.phpfreaks.com/topic/132124-limiting-database-entries-in-phpmysql/#findComment-686709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.