bsamson Posted November 20, 2006 Share Posted November 20, 2006 Here's my code: [code]<?$company = $_POST['company'];$discount = $_POST['discount'];$nte = $_POST['nte'];$recid = $_POST['recid'];$lu = date("m/d/Y");// define connection infoinclude "scripts/mysql/db_connect.php";//connects to the DB w/ above credentialsmysql_connect(localhost,$dbuser,$dbpassword);@mysql_select_db($dbname) or die( "Unable to select database");$sql = "UPDATE nymob SET business='$company', discount='$discount', add_date= '$lu', notes = '$nte' WHERE id ='$recid'";$result = mysql_query($sql) or die(mysql_error());?>[/code] HEre's the situation. I have this short script called add_modify.php. Is there one Query I can use to both add new if one doesnt exist or update if does exist. The reason is that I would like to use this script for both functions. Thanks for any assistance Link to comment https://forums.phpfreaks.com/topic/27880-best-way-to-add-update-info/ Share on other sites More sharing options...
Orio Posted November 20, 2006 Share Posted November 20, 2006 [code]<?php$company = $_POST['company'];$discount = $_POST['discount'];$nte = $_POST['nte'];$recid = $_POST['recid'];$lu = date("m/d/Y");// define connection infoinclude "scripts/mysql/db_connect.php";//connects to the DB w/ above credentialsmysql_connect(localhost,$dbuser,$dbpassword);@mysql_select_db($dbname) or die( "Unable to select database");$result = mysql_query("SELECT COUNT(id) as num FROM nymob");$temp = mysql_fetch_array($result);if($temp['num']){ $sql = "UPDATE nymob SET business='$company', discount='$discount', add_date= '$lu', notes = '$nte' WHERE id ='$recid'";}else{ $sql = "INSERT .......";}$result = mysql_query($sql) or die(mysql_error());?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/27880-best-way-to-add-update-info/#findComment-127506 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.