Once connected to a database call this function to add data to a table.
usage:
insertData($inputTable, $inputField, $inputValue)
The first parameter is the table name.
The second parameter is the name of the field that will have data added to it. This can be an array of field names if updating more than one field.
The last parameter is the value to add to the table, again if adding more than one value make this parameter an array.
If adding an array of values then the array of field names and the array of values to add should be the same size (as you would expect).
By : everytime
<?php
function fixQuotes ($what = "")
{
$what = ereg_replace("'","''",$what);
$counter = 0;
while (eregi("\\\\'", $what) && $counter < 10)
{
$what = ereg_replace("\\\\'","'",$what);
#print "<p>counter=[$counter] what=[$what]</p>\n";
}
return $what;
};
function insertData($inputTable, $inputField, $inputValue)
{
$i = 1;
$fieldList = "";
$valueList = "";
$fieldCount = 0;
$fieldCount = count($inputField);
foreach ($inputField as $v)
{
$fieldList = $fieldList . $v;
$i++;
if ($i <= $fieldCount)
{
$fieldList = $fieldList . ", ";
};
};
# reset local vars
$i = 1;
reset($inputField);
foreach ($inputValue as $v)
{
$v = fixQuotes($v);
$valueList = $valueList . chr(39) . $v . chr(39);
$i++;
if ($i <= $fieldCount)
{
$valueList = $valueList . ", ";
};
};
$query = "INSERT INTO " . $inputTable . " (" . $fieldList . ") VALUES (" . $valueList . ");";
print "<br />";
#print $query;
$result = mysql_query($query);
if (!$result)
{
print "<p>Insert failed, dammit.</p>\n";
}
else
{
#print "<p>Inserted ok.</p>";
};
};
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Database Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
|
|
|
|
CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
|
|
|
|
Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
|
|
|
|
Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
|
|
|
|
Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |