ohno Posted February 28, 2013 Share Posted February 28, 2013 Hi, I have a page that was custom written by a developer some time ago, the page has an email entry text area which currently has some form of checking on it but as to how it works I do not know! The code is as follows :- //Add E-mail Address $sql6 = "SELECT email FROM carts WHERE cartid='".$cart."'";$result6 = mysql_query($sql6);$emailaddress = '';while ( $row6 = @mysql_fetch_array($result6, MYSQL_BOTH) ) { $addemail .= ' <form method="post" action="cart2.php" name="emailform"> '; $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; if ( $emailerror != '' ) { $addemail .= '<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> </form> '; if ( $row6['email'] == '' ) { $emailpresent = 0; } else { $emailpresent = 1; } } $addemail .= ' </td> </tr> '; }?> The text input box has a green background, if the email address is invalid the page reloads but an error image appears next to the text box. What I'd also like to do is if this happens change the colour of the text box. Is this possible? I'm not a programmer, just trying to get my way through this. Thanks for any help Quote Link to comment Share on other sites More sharing options...
timothyarden Posted February 28, 2013 Share Posted February 28, 2013 (edited) On PHP Freaks conventionally you should put your code between // code Can you please do that and then I will read over your code. Edited February 28, 2013 by timothyarden Quote Link to comment Share on other sites More sharing options...
timothyarden Posted February 28, 2013 Share Posted February 28, 2013 Yes it is possible Use an if... elseIf it is valid make it green E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; else make it another color E-mail Address: <input type="text" style="background:OTHER COLOR (HEX)" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; Quote Link to comment Share on other sites More sharing options...
ohno Posted February 28, 2013 Author Share Posted February 28, 2013 //Add E-mail Address $sql6 = "SELECT email FROM carts WHERE cartid='".$cart."'"; $result6 = mysql_query($sql6); $emailaddress = ''; while ( $row6 = @mysql_fetch_array($result6, MYSQL_BOTH) ) { $addemail .= ' <form method="post" action="cart2.php" name="emailform"> '; $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; if ( $emailerror != '' ) { $addemail .= '<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> </form> '; if ( $row6['email'] == '' ) { $emailpresent = 0; } else { $emailpresent = 1; } } $addemail .= ' </td> </tr> '; } ?> Sorry, done as above, can you let me know what I need to change? I know nothing about php. Thanks for your time Quote Link to comment Share on other sites More sharing options...
davidannis Posted February 28, 2013 Share Posted February 28, 2013 (edited) Change: $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; if ( $emailerror != '' ) { $addemail .= '<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> to: if ($emailerror =='') $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; else { $addemail .= E-mail Address: <input type="text" style="background:#f00" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> I think that will work. Edited February 28, 2013 by davidannis Quote Link to comment Share on other sites More sharing options...
ohno Posted March 1, 2013 Author Share Posted March 1, 2013 Thanks for your reply, I'll give it a go later today & let you know OT, is PHP a hard language to learn? I know NOTHING about programming but find this interesting, maybe time to get learning but haven't a clue where to start!! Quote Link to comment Share on other sites More sharing options...
ohno Posted March 1, 2013 Author Share Posted March 1, 2013 (edited) OK, i did a find & replace in DW so it looks like this :- //Add E-mail Address $sql6 = "SELECT email FROM carts WHERE cartid='".$cart."'"; $result6 = mysql_query($sql6); $emailaddress = ''; while ( $row6 = @mysql_fetch_array($result6, MYSQL_BOTH) ) { $addemail .= ' <form method="post" action="cart2.php" name="emailform"> '; if ($emailerror =='') $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; else { $addemail .= E-mail Address: <input type="text" style="background:#f00" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> </form> '; if ( $row6['email'] == '' ) { $emailpresent = 0; } else { $emailpresent = 1; } } $addemail .= ' </td> </tr> '; } ?> I now get a server 500 error, log says :- [01-Mar-2013 11:55:26 UTC] PHP Parse error: syntax error, unexpected T_STRING in /home/domainname/public_html/cart2.php on line 868 Edited March 1, 2013 by ohno Quote Link to comment Share on other sites More sharing options...
timothyarden Posted March 2, 2013 Share Posted March 2, 2013 Can you please post numbers along side your code so we know which line is 868? Quote Link to comment Share on other sites More sharing options...
ohno Posted March 2, 2013 Author Share Posted March 2, 2013 Not sure how to post it with line number but in the block of code :- //Add E-mail Address $sql6 = "SELECT email FROM carts WHERE cartid='".$cart."'"; $result6 = mysql_query($sql6); $emailaddress = ''; while ( $row6 = @mysql_fetch_array($result6, MYSQL_BOTH) ) { $addemail .= ' <form method="post" action="cart2.php" name="emailform"> '; $addemail .= ' E-mail Address: <input type="text" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; if ( $emailerror != '' ) { $addemail .= '<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> </form> '; *******LINE 868******* if ( $row6['email'] == '' ) { $emailpresent = 0; } else { $emailpresent = 1; } } $addemail .= ' </td> </tr> '; } ?> <?php Line 868 as above. Thanks Quote Link to comment Share on other sites More sharing options...
ohno Posted March 2, 2013 Author Share Posted March 2, 2013 Change: $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; if ( $emailerror != '' ) { $addemail .= '<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> to: if ($emailerror =='') $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; else { $addemail .= E-mail Address: <input type="text" style="background:#f00" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> I think that will work. Hi, Sorry but since you've edited the post I can't find the block of code using find & replace in DW?? Quote Link to comment Share on other sites More sharing options...
davidannis Posted March 2, 2013 Share Posted March 2, 2013 My edit, if I remember correctly, was just to replace a = in the if (which would make things equal) to a == which checks for equality so I am not sure why that kills the search and replace. Anyway, I tried to find the error. It appears that you have an extra } in your code. Each open curly brace { should be paired with exactly one close curly brace } Since your original post contains one more close than open I'm not sure which one is extra, but I would bet it is one of the last two. Hope that helps. David Quote Link to comment Share on other sites More sharing options...
ohno Posted March 3, 2013 Author Share Posted March 3, 2013 Hi, Thanks for your reply, i'll try some editing on Monday & let you know. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted March 3, 2013 Share Posted March 3, 2013 Search & replace on an entire block of code is not the way to go forward. You need to read the proposed solution, understand it, and then implement the correct version for your code. Just copying and pasting will ensure that you don't learn anything, and further increase the probability of errors quite significantly. Quote Link to comment Share on other sites More sharing options...
davidannis Posted March 3, 2013 Share Posted March 3, 2013 I was going to make the code allow you to input the value of $row['email'] that it pulls from the database and put the code up someplace where you could execute it and in doing so I noticed that there is another issue: in my else: else { $addemail .= E-mail Address: There is a misplaced quote. I tshould be: { $addemail .=' E-mail Address: <input type="text" style="background:#f00" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" /><img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; so, the mismatched curly braces may just be an artifact of where you started and ended your copy. The missing open quote may be the real culprit. Anyway, it is up now try these two links to see how it works: http://businesssellertoolbox.com/temp/test3.php?email=ddd@ccc.com&emailerror=1 http://businesssellertoolbox.com/temp/test3.php?email=ddd@ccc.com&emailerror= Posted code is: <?php //Add E-mail Address //$sql6 = "SELECT email FROM carts WHERE cartid='".$cart."'"; //$result6 = mysql_query($sql6); $emailaddress = ''; $row6['email']=$_GET['email']; $emailerror=$_GET['emailerror']; $addemail .= ' <form method="post" action="cart2.php" name="emailform"> '; if ($emailerror =='') $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; else { $addemail .=' E-mail Address: <input type="text" style="background:#f00" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" /><img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> </form> '; echo $addemail; ?> the lines: $row6['email']=$_GET['email']; $emailerror=$_GET['emailerror']; just take the variables from the url If you still don't understand PM me and I'll try to explain over Skype. Quote Link to comment Share on other sites More sharing options...
ohno Posted March 4, 2013 Author Share Posted March 4, 2013 (edited) Search & replace on an entire block of code is not the way to go forward. You need to read the proposed solution, understand it, and then implement the correct version for your code. Just copying and pasting will ensure that you don't learn anything, and further increase the probability of errors quite significantly. That's all well & good but I know NOTHING about programming! I'm an electrician, if someone asks a question on electrics to me I explain what they need to do. I don't expect them to learn how to rewire an entire house & fully understand all the circuits involved! Yes I'd like to learn a bit of PHP but obviously this is not for me, if a block of code needs changing & find & replace is no use for this I'm already stumped! (to me it's like having a tool that doesn't do what it says, ie, modify a block of code). Edited March 4, 2013 by ohno Quote Link to comment Share on other sites More sharing options...
Solution ohno Posted March 4, 2013 Author Solution Share Posted March 4, 2013 I was going to make the code allow you to input the value of $row['email'] that it pulls from the database and put the code up someplace where you could execute it and in doing so I noticed that there is another issue: in my else: else { $addemail .= E-mail Address: There is a misplaced quote. I tshould be: { $addemail .=' E-mail Address: <input type="text" style="background:#f00" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" /><img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; so, the mismatched curly braces may just be an artifact of where you started and ended your copy. The missing open quote may be the real culprit. Anyway, it is up now try these two links to see how it works: http://businesssellertoolbox.com/temp/test3.php?email=ddd@ccc.com&emailerror=1 http://businesssellertoolbox.com/temp/test3.php?email=ddd@ccc.com&emailerror= Posted code is: <?php //Add E-mail Address //$sql6 = "SELECT email FROM carts WHERE cartid='".$cart."'"; //$result6 = mysql_query($sql6); $emailaddress = ''; $row6['email']=$_GET['email']; $emailerror=$_GET['emailerror']; $addemail .= ' <form method="post" action="cart2.php" name="emailform"> '; if ($emailerror =='') $addemail .= ' E-mail Address: <input type="text" style="background:#cfc" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />'; else { $addemail .=' E-mail Address: <input type="text" style="background:#f00" "border-color": "#0c0" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" /><img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />'; } $addemail .= ' <input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/confirmemail.gif" style="vertical-align:middle" /> </form> '; echo $addemail; ?> the lines: $row6['email']=$_GET['email']; $emailerror=$_GET['emailerror']; just take the variables from the url If you still don't understand PM me and I'll try to explain over Skype. Thanks again for your time with this, i'll take another look later today Quote Link to comment Share on other sites More sharing options...
ohno Posted March 5, 2013 Author Share Posted March 5, 2013 Thanks for all of your help David, it works Quote Link to comment 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.