5 Replies - 521 Views - Last Post: 31 July 2012 - 08:23 PM Rate Topic: -----

#1 nikita mehra  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 6
  • Joined: 31-July 12

checklist problem in php

Posted 31 July 2012 - 09:20 AM

*html form*
<head>

<?php
if ((@$_POST["tutor_id"]=="") && (@$_POST["password"]=="")&& (@$_POST["name"]=="")&& (@$_POST["hp_num"]=="") && (@$_POST["email_add"]=="") && (@$_POST["mathF1"]=="") && (@$_POST["mathF2"]=="") && (@$_POST["mathF3"]=="") && (@$_POST["mathF4"]=="") && (@$_POST["mathF5"]=="") && (@$_POST["snF1"]=="") && (@$_POST["snF2"]=="") && (@$_POST["snF3"]=="") && (@$_POST["addMathF4"]=="") && (@$_POST["addMathF5"]=="") && (@$_POST["phyF4"]=="") && (@$_POST["phyF5"]=="")) 
{     
?>
	<script type=text/javascript>
	function check()
	{
		if ((form.tutor_id.value=="") || (form.password.value=="")|| (form.name.value=="")||(form.hp_num.value=="") ||(form.email_add.value=="") || (form.mathF1.value=="") || (form.mathF2.value=="") || (form.mathF3.value=="") || (form.mathF4.value=="") || (form.mathF5.value=="") || (form.snF1.value=="") || (form.snF2.value=="") || (form.snF3.value=="") || (form.addMathF4.value=="") || (form.addMathF5.value=="") || (form.phyF4.value=="") || (form.phyF5.value==""))
		{
			alert("Fill all the empty spaces. THANK YOU");
			return false;
		}
		else
			return true;
	}
	</script>
<?php
}
?>

<title>WAWASAN TUITION CENTRE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
<!--
body,td,th {
	font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
	font-size: 16px;
}
.style1 {font-size: xx-small}
body {
	margin-left: 80mm;
	margin-top: 0mm;
	margin-right: 30mm;
	margin-bottom: 50mm;
	background-color:#5CB3FF 

}
.style2 {font-size: 24px}
.style3 {font-size: 16px}
-->
</style>
</head>
<body>

<table width="814"  height="400" border="1">
  <tr>
    <td colspan="3"><p><img src="picture/header image.png" width="963" height="241"></p>
   </td>
  </tr>
 <tr>
    <td colspan="1"><div align="right"><a href="admin_logout.php">LOGOUT</a></div></td>
  </tr>
  <tr>
    <td> <div align="center" class="style2">
      <p>TUTOR REGISTRATION FORM </p>
</div></td>
</tr>
    <tr>
   	 <td width="245" bgcolor="#8CC6C6"><div align="center">
     <form action="tutor_reg2.php" method="post" name="form">
      <table width="484" border="1" align="center"> 
      <tr>
    <td><div align="center"><strong>TUTOR ID</strong></div></td>
    <td><input name ="tutor_id" type="hidden" size="50"></td>
  </tr>
  <tr>
    <td><div align="center"><strong>TUTOR NAME</strong></div></td>
    <td><input name ="name" type="text" size="50"></td>
  </tr>
   <tr>
    <td><div align="center"><strong>PASSWORD </strong></div></td>
    <td><input name ="password" type="password" size="50"></td>
  </tr>
     
  <tr>
    <td><div align="center"><strong>HANDPHONE NUMBER </strong></div>    </td>
    <td><input name="hp_num" type="text" size="50"></td>
  </tr>
  
   <tr>
    <td><div align="center"><strong>EMAIL ADDRESS</strong></div></td>
    <td> <input name ="email_add" type="text" size="50" ></td>
  </tr>
  
  <tr>
    <td><div align="center"><strong>SUBJECT LIST</strong></div></td>
    <td> <input name="mathF1" type="checkbox" value="mathF1" /> 
    MATHEMATICS FORM 1<br />
	<input name="mathF2" type="checkbox" value="mathF2" />           MATHEMATICS FORM 2 <br />
    <input name="mathF3" type="checkbox" value="mathF3" />        MATHEMATICS FORM 3<br />
    <input name="mathF4" type="checkbox" value="mathF4">        MATHEMATICS FORM 4<br />
    <input name="mathF5" type="checkbox" value="mathF5" />        MATHEMATICS FORM 5<br />
    <input name="snF1" type="checkbox" value="snF1" />        SCIENCE FORM 1<br />
    <input name="snF2" type="checkbox" value="snF2" />        SCIENCE FORM 2<br />
    <input name="snF3" type="checkbox" value="snF3" />        SCIENCE FORM 3<br />
    <input name="addMathF4" type="checkbox" value="addMathF4" />        ADDITIONAL MATHEMATICS FORM 4<br />
     <input name="addMathF5" type="checkbox" value="addMathF5" /> 
     ADDITIONAL MATHEMATICS FORM 5<br />
      <input name="phyF4" type="checkbox" value="phyF4" />        
      PHYSICS FORM 4<br />
      <input name="phyF5" type="checkbox" value="phyF5" />        PHYSICS FORM 5<br /> </td>
  </tr>
  
  <tr>
    <td colspan="5"><div align="center" class="style9">
      <div align="center">
        <input type="submit" name="Submit" value="SUBMIT">
        <input type="reset" name="Submit2" value="RESET">
     </div>
    </div></td>
  </tr>
