Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts

    adding/editing same form

    I have an email form that can have comma separated email addresses. I need to modify my code such that initially if the form does not contain any value, it should let me add email addresses to it. When I enter the web page next time it should display and let me edit the existing email addresses. Here is my code below. Right now it does not insert anything the first time.

    PHP Code:
    <?
    error_reporting
    (E_ALL & ~E_NOTICE);
    $conn mysql_connect('localhost','test','*****') or trigger_error("SQL"E_USER_ERROR);
    $db mysql_select_db('test',$conn) or trigger_error("SQL"E_USER_ERROR);
    //$sql=mysql_query("SELECT * from new_database") or die(mysql_error());
    $getemail=mysql_query("SELECT * from email") or die(mysql_error());
    if(
    mysql_num_rows($getemail) > 0)
    {
       while(
    $getemail_results=mysql_fetch_assoc($getemail))
       {
          
    $getemailadd=$getemail_results['email'];
       }
    }
    else
    {
      
    $getemailadd='';
    }
       if (!isset(
    $_POST['submit']))
       {
       
    ?>
       <b>ADDING A Email</b><br>
       <form action="<?php echo $PHP_SELF;?>" method="post">
       Email:<br> <input type="text" size ="80" name="email" value="<?PHP if(isset($getemailadd)){ echo $getemailadd; } ?>" /><br>
       <input type="submit" name="submit" value="submit" />
       </form>
       <?
       
    }
       else
      {

        
    // Get values from form
        
    $email=$_POST['email'];
        
    //$sql=mysql_query("INSERT into email(email)VALUES('$email')") or die (mysql_error());
        
    $sql=mysql_query("UPDATE email SET email='$email'") or die (mysql_error());
        
    header('Location: index.php');

    }
    ?>
    Last edited by Inigoesdr; 09-20-2011 at 01:35 AM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Try this ... untested, so make a safe copy of your current script ...

    PHP Code:
    <?php
    error_reporting
    (E_ALL & ~E_NOTICE);
    $conn mysql_connect('localhost','test','*****') or trigger_error("SQL"E_USER_ERROR);
    $db mysql_select_db('test',$conn) or trigger_error("SQL"E_USER_ERROR);
    //$sql=mysql_query("SELECT * from new_database") or die(mysql_error());
    $getemail=mysql_query("SELECT * from email") or die(mysql_error());
    if(
    mysql_num_rows($getemail) > 0){
       while(
    $getemail_results=mysql_fetch_assoc($getemail))   {
          
    $getemailadd=$getemail_results['email'];
       }
    }
    else{
      
    $getemailadd='';
    }
       if (
    $_POST['email']){
       
    // Get values from form
        
    $email=$_POST['email'];
        
    //$sql=mysql_query("INSERT into email(email)VALUES('$email')") or die (mysql_error());
        
    $sql=mysql_query("UPDATE email SET email='$email'") or die (mysql_error());
        
    header('Location: index.php');
       }
       else{   
       
    ?>
       <b>ADDING A Email</b><br>
       <form action="<?php echo $PHP_SELF;?>" method="post">
       Email:<br> <input type="text" size ="80" name="email" value="<?PHP if(isset($getemailadd)){ echo $getemailadd; } ?>" /><br>
       <input type="submit" name="submit" value="submit" />
       </form>
       <?php
       
    }


    ?>


    .


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •