Reply
Duplicate Entry Script.
Old 05-02-2008, 08:24 AM Duplicate Entry Script.
Novice Talker

Posts: 5
Just trying to make a a simple IF else script. IF <whatever table> ==0 Print "Duplicate Entry on $tablename" Else $insertSql. Any direction/help would be great

Thanks:
Here is the code im using for insert.

PHP Code:

<?php
include('general/header.inc');
require_once(
'general/general.php');

if (!(isset(
$_POST['SubmitForm_x'])))
?>

<<<<HTML Forms CODE is here >>>>>

<?php } else {

$insertSql "INSERT INTO millidgeville (
sticker
,serial
,computer_name
,item
,brand
,model
,cdrom
,cpu_type
,hdd
,cpu_speed
,memory_type
,memory_install
,school
,room
,computer_use
,computer_use_other
,licence_software
,licence_software_other
,comments


) VALUES ( "
." '".addslashes($_POST['sticker'])."'"
.", '".addslashes($_POST['serial'])."'"
.", '".addslashes($_POST['computer_name'])."'"
.", '".addslashes($_POST['item'])."'"
.", '".addslashes($_POST['brand'])."'"
.", '".addslashes($_POST['model'])."'"
.", '".addslashes($_POST['cdrom'])."'"
.", '".addslashes($_POST['cpu_type'])."'"
.", '".addslashes($_POST['hdd'])."'"
.", '".addslashes($_POST['cpu_speed'])."'"
.", '".addslashes($_POST['memory_type'])."'"
.", '".addslashes($_POST['memory_install'])."'"
.", '".addslashes($_POST['school'])."'"
.", '".addslashes($_POST['room'])."'"
.", '".addslashes($_POST['computer_use'])."'"
.", '".addslashes($_POST['computer_use_other'])."'"
.", '".addslashes($_POST['licence_software'])."'"
.", '".addslashes($_POST['licence_software_other'])."'"
.", '".addslashes($_POST['comments'])."'"

.")";

$MyDb->f_ExecuteSql($insertSql);

?>
vipernet is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-02-2008, 08:57 AM Re: Duplicate Entry Script.
tripy's Avatar
Fetchez la vache!

Posts: 2,055
Name: Thierry
Location: In the void
If you are using mysql, you can rely on the ON DUPLICATE KEY syntax.
Basically, if the primary key is already existing, you can provide an update statement after the insert, and it's this update that will be ran

http://dev.mysql.com/doc/refman/5.0/...duplicate.html
Code:
INSERT INTO table (a,b,c) VALUES (1,2,3)
  ON DUPLICATE KEY UPDATE c=c+1;
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Duplicate Entry Script.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11377 seconds with 12 queries