</table></form>
 <tr>
    <td colspan="2"><div align="center"><a href="index.html"><img src="picture/home icon.jpg" width="109" height="70" border="0" align="middle"></a></div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center" class="style1">COPYRIGHT © WAWASAN TUITION CENTRE by PRAVINA @ UNITEN 2012 </div></td>
  </tr> </table>
</body>
</html>



and PHP code


<?php
include 'connect_db.php';
if ((@$_POST["tutor_id"]=="") && (@$_POST["password"]=="")&& (@$_POST["name"]=="")&& (@$_POST["hp_num"]=="") && (@$_POST["email_add"]=="") && (@$_POST["mathF1"]=="") && (@$_POST["mathF2"]=="") && (@$_POST["mathF3"]=="") && (@$_POST["mathF4"]=="") && (@$_POST["mathF5"]=="") && (@$_POST["snF1"]=="") && (@$_POST["snF2"]=="") && (@$_POST["snF3"]=="") && (@$_POST["addMathF4"]=="") && (@$_POST["addMathF5"]=="") && (@$_POST["phyF4"]=="") && (@$_POST["phyF5"]=="")) 
{
?>
<script>
alert("Fill all the empty spaces. THANK YOU");
window.location.href="tutor_reg.php";
</script>
<?php
}
else if(strlen($_POST['hp_num'])!=10)
{
?>
<script>
alert("INVALID NUMBER. IT SHOULD BE IN THE LENGTH OF 10");
window.location.href="tutor_reg.php";
</script>
<script type="text/javascript">
function validate_form ( )
{
	valid = true;
	if (form.email_add.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
       
       valid = false;
    }
		 
}

</script>
<?php
}
else{ 
$tutor_id = $_POST['tutor_id']; 
$password = $_POST['password']; 
$name = $_POST['name']; 
$hp_num = $_POST['hp_num']; 
$email_add = $_POST['email_add']; 
$mathF1 = $_POST['mathF1'];
$mathF2 = $_POST['mathF2'];
$mathF3 = $_POST['mathF3'];
$mathF4 = $_POST['mathF4'];
$mathF5 = $_POST['mathF5'];
$snF1 = $_POST['snF1'];
$snF2 = $_POST['snF2'];
$snF3 = $_POST['snF3'];
$addMathF4 = $_POST['addMathF4'];
$addMathF5 = $_POST['addMathF5'];
$phyF4 = $_POST['phyF4'];
$phyF5 = $_POST['phyF5'];
$var = $_POST['whatever']; 
 

$result = mysql_num_rows(mysql_query("SELECT * FROM tutor WHERE    tutor_id= '$tutor_id'")); 
$mymax = mysql_num_rows(mysql_query("SELECT * FROM tutor"));
$mymaxid = $mymax;
$pad_length = 3;
$item = str_pad($mymax, $pad_length, '0', STR_PAD_LEFT);

if($result == 1) 
        { 
        
        echo '<h1>ERROR!</h1>The userid you have chosen already exists!'; 
        } 
	  
		else 
        { 
		mysql_query("INSERT INTO tutor (tutor_id, password,name ,hp_num,email_add,mathF1,mathF2,mathF3,math4,math5,snF1,snF2,snF3,addMathF4,addMathF5,phyF4,phyF5) VALUES ('T$item','$password', '$name','$hp_num','$email_add','$mathF1','$mathF2','$mathF3' ,'$mathF4','$mathF5','$snF1','$snF2','$snF3','$addMathF4','$addMathF5','$phyF4','$phyF5')"); 
}

 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>WAWASAN TUITION CENTRE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
<!--
body,td,th {
	font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
	font-size: 16px;
}
.style1 {font-size: xx-small}
body {
	margin-left: 80mm;
	margin-top: 0mm;
	margin-right: 30mm;
	margin-bottom: 50mm;
	background-color:#5CB3FF 

}
.style2 {font-size: 24px}
.style3 {font-size: 16px}
-->
</style>
</head>
<body>

<div id="right">                  
				  <div align="right">
				  </div>
				  <div id="thumbnails">
				    <p align="right"></p>
   	                <p align="center">Congratulations! You have successfully registered as a tutor! 
					<p>Click <a href="admin_main_page.php">here</a> admin main page.</p>
		    <p>&nbsp;</p>
		    <p>&nbsp;             </p>
		  		  </div>
	 <p>&nbsp;</p>
	
		    <h2 align="left">&nbsp;</h2>
			</div>
	</div>  			
</body>
</html>' ;	
 
?>

<?php
}
?>


**** I HAVE PROBLEM WITH CHECKBOX WHERE i CAN'T CHOOSE MORE THEN 1 BOX.. AND I TRY TO FIX IT BUT FAILED

CAN ANYONE HELP ME, I HAVE BEEN FIX THE ERROR PAST FEW DAYS BUT I DUNNO WHERE IS THE ERROR

MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!!

:code;

This post has been edited by JackOfAllTrades: 31 July 2012 - 09:22 AM


Is This A Good Question/Topic? 0
  • +

Replies To: checklist problem in php

#2 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: checklist problem in php

Posted 31 July 2012 - 12:55 PM

What are you expecting to happen when you submit the form?
What actually happens when you submit the form?
What have you tried?

Also, this:

if ((@$_POST["tutor_id"]=="") && (@$_POST["password"]=="")&& (@$_POST["name"]=="")&& (@$_POST["hp_num"]=="") && (@$_POST["email_add"]=="") && (@$_POST["mathF1"]=="") && (@$_POST["mathF2"]=="") && (@$_POST["mathF3"]=="") && (@$_POST["mathF4"]=="") && (@$_POST["mathF5"]=="") && (@$_POST["snF1"]=="") && (@$_POST["snF2"]=="") && (@$_POST["snF3"]=="") && (@$_POST["addMathF4"]=="") && (@$_POST["addMathF5"]=="") && (@$_POST["phyF4"]=="") && (@$_POST["phyF5"]==""))



Is fairly hideous and is going to be quite difficult to debug. I would imagine, just from a very quick glance, that your problem may well lie in there somewhere, but give us some more information first and we'll see...
Was This Post Helpful? 1
  • +
  • -

#3 nikita mehra  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 6
  • Joined: 31-July 12

Re: checklist problem in php

Posted 31 July 2012 - 05:59 PM

when I enter submit, the data must insert in my database. but its failed to enter. THE ERROR IN CHECKBOX and I dunno where is the problem in the coding.. the rest all working.
Was This Post Helpful? 0
  • +
  • -

#4 Bent al-Yemen  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 106
  • Joined: 30-December 09

Re: checklist problem in php

Posted 31 July 2012 - 07:46 PM

have a look at this link
http://www.daniweb.c...checkbox-value#
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3105
  • View blog
  • Posts: 10,905
  • Joined: 08-August 08

Re: checklist problem in php

Posted 31 July 2012 - 08:07 PM

PHP, HTML, Javascrpt, and CSS should not all be in the same file together. It makes debugging difficult.

Organization is critical. Start by putting things into functions. Here are three you could write.
$posts = array("tutor_id", "password", "name", "hp_num", "email_add", "mathF1", "mathF2", "mathF3", "mathF4", "mathF5", "snF1", "snF2", "snF3", "addMathF4", "addMathF5", "phyF4", "phyF5");
$no_error = true;
foreach($posts as $key) {
	if(empty($_POST[$key])) {
		display_warning();
		display_form();
		$error = false;
		break;
	}
}

if($no_error) {
	save_to_db();
}


Was This Post Helpful? 0
  • +
  • -

#6 ZevhEr  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 38
  • Joined: 18-July 09

Re: checklist problem in php

Posted 31 July 2012 - 08:23 PM

mysql_query("INSERT INTO tutor (tutor_id, password,name ,hp_num,email_add,mathF1,mathF2,mathF3,math4,math5,snF1,snF2,snF3,addMathF4,addMathF5,phyF4,phyF5) VALUES ('T$item','$password', '$name','$hp_num','$email_add','$mathF1','$mathF2','$mathF3' ,'$mathF4','$mathF5','$snF1','$snF2','$snF3','$addMathF4','$addMathF5','$phyF4','$phyF5')"); 


Have you check your SQL Query.
Maybe you are inserting into wrong column or column with wrong type.

This post has been edited by ZevhEr: 31 July 2012 - 08:24 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1