Jump to content

Parse error


saminsocks

Recommended Posts

I'm sure you see these all the time, but I'm having a hard time figuring out my parse error for two pieces of code. I've searched them several times and can't seem to find a misplaced " or ; so I'm hoping a more knowledgeable set of eyes will be able to find it. I've programmed for awhile but this is my first try at PHP.

 

Here is the first code:

<?php
		while($row = mysql_fetch_array($rs)) {

			if($row['category']="music") {
				echo("$row['alt'] <br />");
			}

		}
	?>

 

and here is the second:

 

	<?php
	$username = $_POST['username'];
	$useraddr = $_POST['useraddr'];
	$comments = $_POST['comments'];
	$sent = $_POST['sent'];

	$form ="<form action=\"$_SERVER['PHP_SELF']\" method=\"post\">";
	$form. ="Name: <input type=\"text\" name=\"username\" size=\"30\" value=\"$username\"/><br /><br />";
	$form. ="Email: <input type=\"text\" name=\"useraddr\" size=\"30\" value=\"useraddr\" /><br /><br />";
	$form. ="Message: <br /><textarea name=\"comments\" cols=\"35\" rows=\"5\">$comments</textarea><br />";
	$form. ="<input type=\"submit\" name=\"sent\" value=\"Send Email\" />";
	$form. ="</form>";

	if($sent) {
		$valid=true;

		if(!$username) {
			$errmsg.="Please provide your name: <br />";
			$valid = false;
		}

		if(!$useraddr) {
			$errmsg.="Please provide an email address: <br />";
			$valid = false;
		}
		else {
			$useraddr = trim($useraddr);
			$_name = "/^l[-!#$%&\'*+\\.\/0-9=?A-Z^_'{\}~]+";
			$_host = "([-0-9A-Z]+\.)+";
			$_tlds = "([0-9A-Z]){2,4}$/i";
			if(!preg_match($_name."@".$_host.$_tlds,$useraddr) {
			$errmsg.="The email address you entered has an incorrect format. <br />";
			$valid = false;
			}
		}

		if(!$comments) {
			$errmsg.="Please leave me a message: <br />";
			$valid = false;
		}

	}

	if($valid !=true) {
		echo( $errmsg . $form );
	}
	else {
		$to = "[email protected]";
		$re = "Website message from $username";
		$msg = $comments;
		$headers = "From: $useraddr \r\n";

		if( mail( $to, $re, $msg, $headers ) {
			echo("Thank you, $username. I appreciate your message and will get back to you as soon as I can. In the meantime, feel free to explore more of my website.");
		}
	}
?>

 

 

The lines in question are lines 5 and 7, respectively. Thank you for any help you can offer. I have a feeling they may be similar problems, I just don't know enough to recognize them.

Link to comment
https://forums.phpfreaks.com/topic/160428-parse-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.