Jump to content

email text box help


ohno
Go to solution Solved by ohno,

Recommended Posts

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 :)

 

Link to comment
Share on other sites

Yes it is possible

Use an if... else
If 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.'" />';
Link to comment
Share on other sites

 

//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 :)

Link to comment
Share on other sites

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 by davidannis
Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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 by ohno
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by ohno
Link to comment
Share on other sites

  • Solution

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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