<?php
@ $db = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('database');
$result = mysql_query("select * from contact ORDER BY id ASC");
$num_results = mysql_num_rows($result);
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
if ($num_results == 0)
{
echo 'There are no records in your database. Please <a href="insert.php" class="rollmain">insert</a> a record into your database.';
exit;
}
if(!$Submit)
{
while($r = mysql_fetch_array($result))
{
$id=$r["id"];
$Company=$r["Company"];
$Name=$r["Name"];
$Address=$r["Address"];
$City=$r["City"];
$State=$r["State"];
$Zip=$r["Zip"];
$Country=$r["Country"];
$Phone=$r["Phone"];
$Fax=$r["Fax"];
$URL=$r["URL"];
$Email=$r["Email"];
$Service=$r["Service"];
$WebDesignList=$r["WebDesignList"];
$OtherMediaList=$r["OtherMediaList"];
$Balance=$r["Balance"];
$Comments = trim($r["Comments"]);
?>
<input type="radio" checked name="id" value="<?php echo $id;?>">
<?php
if(!$Company)
{
echo '';
}
else
{
echo '<b>'.$Company.'</b><br />';
} ?>
<?php
if(!$Name)
{
echo '';
}
else
{
echo '<b>'.$Name.'</b><br />';
} ?>
<?php
if(!$Address)
{
echo '';
}
else
{
echo $Address.'<br />';
} ?>
<?php
if(!$City)
{
echo '';
}
else
{
echo $City.',';
} ?>
<?php
if(!$State)
{
echo '';
}
else
{
echo $State;
} ?>
<?php
if(!$Zip)
{
echo '';
}
else
{
echo $Zip;
} ?>
<?php
if($City || $State || $Zip)
{
echo '<br />';
}
else
{
echo '';
} ?>
<?php
if(!$Country)
{
echo '';
}
else
{
echo '<b>Country:</b> '.$Country.'<br />';
} ?>
<?php
if(!$Phone)
{
echo '';
}
else
{
echo '<b>Phone:</b> '.$Phone.'<br />';
} ?>
<?php
if(!$Fax)
{
echo '';
}
else
{
echo '<b>Fax:</b> '.$Fax.'<br />';
} ?>
<?php
if(!$URL)
{
echo '';
}
else
{
echo '<b>URL:</b> <a href="http://www.'.$URL.'" class="rollmain" target="_blank">'
.$URL.'</a><br />';
} ?>
<?php
if(!$Email)
{
echo '';
}
else
{
echo '<b>Email:</b> <a href="mailto:'.$Email.'" class="rollmain">'
.$Email.'</a><br />';
} ?>
<?php
if(!$Service)
{
echo '';
}
else
{
echo '<b>'.$Service.':</b>';
} ?>
<?php
if(!$WebDesignList | !$Service)
{
echo '';
}
else
{
echo $WebDesignList.'<br />';
} ?>
<?php
if(!$OtherMediaList | !$Service)
{
echo '';
}
else
{
echo $OtherMediaList.'<br />';
} ?>
<?php
if(!$WebDesignList && !$OtherMediaList)
{
echo '<br />';
}
else
{
echo '';
} ?>
<?php
if(!$Balance)
{
echo '';
}
else
{
echo '<b>Outstanding Balance:</b> $'.$Balance;
} ?>
<?php
if(!$Comments)
{
echo '';
}
else
{
echo '<b>Comments:</b> '.$Comments;
} ?>
<br /><br />
<?php
}
?>
<input type="submit" name="Submit" value="Update">
<?php
}
?>
<?php
if($Submit)
{
if (!$Update)
{
$sql = "SELECT * FROM contact WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<table align="left">
<tr>
<td>
<input type="hidden" name="id" value="<?php echo $myrow["id"]; ?>">
<b>Company</b>
</td>
<td colspan="3">
<input type="text" name="Company" value="<?php echo $myrow["Company"]; ?>" size="30">
<b>Name:</b>
<input type="text" name="Name" value="<?php echo $myrow["Name"]; ?>" size="28">
</td>
</tr>
<tr>
<td>
<b>Address:</b>
</td>
<td colspan="3">
<input type="text" name="Address" value="<?php echo $myrow["Address"]; ?>" size="30">
<b>City:</b>
<input type="text" name="City" value="<?php echo $myrow["City"]; ?>" size="30">
</td>
</tr>
<tr>
<td>
<b>State:</b>
</td>
<td colspan="3">
<input type="text" name="State" value="<?php echo $myrow["State"]; ?>" size="15">
<b>Zip:</b>
<input type="text" name="Zip" value="<?php echo $myrow["Zip"]; ?>" size="10">
<b>Country:</b>
<input type="text" name="Country" value="<?php echo $myrow["Country"]; ?>" size="20">
</td>
</tr>
<tr>
<td>
<b>Phone:</b>
</td>
<td colspan="3">
<input type="text" name="Phone" value="<?php echo $myrow["Phone"]; ?>" size="15">
<b>Fax:</b>
<input type="text" name="Fax" value="<?php echo $myrow["Fax"]; ?>" size="15">
</td>
</tr>
<tr>
<td>
<b>URL:</b>
</td>
<td colspan="3">
<input type="text" name="URL" value="<?php echo $myrow["URL"]; ?>" size="25">
<b>Email:</b>
<input type="text" name="Email" value="<?php echo $myrow["Email"]; ?>" size="30">
</td>
</tr>
<tr>
<td>
<b>Service:</b>
</td>
<td colspan="3">
<select name="Service" class="textarea">
<option selected>
<?php echo $myrow["Service"]; ?><option>
<option>Web Design<option>Other Media</select>
<b>Outstanding Balance:</b>$
<input type="text" name="Balance" value="<?php echo $myrow["Balance"]; ?>" size="5">
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3" valign="bottom">
<b>Web Design Service:</b>
<select name="WebDesignList" class="textarea">
<option selected><?php echo $myrow["WebDesignList"]; ?><option>
<option>Reconstruction<option>Basic<option>High Tech</select>
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3" valign="bottom">
<b>Other Media Service:</b>
<select name="OtherMediaList" class="textarea">
<option selected><?php echo $myrow["OtherMediaList"]; ?><option>
<option>PowerPoint Presentations<option>Mass-Mailings<option>Business Cards
<option>Invoices<option>Other</select>
</td>
</tr>
<tr>
<td>
<b>Comments:</b>
</td>
<td colspan="3">
<textarea name="Comments" class="bodytext" style="width:225" rows="3" cols="55">
<?php echo $myrow["Comments"]; ?>
</text>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<input type="hidden" name="Submit" value="Update">
<input type="submit" name="Update" value="Save">
<input type="submit" name="Update" value="Delete">
<input type="submit" name="Update" value="Cancel">
</td>
</tr>
</table>
<?php
}
if($Update == 'Save')
{
$sql = "UPDATE contact SET Company='$Company', Name='$Name', Address='$Address', City='$City', State='$State', Zip='$Zip', Country='$Country', Phone='$Phone', Fax='$Fax', URL='$URL', Email='$Email', Service='$Service', WebDesignList='$WebDesignList', OtherMediaList='$OtherMediaList', Balance='$Balance', Comments='$Comments' WHERE id='$id'";
$result = mysql_query($sql);
if($result)
{
echo '<p class="bodytext" align="center"><h4>Record updated!</h4>The record for '.$Company.' was successfully saved.<br /> Click <a href="access.php" class="rollmain">here</a> to go back.</p><br />';
}
if(!$result)
{
echo '<p class="bodytext" align="center"><h4>Record not updated!</h4>The record for '.$Company.' was not successfully saved.<br /> Click <a href="access.php" class="rollmain">here</a> to go back.</p><br />';
}
}
if($Update == 'Delete')
{
$sql = "DELETE FROM contact WHERE id='$id'";
$result = mysql_query($sql);
if($result)
{
echo '<p class="bodytext" align="center"><h4>Record deleted!</h4>The record for '.$Company.' was successfully deleted.<br /> Click <a href="access.php" class="rollmain">here</a> to go back.</p><br />';
}
if(!$result)
{
echo '<p class="bodytext" align="center"><h4>Record not deleted!</h4>The record for '.$Company.' was not successfully deleted.<br /> Click <a href="access.php" class="rollmain">here</a> to go back.</p><br />';
}
}
if($Update == 'Cancel')
{
echo '<p class="bodytext" align="center"><h4>Update cancelled!</h4>The update for the '.$Company.' record was canceled.<br /><br />Click <a href="access.php" class="rollmain">here</a> to go back.</p><br />';
}
?>
<?php
}
mysql_close($db);
?>
[\php]