ajoo Posted May 30, 2014 Share Posted May 30, 2014 Hi ! I am created this form - well it's more of a view and less of a form since the form part is only the check-boxes column and the rest is the data displayed from a database. But now I want to have this submitted with a SUBMIT button centered beneath the form after I have checked the required check boxes. I am unable to find a way to do this maybe simple task. Please help, unclubbed.php <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'testdb'; // CHANGE THIS TO ANY EXISTING DB ON PHPMYADMIN OR CREATE THIS DB FIRST IN PHPMYADMIN // $fcon = mysqli_connect($dbhost, $dbuser, $dbpass, $db); if(!$fcon ) { die('Could not connect: ' . mysql_error()); } // echo 'Connected successfully'; /* /////////// UNCOMMENT TO CREATE A TABLE IN A DATABASE NAMED testdb THEN COMMENT BACK ///////////// $sql = "CREATE TABLE member( mid INT NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, reg_date Date NOT NULL, email VARCHAR(30) NOT NULL, cell INT NOT NULL, status VARCHAR(2) NOT NULL, primary key ( mid ))"; if (mysqli_query($fcon,$sql)) { echo "Table member created successfully"; } else { echo "Error creating table: " . mysqli_error($con); } $query = "Insert into member (name, reg_date, email, status) VALUES ('John','1980-08-12','john@123.com','9878954323','cc')"; mysqli_query($fcon, $query); $query = "Insert into member (name, reg_date, email, status) VALUES ('Bill','1988-03-21','bill@123.com','9878900123','cc')"; mysqli_query($fcon, $query); $query = "Insert into member (name, reg_date, email, status) VALUES ('Jack','1990-05-18','jack@123.com','9878912300','cc')"; mysqli_query($fcon, $query); */ $check = true; $query = "SELECT * from member"; $result = mysqli_query($fcon, $query); if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') { echo "<br> Member = ".$_POST['name']."<br>" ; echo "RegDate = ".$_POST['reg_date']."<br>" ; echo "Email = ".$_POST['email']."<br>" ; echo "Status = ".$_POST['status']."<br>" ; /// more code would go here once I have submitted the check box information successfully ///// } ?> <html> <head> <title> CLUB ADMIN </title></head> <body> <table> <?php echo "<table class = 'TFtable' border = 1 cellspacing =2 cellpadding = 5 >"; echo "<tr>"; echo "<th> S.No. </th>"; echo "<th> Member </th>"; echo "<th> Reg Date </th>"; echo "<th> Email </th>"; if($check == true) echo "<th> <Input type='checkbox' id='selecctall' /> All </th>"; else echo "<th> Status </th>"; echo "</tr>"; $cnt = 1; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $name = htmlspecialchars($row['name']); $reg_date = htmlspecialchars($row['reg_date']); $cell = htmlspecialchars($row['cell']); $email = htmlspecialchars($row['email']); $mid = htmlspecialchars($row['mid']); if($check == false) $status = htmlspecialchars($row['status']); echo "<tr>"; echo "<td>".$cnt++."</td>"; echo "<td>".$name."</td>"; echo "<td>".$reg_date. "</td>"; echo "<td>".$email. "</td>"; if($check == true) { echo "<form name = 'form1' action='unclubbed.php' method='post' > "; echo "<td align ='center'><Input type='hidden' name='mid' value=$mid> <Input class='checkbox1' type = 'checkbox' name='check[]' value='$mid'> </td>"; echo "</form>"; echo "</tr>"; } else echo "<td>".$status. "</td> </tr> "; } ?> </table> </body> </html> Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/288883-problem-in-completing-the-form/ Share on other sites More sharing options...
Psycho Posted May 30, 2014 Share Posted May 30, 2014 (edited) This is not really a PHP problem (mostly), it is a JavaScript problem. But, you should NEVER rely only upon JavaScript to enforce things on a form. So, you would have to have back-end PHP code upon form submission as a way to absolutely check that the user checked the check box. But, to add a dynamic process, it is JavaScript. Look at the example I posted here: http://forums.phpfreaks.com/topic/288864-help-me-integrate-this-code-with-this-code-contact-form/?p=1481319 Edited May 30, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/288883-problem-in-completing-the-form/#findComment-1481414 Share on other sites More sharing options...
ajoo Posted May 31, 2014 Author Share Posted May 31, 2014 Hey I am sorry. I did not intend to post this one here but did so by mistake. I am using only php here. But from your reply it seems that it came to the right place. Is there no way to do this using PHP ? If not, then can we use JQuery instead? Meanwhile I'll look at your reply. Thanks for that Psycho. Quote Link to comment https://forums.phpfreaks.com/topic/288883-problem-in-completing-the-form/#findComment-1481453 Share on other sites More sharing options...
ajoo Posted May 31, 2014 Author Share Posted May 31, 2014 Hi Psycho & all. I have gone through the example but I don't understand it too well bcos I am not familiar with javascript or Jquery for that matter. Hence I wanted a PHP only solution. My problem has two parts. The first is to display a SUBMIT button centered below the form. The second is to ensure that that submit button is also a part of the form that contains the checked box buttons. Else how would the status of the checked boxes get POSTed on submit. If this cannot be achieved with PHP alone then please could you kindly integrate the jquery code into my example for me. Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/288883-problem-in-completing-the-form/#findComment-1481458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.