Jump to content

problem in completing the form.


ajoo

Recommended Posts

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 ! 

Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.