Heres my Code Goodluck lol any how the if statement works but always coming up true not false dont understand why

$_POST = valid_post($_POST);
	$i=1;
	$i4=1;
	$result4 = mysql_query("DESCRIBE ".$table2."");
	while($row4 = mysql_fetch_array($result4))
	{
	$test4 = mysql_num_rows(mysql_query("DESCRIBE ".$table2.""));
	if($row4["Field"] == "id")
	{
        print'';
	}
	elseif($row4["Field"] != "id" AND $i4 != $test4)
	{
        $info4 .= '`'.$row4["Field"].'`, ';
	}
	elseif($row4["Field"] != "id" AND $i4 == $test4)
	{
        $info4 .= '`'.$row4["Field"].'`';
	}
	elseif($row4["Field"] == "id" AND $i4 == $test4)
	{
        $info4 .= '`'.$row4["Field"].'`';
	}
	$i4++;
	}
	$query = "SELECT ".$info4." FROM ".$table2." WHERE `require` = '1'";
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result))
	{
	$row = valid_row($row);
	$sql = 'SELECT count(name) AS `counting` FROM '.$table2.' WHERE `require` = "1"';
	$result2 = mysql_query($sql);
	$row2 = mysql_fetch_array($result2);
	$row2 = valid_row($row2);
	$last = $row2["counting"];
	if($row["stype"] == 'normal')
	{
	if($i != $last AND $i > '1')
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0" OR ';$i++;
	}
	elseif($i == '1' AND $i != $last)
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0" OR ';$i++;
	}
	elseif($i == $last AND $i > '1')
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0"';$i++;
	}
	elseif($i == $last AND $i == '1')
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0"';$i++;
	}
	}
	elseif($row["stype"] == 'email')
	{
		if($i > '1' AND $i != $last)
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"] OR ';$i++;
	}
	elseif($i == '1' AND $i != $last)
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"] OR ';$i++;
	}
	elseif($i == $last AND $i > '1')
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"]';$i++;
	}
	elseif($i == $last AND $i == '1')
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"]';$i++;
	}
	}
	}
	if($scheck)
	{
	print'<table>
	<form name="autocfg" action="?p='.$_GET["p"].'&v=1" method="post">';
		$query = "SELECT `title`, `name`, `type`, `default`, `stype`, `require` FROM ".$table2."";
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result))
			{
				$row = valid_row($row);
				if($row["stype"] == "normal" AND $row["require"] = "1")
				{
					if($_POST["".$row["name"].""] < "0")
					{
						print'<tr>
						<td></td>
						<td >'.$row["title"].' is required</td>
						</tr>';
						text(''.$row["title"].'', ''.$row["name"].'', ''.$row["type"].'', ''.$_POST["".$row['name'].""].'', ''.$row["default"].'');
					}
					else
					{
						text(''.$row["title"].'', ''.$row["name"].'', ''.$row["type"].'', ''.$_POST["".$row['name'].""].'', ''.$row["default"].'');
					}
				}
				elseif($row["stype"] == "email" AND $row["require"] = "1")
				{
					if(!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}', stripslashes(trim($_POST["".$row['name'].""])) ) OR $_POST["".$row['name'].""] != $_POST["verify_email"])
					{
						if(!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}', stripslashes(trim($_POST["".$row['name'].""])) ))
						{
						print'<tr>
						<td></td>
						<td>E-mail is not valid</td>
						</tr>';
						text(''.$row["title"].'', ''.$row["name"].'', ''.$row["type"].'', ''.$_POST["".$row['name'].""].'', ''.$row["default"].'');
						}
						elseif($_POST["".$row['name'].""] != $_POST["verify_email"])
						{
						print'<tr>
						<td></td>
						<td>E-mail and Verify E-mail does not match</td>
						</tr>';
						text(''.$row["title"].'', ''.$row["name"].'', ''.$row["type"].'', ''.$_POST["".$row['name'].""].'', ''.$row["default"].'');
						}
					}
					else
					{
						text(''.$row["title"].'', ''.$row["name"].'', ''.$row["type"].'', ''.$_POST["".$row['name'].""].'', ''.$row["default"].'');
					}
				}
				else
				{
					text(''.$row["title"].'', ''.$row["name"].'', ''.$row["type"].'', ''.$_POST["".$row['name'].""].'', ''.$row["default"].'');

				}
			}
			text('', '', 'submit', 'Submit', '');
		print'</form>
				</table>';
	}
	else
	{
		$query = "SELECT `email` FROM `config`";
		$result = mysql_query($query);
		$config2 = mysql_fetch_array($result);
		$config2 = valid_row($config2);
		
		$_POST = valid_row($_POST);
		$email = $_POST["email"];
		$to = "".$config2["email"]."";
		$subject = "".$_POST["subject"]."";
		$body = "".$_POST["name"]."<br />".$_POST["message"]."";
		$headers = "MIME-Version: 1.0 \r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
		$headers .= "From: ".$email."";
		$send = mail($to, $subject, $body, $headers);
		$_POST = valid_post($_POST);
		$i2=1;
		$i3 = 1;
	$result = mysql_query("DESCRIBE ".$table2."");
	while($row = mysql_fetch_array($result))
	{
	$test = mysql_num_rows(mysql_query("DESCRIBE ".$table2.""));
	if($row["Field"] == "id")
	{
        print'';
	}
	elseif($row["Field"] != "id" AND $i3 != $test)
	{
        $info2 .= '`'.$row["Field"].'`, ';
	}
	elseif($row["Field"] != "id" AND $i3 == $test)
	{
        $info2 .= '`'.$row["Field"].'`';
	}
	elseif($row["Field"] == "id" AND $i3 == $test)
	{
        $info2 .= '`'.$row["Field"].'`';
	}
	$i3++;
	}
		$query = "SELECT ".$info2." FROM ".$table2."";
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result))
			{
				$row = valid_row($row);
				$sql = 'SELECT count(id) AS `counting` FROM '.$table2.'';
				$result2 = mysql_query($sql);
				$row2 = mysql_fetch_array($result2);
				$row2 = valid_row($row2);
				if($row["name"] != 'time' AND $i2 != $row2["counting"])
				{
					$values .= '$_POST["'.$row["name"].'"], ';
				}
				elseif($row["name"] != 'time' AND $i2 == $row2["counting"])
				{
					$values .= '$_POST["'.$row["name"].'"]';
				}
				elseif($row["name"] == 'time' AND $i2 == $row2["counting"])
				{
					$values .= ''.time().'';
				}
				elseif($row["name"] == 'time' AND $i2 != $row2["counting"])
				{
					$values .= ''.time().', ';
				}
				$i2++;
			}
