Hi all, I have finished my php for dummis book and have few errors that I could not fix.

I show u my first example.

<?php

/* Program: showpets.php
   Description: Displays all the pets in a category. 
   Category is passed in a variable from a form.
   The Information for each pet is displayed in a 
   single line, unless the pet comes in more than one color.
   If the pet comes in colors, a single line is displayed 
   without pictures, is displayed following the single line.
   Small pictures are displayed, which are links to larger pictures
 */
 
 
?>

<html>
 <head><title>Pet Types</title></head>
 <body>
 
 <?php
 
 require_once("config.php");
 
 //select pets of the given type
 
 $query="SELECT * FROM pets WHERE petcatalog=\"{_POST['interest']_\"";
 $result = mysqli_query($cxn, $query)
 or die ("could not execute query");
 
 //display  results in a table
 echo "<table cellspacing='10' border='0' cellpadding='0' width='100%'>";
 echo "<tr><td colspan='5' style='text-align: right'>
 		click on any picture to see larger version.<hr /></td></tr>\n";
		
		while($row = mysqli_fetch_assoc($result))
		{
			$f_price = number_format ($row['price'], 2);
			//checks wheather pet will come in colors
			$query = "SELECT * FROM Color 
						WHERE petName ='{$row['petName']}'";
						
						$result2 = mysqli_query($cxn, $query)
						or die (mysqli_error($cxn));
						$ncolors = mysqli_num_rows($result2);

		//display row of each pet
		
		echo "<tr>\n"; 
		echo " <td> {row['petID']}</td>\n";
		echo  "<td style='font-weight:bold;
				font-size:1.1em'> {$row['petName']}</td>\n";
		echo  "<td>{$row['petDescription']}</td>\n";
		
		//display picture if pet does not come in colors
		
		if($ncolors <= 1)
		{
			echo"<td><a href='../images/{$row['pix']}'
			border='0' width='100' height='80' />
			</a></td>\n";
			
		}

	echo "<td align='center'>\$$f_price</td>\n</tr>\n";
	
	//display row for each color
	
	if($ncolors > 1)
		{
			while ($row2 = mysqli_fetch_assoc($result2))
			{
			  echo "<tr> <td colspan=2> &nbsp;</td>
			  		<td>{$row2['petColor']}</td>
					<td><a href='../images/{row2['pix']}'
						border='0'>
						 <img src='../images/{$row2['pix']}'
						 	border='0' width='100'
							height='80' /></a></td>\n";
						 }
						 
						 echo"<tr><td colspan='5'><hr /></td></tr>\n";
						
			        }
					echo "</table>\n";
					echo "<div style='text-align:center'>
							<a href='petcatalog.php'>
							<h3>See more pets</h3></a></div>";
						

?>
</body></html>

error 1:

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\petstore2\showpets.php  on line 92

Second working code

<?php

/* Program: login_reg.php
   Description: Main application script for the user login
   application. It provides two options:
   1. login using an existing username.
   2. register  a new username
   
 */
 
 session_start();
 switch(@$_POST['Button'])
 { 
   case "Log in";
   require_once("config.php");
   
   $sql = "SELECT loginName FROM Member WHERE loginName='$_POST[fusername]'";
   $result = mysqli_query($cxn, sql)
   or die("query F'ing died: fusername");
   
   $num = mysqli_num_rows($result);
   
   if ($num > 0 ) //login name was found 
   {
	   
   $sql = "SELECT loginName FROM Member WHERE loginName='$_POST[fusername]'
   AND password=md5('$_POST[fpassword]')";
   
   $result2 = mysqli_query($cxn, sql)
   or die("query F'ing died: fpassword");
   
   $num2 = mysqli_num_rows($result2);
   
   if ($num2 > 0) //password matches
   {
	   $_SESSION['auth']="yes";
	   $_SESSION['logname'] =$_POST['fusername'];
	   $sql = "INSERT INTO Login(loginName, LoginTime)
	   		   VALUES ($_SESSION[logname]', NOW())";
		$result = mysqli_query($cxn, $sql)
			or die("Query dead: insert");
			
			header("location: secretpage.php");
   }
   	else// password does not match 
	{
		$message_1="The Login Name, '$_POST[fusername]'
			exists, but you have not entered the correct
			password! Please try again. ";
			
			$fusername=strip_tags(trim($_POST['fusername']));
			include("login_form.inc");
    }
  
 }
 
 
 else// login name not found
 {
	 $message_1 =" The user name you entered does  not exist! Please try again";
	 include("login_form.inc");
 }
 
 break;
 
 case "Register":
 //checks for blanks
 foreach($_POST as $field => $value)
		{
		
	       if($field != "fax")
		   {
			   if(empty($value))
			   
			   {
				   $blanks[] = $field;
			   }
			   else
			   
			   {
				   $good_data[$field] = strip_tags(trim($value));
			   }
		   }
		}
		
		if(isset($blanks))
		{
			$message_2 = "The following fields are blank.
							Please enter the required information: ";
							foreach($blanks as $value)
							{
								$message_2.="$value, ";
							}
			       extract($good_data);
				   include("login_form.inc");
				   exit();
				   
		}
		
		//validate data
		
		foreach($_POST as $field => $value)
		{
			if(!empty($value))
			{
				if(preg_match("/name/i",$field) and
				!preg_match("/user/i",$field) and
				!preg_match("/log/i",$field))
				
			{
					   
					if(!preg_match("/^[A-Za-z' -]{1,50}$/", $value))
					{
						$errors[] ="$value is not a valid name.";
					}
				}
             
				
				if(preg_match("/street/i",$field) or
				!preg_match("/addr/i",$field) or
				!preg_match("/city/i",$field)) 
				
				{					
				if(!preg_match("/^[A-Za-z0-9., -] {1,50}$/",$value))
				
				{
					$errors[] = "$value is not a valid address or city.";
				}
				
			}
			
			if(!preg_match("/state/i", $field))
			{
				if(!preg_match("/^[A-Z][A-Z]$/", $value))
				{
					$errors[] = "$value is not valid state code.";
				}
			}
			
			if(!preg_match("/email/i", $field))
			{
				if(!preg_match("/^.+@.+\\..+$/", $value))
				{
					$errors[] = "$value is not valid email addr.";
				}
			}
			
			if(!preg_match("/zip/i", $field))
			{
				if(!preg_match("/^[0-9]{5}(\-[0-9]{4})?$/", $value))
				{
					$errors[] = "$value is not valid zipcode.";
				}
			}
			
			if(!preg_match("/phone/i", $field) or
			preg_match("/fax/i", $field))
			{
				if(!preg_match("/^[0-9)[xX -] {7, 20}$/", $value))
				{
					$errors[] = "$value is not valid phone no.";
				}
			}
		}// end if not empty 
	}
	
	foreach($_POST as $field => $value)
	{
		$$field = strip_tags(trim($value));
	}
			
			if(@is_array($errors))
			{
				$message_2 .= $value. " Please try again<br />";
			}
		
		include("login_form.inc");
		exit();
 }// ends if errors are not found
 
 	//check to see if username already exists
	$sql = "SELECT loginName FROM Member WHERE loginName'";
	$result = mysqli_query($cxn, $sql)
			or die ("Query died: loginName");
			
		$num = mysqli_num_rows($result);
		if($num > 0)
		 {
			 $message_2 = "$loginName already used. Select another User Name.";
			 include("login_form.inc");
			 exit();
		 }// end if username already exists 
		 
		 else// Add new member to databse
		 {
			 $sql = "INSERT INTO Member (loginName, createData, password,
										 firstName, lastName, street, city,
										 state, zip, phone, fax, email) VALUES
			 							 ('$loginName', NOW () ,md5 ('$password'),
										  '$firstName', '$lastName', '$street', '$city',
										  '$state', '$zip', '$phone' , '$fax', '$email')";
				mysqli_query($cxn, $sql);
				$_SESSION['auth'] = "yes";
				$_SESSION['logname'] = $loginName;
				//send email to new Customer
				$emess = "You have succesfully registered. ";
				$emess .= "Your new username and password are: ";
				$emess .= "\n\n\t$loginName\n\t";
				$emess .= "$password \n\n";
				$emess .= "We appreciate your interest.  \n\n";
				$emess .= "if you have any questions or problems, ";
				$emess .= "email service@ourstore.com";
				$subj .= "Your new customer registration";
				# mailsend=mail("$email", "subj","$emess");
				header("Location: secretpage.php");
		 }
		 
		 break;
		 
		 default:
		  include("login_form.inc");
		  
		 }
			   
	 
 
	   
 ?>
