cs1h Posted September 27, 2007 Share Posted September 27, 2007 Hi, I have written an email form but I can its not working properly I keep getting errors, the latest being, Parse error: syntax error, unexpected T_STRING in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 49 The form is, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="emailform.php"> <label>Send to</label> <input type="text" name="Email" id="Email" /> <p> <label>From <input type="text" name="From" id="From" /> </label> </p> <p> <label></label><label>Send <input type="submit" name="Send" id="Send" value="Submit" /> </label> </p> <p> </p> </form> <p> <?php mysql_connect("localhost","adsffdser","clfdsfdsd"); mysql_select_db("real") or die("Unable to select database"); $art = $_GET['id']; $sql = "SELECT * FROM items WHERE id=$art"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "There has been a problem with your request please try again."; } else { while($row = mysql_fetch_array($result)) { $Title = $row['Title']; //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$Email; $mail_from=$From; $mail_sub=Please read this; $mail_mesg=You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")) echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } ?> </p> </body> </html> Does anyone know why this form won't work? All help is appriciated, Cheers Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/ Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 Put single or double quotes around: $mail_sub and $mail_mesg Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356640 Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Share Posted September 27, 2007 also he is missing close brackets <?php mysql_connect("localhost","adsffdser","clfdsfdsd"); mysql_select_db("real") or die("Unable to select database"); $art = $_GET['id']; $sql = "SELECT * FROM items WHERE id=$art"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "There has been a problem with your request please try again."; } else { while($row = mysql_fetch_array($result)) { $Title = $row['Title']; //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$Email; $mail_from=$From; $mail_sub=Please read this; $mail_mesg=You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")) echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } } } ?> also shoould have quotes around your messages <?php mail_sub="Please read this"; $mail_mesg= echo"You have been recomended to read the article";echo $Title;echo "on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356644 Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 Closing brackets? All of his brackets defined variables are ended and closed. Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356651 Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Share Posted September 27, 2007 no they arent they were left open might wanna double check there i used jedit and it found 3 missing close brackets Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356653 Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 Oh, you mean braces. Brackets !== Braces Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356654 Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Share Posted September 27, 2007 oh scuse me braces then i meant } <------ those things Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356655 Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 Yes, I know what you meant. Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356664 Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Share Posted September 27, 2007 i know you did but i was confusing myself between braces and brackets Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356666 Share on other sites More sharing options...
cs1h Posted September 27, 2007 Author Share Posted September 27, 2007 Hi I made those changes but its still coming up with the same error, Parse error: syntax error, unexpected T_STRING in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 49 Could it have anything to do with the form being included in the same page, I'm still new to php and not sure what to do. Thanks for the help so far, Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356704 Share on other sites More sharing options...
BlueSkyIS Posted September 27, 2007 Share Posted September 27, 2007 please repost your updated code. thanks i know you did but i was confusing myself between braces and bracket i didn't even know they are called braces. i worked with British developers for a number of years where i learned to call them "curly brackets". doh! Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356730 Share on other sites More sharing options...
cs1h Posted September 27, 2007 Author Share Posted September 27, 2007 Hi, This is the updated form, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="frmsendmail" method="post" action="emailform.php" onSubmit="return ValidationForm()"> <label>Send to</label> <input type="text" name="Email" id="Email" /> <p> <label>From <input type="text" name="From" id="From" /> </label> </p> <p> <label></label><label>Send <input type="submit" name="Send" id="Send" value="Submit" /> </label> </p> <p> </p> </form> <p> <?php mysql_connect("localhost","rere","rere"); mysql_select_db("real") or die("Unable to select database"); $art = $_GET['id']; $sql = "SELECT * FROM items WHERE id=$art"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "There has been a problem with your request please try again."; } else { while($row = mysql_fetch_array($result)) { $Title = $row['Title']; //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$Email; $mail_from=$From; $mail_sub="Please read this"; $mail_mesg= echo"You have been recomended to read the article";echo $Title;echo "on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it."; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")) echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } } } ?> </p> </body> </html> Cheers Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356741 Share on other sites More sharing options...
BlueSkyIS Posted September 27, 2007 Share Posted September 27, 2007 $mail_mesg is invalid syntax, should be more like: $mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it."; also, your href isn't valid without http://, and you should quote your URLs, so this is better: $mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href='http://www.myroho.com/more.php?id=$art'>here</a> to read it."; Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356745 Share on other sites More sharing options...
cs1h Posted September 27, 2007 Author Share Posted September 27, 2007 Hi, I made the changes so it now looks like this, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="frmsendmail" method="post" action="emailform.php" onSubmit="return ValidationForm()"> <label>Send to</label> <input type="text" name="Email" id="Email" /> <p> <label>From <input type="text" name="From" id="From" /> </label> </p> <p> <label></label><label>Send <input type="submit" name="Send" id="Send" value="Submit" /> </label> </p> <p> </p> </form> <p> <?php mysql_connect("localhost","arerteer","crreord"); mysql_select_db("real") or die("Unable to select database"); $art = $_GET['id']; $sql = "SELECT * FROM items WHERE id=$art"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "There has been a problem with your request please try again."; } else { while($row = mysql_fetch_array($result)) { $Title = $row['Title']; //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$Email; $mail_from=$From; $mail_sub="Please read this"; $mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it."; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")) echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } } } ?> </p> </body> </html> It gets further now because it actually shows the form but when I go to send it it gives me the error, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 36 There has been a problem with your request please try again. Any ideas why, Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356751 Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Share Posted September 27, 2007 <?php $conn=mysql_connect("localhost","arerteer","crreord"); mysql_select_db("real",$conn) or die("Unable to select database"); while($row = mysql_fetch_assoc($result)) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356774 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 also change $art = $_GET['id']; to if( !isset($_GET['id']) ) exit("Nothing Selected"); // error capture $art = (int)$_GET['id']; //clean Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356782 Share on other sites More sharing options...
cs1h Posted September 27, 2007 Author Share Posted September 27, 2007 Hi, thanks for the reply, I changed the php to this, <?php $conn=mysql_connect("localhost","adder","clifford"); mysql_select_db("real",$conn) or die("Unable to select database"); if( !isset($_GET['id']) ) exit("Nothing Selected"); // error capture $art = (int)$_GET['id']; //clean $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "There has been a problem with your request please try again."; } else { while($row = mysql_fetch_assoc($result)) { $Title = $row['Title']; //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$Email; $mail_from=$From; $mail_sub="Please read this"; $mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it."; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")) echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } } } ?> But I now get the error, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 37 There has been a problem with your request please try again. and when I go to send the email it says, Nothing Selected Cheers Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356791 Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Share Posted September 27, 2007 where is $sql defined? Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356794 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 true you seam to of taken it out mysql_select_db("real",$conn) or die("Unable to select database"); if( !isset($_GET['id']) ) exit("Nothing Selected"); // error capture $art = (int)$_GET['id']; //clean $sql = "SELECT * FROM items WHERE id=$art"; //ADD BACK IN as for the email not working, your link to the email MUST have ?id=number or ie will fails hence the error capture Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356795 Share on other sites More sharing options...
cs1h Posted September 27, 2007 Author Share Posted September 27, 2007 Thanks for the help, I changed that and the main error went. As for the second one about 'Nothing Selected', when the form comes up it has the ?id=number but I think when you submit the form it looses it before it is procesed. Any ideas how I could keep it? Thanks, Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356802 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 either add it to the action ie echo "<form action='?ID={$_GET['ID']}' >"; or add a hidden field or <input type="hidden" name="ID" value="<?php echo $_GET['ID'];?>"> Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356806 Share on other sites More sharing options...
cs1h Posted September 27, 2007 Author Share Posted September 27, 2007 Hi, Sorry this may be a dumb question but how do I add it to the action, the form title being, <form name="frmsendmail" method="post" action="emailform.php" onSubmit="return ValidationForm()"> Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356811 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 try this <?php echo '<form name="frmsendmail" method="post" action="emailform.php?ID='.$_GET['ID'].'" onSubmit="return ValidationForm()">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356813 Share on other sites More sharing options...
cs1h Posted September 27, 2007 Author Share Posted September 27, 2007 Hi, I made the changes but its still not working, My full code now is, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo '<form name="frmsendmail" method="post" action="emailform.php?ID='.$_GET['ID'].'" onSubmit="return ValidationForm()">'; ?> <label>Send to</label> <p> <input type="text" name="Email" id="Email" /> </p> <p> <label>From <input type="text" name="From" id="From" /> </label> </p> <p> <label></label><label>Send <input type="submit" name="Send" id="Send" value="Submit" /> </label> </p> <p> </p> </form> <p> <?php $conn=mysql_connect("localhost","adder","clifford"); mysql_select_db("real",$conn) or die("Unable to select database"); if( !isset($_GET['id']) ) exit("Nothing Selected"); // error capture $art = (int)$_GET['id']; //clean $sql = "SELECT * FROM items WHERE id=$art"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "There has been a problem with your request please try again."; } else { while($row = mysql_fetch_assoc($result)) { $Title = $row['Title']; //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$Email; $mail_from=$From; $mail_sub="Please read this"; $mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it."; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")) echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } } } ?> </p> </body> </html> Any ideas why this isn't working? Thanks for all the help so far, Colin Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356822 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 oops should be lower case id ie action="emailform.php?id='.$_GET['id'].'" But in anycase why you using the ID field? the form doesn't pass it ? infact how does the form know who to send the email to ? Quote Link to comment https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.