$i3 = 1;
$result = mysql_query("DESCRIBE ".$table."");
while($row = mysql_fetch_array($result))
{
	$test3 = mysql_num_rows(mysql_query("DESCRIBE ".$table.""));
	if($row["Field"] == "id")
	{
        print'';
	}
	elseif($row["Field"] != "id" AND $i3 != $test3)
	{
        $info .= '`'.$row["Field"].'`, ';
	}
	elseif($row["Field"] != "id" AND $i3 == $test3)
	{
        $info .= '`'.$row["Field"].'`';
	}
	elseif($row["Field"] == "id" AND $i3 == $test3)
	{
        $info .= '`'.$row["Field"].'`';
	}
	$i3++;
	}
		$query = "INSERT into ".$table." (".$info.") values(".$values.")";
		$result = mysql_query($query);
		print'Thank You for contacting us we will get back to you as soon as possible';
	
	}
Member Avatar for diafol

Phew! That's a lot of code to look at. Have you tried commenting out the unimportant bits (isolating the bits pertaining to the if statement)? Code this long will be difficult for forum members to dissect. Try a shortened version!

You also reference custom functions (valid_post and text) which aren't included, which doesn't help.

The error is this

if($row["stype"] == 'normal')
	{
	if($i != $last AND $i > '1')
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0" OR ';$i++;
	}
	elseif($i == '1' AND $i != $last)
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0" OR ';$i++;
	}
	elseif($i == $last AND $i > '1')
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0"';$i++;
	}
	elseif($i == $last AND $i == '1')
	{
		$scheck .= '$_POST["'.$row['name'].'"] < "0"';$i++;
	}
	}
	elseif($row["stype"] == 'email')
	{
		if($i > '1' AND $i != $last)
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"] OR ';$i++;
	}
	elseif($i == '1' AND $i != $last)
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"] OR ';$i++;
	}
	elseif($i == $last AND $i > '1')
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"]';$i++;
	}
	elseif($i == $last AND $i == '1')
	{
		$scheck .= '!eregi(\'^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}\', stripslashes(trim($_POST["'.$row['name'].'"])) ) OR $_POST["'.$row['name'].'"] != $_POST["verify_email"]';$i++;
	}
	}
	}
	if($scheck)

in this code the if($scheck) is always coming up as false if i put it to true it will not go to the else statement

okay it doesn't see the OR at all in the code I've confirm that

have you tried to echo $scheck to see what it contains if($check) all it means is that the variable holds contents and looking at your code I don't see where you just declare the variable. I see you add to it by $scheck .= .... but never a $scheck = ... You have to declare it before you can add to it.

Fixed Can't share the code yet still in beta process

Member Avatar for diafol
$scheck .= ' 'OR' ';

Do you have code highlighting on your editor? If so I think these lines will show an error. The OR in the middle won't be included in the string. If you need this how about: ' "OR" ' or ' OR ' Sorry mate haven't read your code thoroughly, but this looks a bit odd to me.

I've recently found a great free PHP editor that shows up these things with a red warning in the margin: APTANA.

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.