<head>
<title>Login </title>
</head>

<body>
</body>
</html>

error 2:

Parse error: syntax error, unexpected T_DEFAULT in C:\xampp\htdocs\petstore2\login_reg.php  on line 222

If any one of you have any method or I did some misstypo, is it ok to show it in an example I would appreciate this more as Im very new to php and programming is not a strong point :).

thanks

for error 1 : you need to close while loop brace }.
for error 2 : switch case ends in line : 304. But you have written default in line no : 345. So remove unexpected default there. or re arrange your switch cases.

Hey thanks for replying, error 1 seems to to be fixed but query was not executed, the book does not give me a good die message that enables to show an error :(

error 2: I get this

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\petstore2\login_reg.php:3) in C:\xampp\htdocs\petstore2\login_reg.php  on line 13

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\petstore2\login_reg.php:3) in C:\xampp\htdocs\petstore2\login_reg.php on line 13

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\petstore2\login_reg.php on line 189
Query died: loginName

Pretty major errors and not have a clue what this is :(

thanks

put ob_start(); in the first line of your page..

I still get the same errors :(.

<?php

/* Program: login_reg.php
   Description: Main application script for the user login
   application. It provides two options:
   1. login using an existing username.
   2. register  a new username
   
 */
 ob_start();
 
 session_start();
 switch(@$_POST['Button'])
 { 
   case "Log in";
   require_once("config.php");
   
   $sql = "SELECT loginName FROM Member WHERE loginName='$_POST[fusername]'";
   $result = mysqli_query($cxn, sql)
   or die("query F'ing died: fusername");
   
   $num = mysqli_num_rows($result);
   
   if ($num > 0 ) //login name was found 
   {
	   
   $sql = "SELECT loginName FROM members WHERE loginName='$_POST[fusername]'
   AND password=md5('$_POST[fpassword]')";

Just to be sure if I put it in the wrong place and what does ob_start function do :)

thanks

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.