Jump to content

Best way to Add & Update info ...


bsamson

Recommended Posts

Here's my code:

[code]<?
$company = $_POST['company'];
$discount = $_POST['discount'];
$nte = $_POST['nte'];
$recid = $_POST['recid'];

$lu = date("m/d/Y");

// define connection info
include "scripts/mysql/db_connect.php";

//connects to the DB w/ above credentials
mysql_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

[code]<?php

$company = $_POST['company'];
$discount = $_POST['discount'];
$nte = $_POST['nte'];
$recid = $_POST['recid'];

$lu = date("m/d/Y");

// define connection info
include "scripts/mysql/db_connect.php";

//connects to the DB w/ above credentials
mysql_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.

Archived

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

×
×
  • Create New...

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.