coding_begins
09-20-2011, 01:29 AM
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.
<?
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');
}
?>
<?
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');
}
?>