saminsocks Posted June 1, 2009 Share Posted June 1, 2009 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 More sharing options...
Michdd Posted June 1, 2009 Share Posted June 1, 2009 To compare you use '==' not '='. Also, combine variables and constants like this: if($row['category']=="music") { echo $row['alt'] . "<br />"; Link to comment https://forums.phpfreaks.com/topic/160428-parse-error/#findComment-846595 Share on other sites More sharing options...
saminsocks Posted June 1, 2009 Author Share Posted June 1, 2009 Thanks! I was so busy looking for quotes and semicolons I didn't think about == vs =. Is the concatenation also what my problem is in the second set of code? I copied that directly from the book I'm learning from so I figured it would be ok. Link to comment https://forums.phpfreaks.com/topic/160428-parse-error/#findComment-846622 Share on other sites More sharing options...
saminsocks Posted June 1, 2009 Author Share Posted June 1, 2009 After some more testing, it seems my problem is with the $_SERVER['PHP_SELF']. I have tried that line as written, without quotes and with just single quotes and still get a parse error every time. I am running PHP 5.2.9. Link to comment https://forums.phpfreaks.com/topic/160428-parse-error/#findComment-846632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.