|
Help needed on non - working php script
Hi everyone,
If someone has some time, would you please have a look at the scripts I have pasted below, and explain to me why it isn't working...I keep getting an error saying that 'Duplicate entry for key...' when I try to update, and if I try to delete it doesn't work.
If anyone would have the time, I would be very appreciative...
thanks in advance for any help forthcoming.
Kindest Regards
Paul Stewart
If you could please respond to paulstewart@maxnet.co.nz that would be great.
Main code
php Code:
Original
- php Code |
|
|
|
<html> <body> <?php require("database_abstraction.inc.php"); $db = new removals_db(); $db->Connect(); if ($submit) { if ($id) { if (!$db->UpdateDB('client',$id,'client_id')) } else { if (!$db->AddToDB('client')) } } elseif ($delete) { $sql = "DELETE FROM client WHERE client_id= $id"; echo "$sql Record deleted!<p>"; } else { if (!$id) { printf("<a href="%s?id=%s ">%s %s</a> n", $PHP_SELF, $myrow["client_id"], $myrow["client_first_name"], $myrow["client_last_name"]); printf("<a href="%s?id=%s&delete=yes ">(DELETE)</a><br>", $PHP_SELF, $myrow["client_id"]); } } ?> <form method="post" action="<?php echo $PHP_SELF?>"> <?php if ($id) { $sql = "SELECT * FROM client WHERE client_id=$id"; $client_id = $myrow["client_id"]; $client_first_name = $myrow["client_first_name"]; $client_last_name = $myrow["client_last_name"]; $client_building_no = $myrow["client_building_no"]; $client_street = $myrow["client_street"]; $client_suburb = $myrow["client_suburb"]; $client_city = $myrow["client_city"]; $client_state = $myrow["client_state"]; $client_post_code = $myrow["client_post_code"]; $client_phone = $myrow["client_phone"]; $client_mobile_phone = $myrow["client_mobile_phone"]; $client_email = $myrow["client_email"]; $client_notes = $myrow["client_notes"]; // print the id for editing ?> <?php } ?> <div id="Layer1" style="position:absolute; left:137px; top:22px; width:861px; height:88px; z-index:1"> <hr> <p><b><font face="Arial, Helvetica, sans-serif" size="6">Client Administration</font></b></p> </div> <div id="Layer3" style="position:absolute; left:136px; top:118px; width:718px; height:516px; z-index:3"> <table width="75%" border="0" height="75"> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Client ID:</font></td> <td width="76%"> <input type="text" name="client_id" size="20" value="<?php echo $client_id ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">First Name:</font></td> <td width="76%"> <input type="text" name="client_first_name" size="45" value="<?php echo $client_first_name ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Last Name:</font></td> <td width="76%"> <input type="text" name="client_last_name" size="45" value="<?php echo $client_last_name ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Building No:</font></td> <td width="76%"> <input type="text" name="client_building_no" size="20" value="<?php echo $client_building_no ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Street:</font></td> <td width="76%"> <input type="text" name="client_street" size="45" value="<?php echo $client_street ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Suburb:</font></td> <td width="76%"> <input type="text" name="client_suburb" size="30" value="<?php echo $client_suburb ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">City:</font></td> <td width="76%"> <input type="text" name="client_city" size="20" value="<?php echo $client_city ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">State:</font></td> <td width="76%"> <input type="text" name="client_state" size="20" value="<?php echo $client_state ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Post Code:</font></td> <td width="76%"> <input type="text" name="client_post_code" size="20" value="<?php echo $client_post_code ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Phone:</font></td> <td width="76%"> <input type="text" name="client_phone" size="20" value="<?php echo $client_phone ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Mobile Phone:</font></td> <td width="76%"> <input type="text" name="client_mobile_phone" size="20" value="<?php echo $client_mobile_phone ?>"> </td> </tr> <tr> <td width="24%"><font face="Arial, Helvetica, sans-serif">Email:</font></td> <td width="76%"> <input type="text" name="client_email" size="45" value="<?php echo $client_email ?>"> </td> </tr> <tr> <td width="24%" height="85"><font face="Arial, Helvetica, sans-serif">Notes:</font></td> <td width="76%" height="85"> <TEXTAREA name= "client_notes" rows= "3" cols= "35" ><?php echo $client_notes ?></textarea> </td> </tr> </table> <input type="Submit" name="submit" value="Enter information"> </form> <?php } ?> </body> </html>
Database abstraction code
php Code:
Original
- php Code |
|
|
|
<?php Class removals_db { var $SQLStatement = ""; var $Error = ""; function Connect() { include("db_password.inc.php"); } function Disconnect() { } function GetError() { return $this->Error; } function GetLastSQL() { return $this->SQLStatement; } function AddToDB($tbl) { $sql_columns_use = array(); $sql_value_use = array(); $sql_columns[] = $columns["Field"]; foreach( $_POST as $key => $value ) { { if ($value == "DATESTAMP") $sql_value_use[] = "NOW()"; else { $sql_value_use[] = $value; else } $sql_columns_use[] = $key; } } if ( (sizeof($sql_columns_use) == 0) || (sizeof($sql_value_use) == 0) ) { $this->Error = "Error: No values were passed that matched any columns."; return false; } else { $this-> SQLStatement = "INSERT INTO ". $tbl. " (". implode(",", $sql_columns_use). ") VALUES (". implode
|