Say for example, I want to add 50 more books to a database of 100 books. How could I do it using the Update method? It is for the inventory module of the system that I'm working on.
Please help. Thanks.
8 3308
If you prefer using the UPDATE ... SET style method, MySQL has an answer, the INSERT ... SET method. -
INSERT INTO tablename
-
SET colname = value, colname = value, ...
-
http://dev.mysql.com/doc/refman/5.0/en/insert.html
If you prefer using the UPDATE ... SET style method, MySQL has an answer, the INSERT ... SET method. -
INSERT INTO tablename
-
SET colname = value, colname = value, ...
-
http://dev.mysql.com/doc/refman/5.0/en/insert.html
Thanks for this but I was asking how to add values to an existing value in the database.
for example, can i do this? - UPDATE tablename SET quantity = quantity+'$qty'
Hi,
I am assuming your are not working with images and only letters and your book has a ID Example Book_ID just to keep track of them:
We can do this with 3 pages.
1. form.html
2. update.php
3 updated.php 1. form.html
First make a html form so bring up the book we want to update:
[HTML]
<form id="form1" name="form1" method="post" action="http://www.location.com/update.php">
<label>
<input name="book" type="text" id="book" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
[/HMTL] 2. Update.php
[PHP]
<?
$book=$_POST['book']; ////////Get id number or book name from the html form
#Connect to Database ( Change all the stuff that has _ Example; Your_DB.
$con = mysql_connect("localhost","yourDBusername","yourDB password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("Your_database_name", $con); #database name
$query="SELECT * FROM Your_Table WHERE Book_ID_no='$book'"; #database name and book to update
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
# Get all the details from the Database for the book you want to up date. PLease note you must write every row you have for the particular table otherwise the update will not work
$i=0;
while ($i < $num) {
$book_id_no=mysql_result($result,$i,"book_id_no");
$title=mysql_result($result,$i,"title");
$writer=mysql_result($result,$i,"writer");
$info=mysql_result($result,$i,"info");
?>
<form action="http://www.location.com.to/updated.php" method="post">
<input name="book" type="hidden" id="book" value="<? echo"$book_ID_No "?>" /> <!-- Hide this cause we don't want anyone updating the book name or id that we work with to update otherwise if someone change the id/book name it will no longer be updateble-->
<input type="text" name="ud_title" value="<? echo "$title"?>" />
<input type="text" name="ud_writer" value="<? echo "$writer"?>" />
<input type="text" name="ud_info" value="<? echo "$info"?>" />
<input name="submit" type="submit" value="Update" />
</form>
[/PHP]
3. Updated.php
[PHP]
<?
$$book_ID_No=$_POST['$book_ID_No'];
$con = mysql_connect("localhost","yourDBusername","yourDB password");
$query="UPDATE Your_table SET title='$ud_title', writer='$ud_writer', info='$ud_info' WHERE book_id_no='$book_ID_No'";
#once again make sure your write all your rows otherwise your stuff will not update. Make sure you put no spaces where there are not suppose to be and as well as for the commas:
@mysql_select_db("divereg") or die( "Unable to select database");
mysql_query($query);
mysql_close();
?>
[/PHP]
If you have any trouble feel free to post again
Hi,
I am assuming your are not working with images and only letters and your book has a ID Example Book_ID just to keep track of them:
We can do this with 3 pages.
1. form.html
2. update.php
3 updated.php 1. form.html
First make a html form so bring up the book we want to update:
<form id="form1" name="form1" method="post" action="http://www.location.com/update.php">
<label>
<input name="book" type="text" id="book" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form> 2. Update.php
[PHP]
<?
$book=$_POST['book']; ////////Get id number or book name from the html form
#Connect to Database ( Change all the stuff that has _ Example; Your_DB.
$con = mysql_connect("localhost","yourDBusername","yourDB password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("Your_database_name", $con); #database name
$query="SELECT * FROM Your_Table WHERE Book_ID_no='$book'"; #database name and book to update
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
# Get all the details from the Database for the book you want to up date. PLease note you must write every row you have for the particular table otherwise the update will not work
$i=0;
while ($i < $num) {
$book_id_no=mysql_result($result,$i,"book_id_no");
$title=mysql_result($result,$i,"title");
$writer=mysql_result($result,$i,"writer");
$info=mysql_result($result,$i,"info");
?>
<form action="http://www.location.com.to/updated.php" method="post">
<input name="book" type="hidden" id="book" value="<? echo"$book_ID_No "?>" /> <!-- Hide this cause we don't want anyone updating the book name or id that we work with to update otherwise if someone change the id/book name it will no longer be updateble-->
<input type="text" name="ud_title" value="<? echo "$title"?>" />
<input type="text" name="ud_writer" value="<? echo "$writer"?>" />
<input type="text" name="ud_info" value="<? echo "$info"?>" />
<input name="submit" type="submit" value="Update" />
</form>
[/PHP]
3. Updated.php
[PHP]
<?
$$book_ID_No=$_POST['$book_ID_No'];
$con = mysql_connect("localhost","yourDBusername","yourDB password");
$query="UPDATE Your_table SET title='$ud_title', writer='$ud_writer', info='$ud_info' WHERE book_id_no='$book_ID_No'";
#once again make sure your write all your rows otherwise your stuff will not update. Make sure you put no spaces where there are not suppose to be and as well as for the commas:
@mysql_select_db("divereg") or die( "Unable to select database");
mysql_query($query);
mysql_close();
?>
[/PHP]
If you have any trouble feel free to post again
just let me know if this works for you, I use it for all of my stuff........
Regards
Webandwe
just let me know if this works for you, I use it for all of my stuff........
Regards
Webandwe
well, i'm pretty sure that your code will work because I've used that kind of code before. but it really didn't solve my problem. I wanted to know how to add additional values in a databse.
for example, I have 100 boxes of oranges in my inventory database and I want to add 100 more. how should I do it?
could I do something like this: -
-
$quantity=$_POST["quantity"];
-
-
$query=mysql_query(SELECT fruit_id,description,quantity FROM tblFruits WHERE description = "oranges");
-
-
if($query)
-
{
-
$fruit_id = $row['fruit_id'];
-
$description = $row['description'];
-
$qty = $row['quantity'];
-
-
$qtyplus = $qty + $quantity;
-
-
$query2 = mysql_query("UPDATE tblFruits SET quantity = '$qtyplus'");
-
-
if($query2)
-
{
-
echo "update success!!!!"
-
}
-
}
-
}
sorry for the miss understanding......
Yes, that will work.
sorry for the miss understanding......
Yes, that will work.
do you any other solution aside from what I posted? If so, please post it. It would help me a lot.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve B. |
last post by:
Does anyone know why the DA Update() would throw an exception?
I moved the database but I updated the Conn and the DA, currently
(trying)removing/replacing DS. Is there a another direction I...
|
by: M. David Johnson |
last post by:
I cannot get my OleDbDataAdapter to update my database
table from my local dataset table. The Knowledge Base
doesn't seem to help - see item 10 below.
I have a Microsoft Access 2000 database...
|
by: DanielJ |
last post by:
I'm new to using SQL and in my current position I am doing some basic uploading to a Oracle database, to a sinlge table with approx 1.4 million rows. IBM is supporting the database and have provided...
|
by: Andi Clemens |
last post by:
Hi,
I want to update our DNS servers periodically with some IP addresses. But I
don't know how to do this.
I searched the Internet quite a while but I haven't found a good example how
to do...
|
by: uranuskid |
last post by:
Hey folks,
I'm curious about how to perform following task:
I need to update a MySQL database every day in terms of deleting expired entries.Therefore, I have to fields in the db named 'date'...
|
by: P3Eddie |
last post by:
Hello all!
I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same.
My problem may be a simple find duplicates / do something...
|
by: ARC |
last post by:
Hello all,
So I'm knee deep in this import utility program, and am coming up with all
sorts of "gotcha's!".
1st off. On a "Find Duplicates Query", does anyone have a good solution for...
|
by: Terry Olsen |
last post by:
I'm using OleDb to connect with an Access Database. I have anywhere from
10 to over 100 records that I need to either INSERT if the PK doesn't
exist or UPDATE if the PK does exist, all in a single...
|
by: mariaz |
last post by:
Hello, I am creating a project where I parse an xml page (feed from a website) in a javabean file and I insert the parsed data in a mysql database. I want this data that gets inserted into the...
|
by: P.J.M. Beker |
last post by:
Hi there,
I'm currently writing a program in which I use the FileMonitor to monitor a
folder in which I store downloaded images. I know that I can't add much
coding in the filemonitor's event in...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |