Please can you help. I have been trying create a form to insert some data into a database. (I am coding with PHP and MYSQL). When I put any data into the field called enter treatments completed the database gets updated with the treatments_completed column containing a 0 and then a record is made on the line underneath but with a zero in each column which is an int.

In addition I have been trying to check my form so that it goes to an error page if one of the fields has no value but it doesnt seem to do it.

This is my php/mysql code

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


	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
		<link rel="stylesheet" type="text/css" id="change" href="" />
		<title>Laser-clear entry</title>
	</head>
	
	<body>	
	
	<?php
		include ("conn.php");
		$uniqueT=$_POST['uniqueidT'];
		$fnameT=$_POST['fnameT'];
		$snameT=$_POST['snameT'];
		$tottreat=$_POST['tottreatT'];
		$treatcom=$_POST['treatcomT'];
		$ampay=$_POST['ampayT'];
		$filelink=$_POST['filelink'];
		
		/*$uniqueT= mysql_real_escape_string($uniqueT);
		$fnameT= mysql_real_escape_string($fnameT);
		$snameT= mysql_real_escape_string($snameT);
		$tottreatT= mysql_real_escape_string($tottreatT);
		$treatcom= mysql_real_escape_string($treatcomT);
		$ampayT= mysql_real_escape_string($ampayT);
		$filelinkT= mysql_real_escape_string($filelinkT); */
		
		$sqlmm= "INSERT into person_info(unique_number, first_name,surname,total_treatments,treatments_completed,amount_paid,file_link) values ('$uniqueT' , '$fnameT' , '$snameT' , '$tottreat' , '$treatcom' , '$ampay' , '$filelink' )";
		
		if ( $uniqueT == ' ' or $fnameT == ' ' or $snameT == ' ' or $tottreatT == ' ' or $tottreatT == ' ' or $treatcom == ' ' or $ampayT == ' ' or $filelinkT == ' ') 
		{
			echo "error please enter data in all the boxes <br/>";
			echo "<a href='laserclearentry.html'> click here to go back to entry page</a>";
		}
		
		else
		{
		
		mysql_query($sqlmm) or die(mysql_error());
		echo "data successfully entered into the database <br/>";
		echo "<a href='laserclearentry.html'> click here to go back to entry page</a>";
		 
		}
		
		 mysql_close($conn);
	?>

	</body>

</html>

These are the names of the columns in my database

unique_number first_name surname treatments_completed total_treatments amount_paid file_link

you appear to be testing for a space being entered, when you should be testing for an empty field.

Try this instead

<?php
include ("conn.php");

$uniqueT=trim($_POST['uniqueidT']);
$fnameT=trim($_POST['fnameT']);
$snameT=trim($_POST['snameT']);
$tottreat=trim($_POST['tottreatT']);
$treatcom=trim($_POST['treatcomT']);
$ampay=trim($_POST['ampayT']);
$filelink=trim($_POST['filelink']);


if ( $uniqueT == '' OR $fnameT == '' OR $snameT == '' OR $tottreatT == '' OR $tottreatT == '' OR $treatcom == '' OR $ampayT == '' OR $filelinkT == '')

{
echo "error please enter data in all the boxes <br/>";
echo "<a href='laserclearentry.html'> click here to go back to entry page</a>";

/*rest of code here */

trim() will remove any leading or trailing blank spaces, so if there is only blanks, the variable becomes a null, then the tests in the if are for nothing - i.e. that is a set of single quotes, not one double quote. The rest of the code would be the same

you appear to be testing for a space being entered, when you should be testing for an empty field.

Try this instead

<?php
include ("conn.php");

$uniqueT=trim($_POST['uniqueidT']);
$fnameT=trim($_POST['fnameT']);
$snameT=trim($_POST['snameT']);
$tottreat=trim($_POST['tottreatT']);
$treatcom=trim($_POST['treatcomT']);
$ampay=trim($_POST['ampayT']);
$filelink=trim($_POST['filelink']);


if ( $uniqueT == '' OR $fnameT == '' OR $snameT == '' OR $tottreatT == '' OR $tottreatT == '' OR $treatcom == '' OR $ampayT == '' OR $filelinkT == '')

{
echo "error please enter data in all the boxes <br/>";
echo "<a href='laserclearentry.html'> click here to go back to entry page</a>";

/*rest of code here */

trim() will remove any leading or trailing blank spaces, so if there is only blanks, the variable becomes a null, then the tests in the if are for nothing - i.e. that is a set of single quotes, not one double quote. The rest of the code would be the same

Cheers for that. next time I am in work I will try it out.

Any ideas about the The treatments_completed column not taking getting the number from the variable $treatcom ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.