Jump to content

Archived

This topic is now archived and is closed to further replies.

witham

amending duplicate entries

Recommended Posts

I would really appreciate some help with this problem.

I have a database that allows valid duplicate entries but I also wish to allow users to amend these entries all at once. At the moment I have two select boxes that identifies the information but it shows all entries even duplicates, I really only want the user to see the duplicates only once an be able to amend all of them.

This is the data capture form:

[code]<?
$dbuser  = ''; // your database server user name
$dbhost  = 'localhost'; // name of the sql server
$dbpass  = ''; // your database server password
$dbname  = ''; // the name of the database to connect to

$connection = mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error());
mysql_select_db($dbname, $connection) or die (mysql_error());


include 'baaSelect.php';

$sel = new baaSelect();
$sel->addSelect('manufacturer', 'man', 'manid', 'manname', '', 1, '- MANUFACTURER -');
$sel->addSelect('product', 'prodname', 'prodno', 'prodequiv', 'manno', 1, '- PRODUCT -');


?>

//$sel->addSelect('product', 'prodname', 'prodno', 'proddesc', 'manno', 1, '- PRODUCT -');

<title>Add Prod</title>
</head>
<table align = "center" border=0>
<tr>
<td colspan = 3 align = "center"><table width="100" border="0" cellspacing="10" cellpadding="10">
  <tr>
    <th scope="row"><img src="car.jpg" width="150" height="150"></th>
    <td><img src="gears.jpg" width="150" height="150"></td>
    <td><img src="wheel.jpg" width="150" height="150"></td>
    <td><img src="metalworking.jpg" width="150" height="150"></td>
    </tr>
</table></td></tr>

<!-- open the form and send the data to "weld2.php" for processing-->

<form action="doamendequiv.php" method="get">
<hr>
<tr><td colspan = 3><h2 align = "center"><b>PRODUCT AMENDMENTS</b></h2></td><tr>
<br>
<br>
<br>
<br
<tr><td colspan = 2><h3 align=center>This screen allows users with the appropriate password to amend products from the database</h3></td></tr>


<?php $sel->makeScript() ?>

</head>

<body>
    <form>
  <table align = "center">
  <tr>
      <td>
        MANUFACTURER
      </td>
      <td>
        <?php $sel->makeSelect('manufacturer'); ?>
      </td>
  </tr>
  <tr>
      <td>
        CURRENT PRODUCT NAME
      </td>
      <td>
        <?php $sel->makeSelect('product'); ?>
      </td>
  </tr>
  <tr>
      <td>
NEW PRODUCT NAME
      </td>
      <td><input type text name="newprod">
      </td>
  </tr>

</table>
<input type="submit" name="submit" value="AMEND THE PRODUCT">
</form>[/code]

and this is the data processing form:

[code]if (empty($newprod)){ 
header("Location: amendprod.php");
die ("opps"); 
}

$dbuser  = ''; // your database server user name
$dbhost  = 'localhost'; // name of the sql server
$dbpass  = ''; // your database server password
$dbname  = ''; // the name of the database to connect to

// the sql amend statement

$sqlAMEND = "UPDATE prodname SET
  prodequiv = '$newprod' where
  '$product' = prodno
  and prodno = prodid;";

$sqlAMEND = strtoupper($sqlAMEND);

//put in the sql statement that will display the results

$sqlSELECT = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv
FROM man, produse, prodname where manno = manid
and '$manufacturer' = manno
and '$product' = prodno  
and prodid = useid
                and manno = MANID
order by MANNAME;";



// mysql_connect connects to the database server and returns a link to the the resource
$dblink = @mysql_connect("$dbhost","$dbuser","$dbpass")
or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n");

// mysql_select_db selects a database to use on the database server pointers to by $dblink
// the @ sign before the command supresses any error messages
@mysql_select_db ($dbname , $dblink)
or die ("<p><b>Could not connect to database ($dbname)</b></p>\n");

// now execute the next query to insert the data into the table

$result  = mysql_query($sqlAMEND, $dblink)
or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n");

// now execute the next query to return the table data to display

$result  = mysql_query($sqlSELECT, $dblink)
or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n");


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<title>W.E.L.D.</title>

<!-- set the css style for the page -->
</head>
<body>
<?

echo'<table align = "center" border=0>
<tr>
<td colspan = 3 align = "center"><table width="100" border="0" cellspacing="10" cellpadding="10">
  <tr>
    <th scope="row"><img src="car.jpg" width="150" height="150"></th>
    <td><img src="gears.jpg" width="150" height="150"></td>
    <td><img src="wheel.jpg" width="150" height="150"></td>
    <td><img src="metalworking.jpg" width="150" height="150"></td>
    </tr>
</table></td></tr>';


// output the table and the first row headings
echo '<table align = "center" border="1">' . "\n";
//echo '<td colspan = 5 align = "center"><img alt="addmanufact.JPG" src="addmanufact.JPG" height="155" width="550"></td></tr>';
echo "<tr bgcolor = #000000><td>MANUFACTURERS</td><td>PRODUCT TYPE</td><td>PRODUCT NAME</td><td>PRODUCT DESCRIPTION</td><td>PRODUCT EQUIVALENT</td></tr>\n";


// mysql_fetch_array fetches the results from the query a row at a time each time it's called
// the result is returned as an array that can be referenced either by field name or by it's index

while ($row = mysql_fetch_array ($result))
// loop through the rows outputing them as html table rows
  {



// $row["fieldname"] returns the content for the field in the current row


  echo "<tr><td>" .$row["MANNAME"].  "</td>";

  echo "<td>"  .$row["prodtype"].  "</td>";

  echo "<td>"  .$row["proddesc"].  "</td>";

echo "<td>"  .$row["prodnar"]. "</td>";

  echo "<td>"  .$row["prodequiv"].  "</td></tr>";


  }
// close html table tag
echo "</table>\n";


// the mysql_free_result command removes any resources relating to the query results
// this happens automatically at the end of the script but still better to free up now
mysql_free_result ($result);

// the mysql_close command severs the link to the database, with scripts that make multiple
// queries on the same database the command only needs to be done once after all queries are completed
@mysql_close ($dblink)   
or die( "<p><b>Error while closing connection to database server:" .
        "($dbhost)</b></p>");

?>

<!-- put in a link that brings the site together -->

<p><a href="Addman.php"><b>Return to the data entry page</b>
    </a></p>
</body>
</html>
[/code]

Is what I want to do possible?

Share this post


Link to post
Share on other sites

×

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.