douge7771 2015-10-21 00:46
浏览 28

如何在输入超出限制的数据时提示警报?

I am working on library system and having a table of rack and a table of books.

Every book should belong to one rack and no rack can contain more than 10 books when user is adding a book in database when he select a rack if it already contains 10 books in it then it should prompt an alert.

Only 10 books can be added in a rack. An alert should prompt if user is trying to add more books. How can I do please help me.

     <?php

            $msg="";
            $query1 = "SELECT * FROM tbl_rack"; 
            $result1 = mysql_query($query1); 
            if(isset($_POST['btnadd']))

                {


                    $title      =$_POST['txttitle'];
                    $author =$_POST['txtauthor'];
                    $year       =$_POST['txtyear'];
                    $rack       =$_POST['txtrack'];
                    $query="insert into tbl_books(book_title,book_author,book_year,book_rack)values('$title','$author','$year','$rack')";

                    $rs     =   mysql_query($query);
                    if ($rs == 1)
                        $msg="Book has been added successfully" ;
                    else  
                        $msg="Try Again";


                }
  • 写回答

2条回答 默认 最新

  • doutuo3575 2015-10-21 01:11
    关注

    You can use mysqli_num_rows to get the number of results your $result1 variable was able to fetch. After that just use a conditional to check if that number is already 10.

    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接