Re: [PHP] Checking for records + deleting via URL From: AJDIN BRANDIC (abrandic <email protected>)
Date: 11/03/00

1.
You can either set a field as unique when you create a table, this will
(I think) refuse any duplicates . Another way is before INSERT into table
do a SELECT query and check if the value alredy exists ie.

 $query = "SELECT * FROM yourtable where somefield='$formfield'";

if result is one or more then you have a duplicate field.

2. Here is an example but you must make changes to match your table/fields

<?php
// your db connection details

 $query = "SELECT * FROM yourtable ORDER BY something";
 $results = mysql_query($query) or die("Select Failed!");
?>
 <table cellpadding="2" cellspacing="1" border="0" align="center">
   <tr>
        <td align="center">ID</td>
        <td>Date</td>
        <td>some more..</td>
   </tr>
<?php
 <?php while ($result = mysql_fetch_array($results)) { ?>
<tr>
        <td align="center" bgcolor="#99CCCC"><?php echo
$result['id']; ?></td>
        <td bgcolor="#99CCCC"><?php echo $result['date']; ?></td>
        <td bgcolor="#99CCCC"><?php echo $result['some more']; ?></td>
<td valign="middle"><br>
        <form action="somescript.php3" method="POST">
        <input type="hidden" name="record_id" value="<? echo
$supplier['id']; ?>">
        <input type="submit" value="Edit" align="absmiddle">
        </form>
// you cah have another form for delete etc.
        </td>
</tr>

<?php } ?>
</table>
.....

Hope this helps a bit.

Ajdin

On Fri, 3 Nov 2000, =?iso-8859-1?Q?Daniel_Als=E9n?= wrote:

> Hi!
>
> I have two questions:
>
> 1. Im building an administrative tool to add, delete and update records in
> MySQL.
> I need some help on how i can check if there already is a record with a
> identical value as i entered in my form and respond with a error message.
>
> 2. I need to create a link dynamically on each row as im showing the
> database in a table. The link will contain a 'delete'-command.
> How do i add the correct id to the link and what should the syntax of the
> link be?
>
>
> Does anyone have any exmple code or URLs where i can learn something about
> this?
>
> Regards
> ## Daniel Alsén | http://www.eyebee.com #
> ## Innehĺllsbolaget | ICQ: 63006462 #
> ## daniel <email protected> | Fax: +46 8 4100 1650 #
> ## +46 8 4100 1605 | Mob: +46 709 93 57 05 #
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe <email protected>
> For additional commands, e-mail: php-general-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>