473,606 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating mySQL data using PHP forms.

2 New Member
I've done a simple PHP-thing which adds data into my mySQL database, using that "PHP $_POST" thing, now I want to do editing that data through PHP form again, but I don't know how to do that. I've tried once, but it failed.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $author=$_POST['author'];
  4. $date=$_POST['date'];
  5. $shortstory=$_POST['story'];
  6.  
  7. mysql_connect ("dbserver", "user", "pass") or die ('Error: ' .mysql_error());
  8. mysql_select_db ("dbname");
  9.  
  10. $query = "INSERT INTO blog (author, date, shortstory) VALUES ('".$author."', '".$date."', '".$shortstory."')";
  11.  
  12. mysql_query($query) or die ('Error updating database');
  13.  
  14. echo "Database Updated! <br />
  15. Data Inserted : <br />
  16. ";
  17. ?>
  18.  
Now, I wanted to do is if I add a "news" then, I'll be able to edit that, just like in blogs or news cms.

I'm just a newbie in PHP, so I don't know much yet in PHP and mySQL...
May 3 '08 #1
6 1923
hsriat
1,654 Recognized Expert Top Contributor
Did you try that with MySQL Update query?
May 3 '08 #2
ronverdonk
4,258 Recognized Expert Specialist
...using that "PHP $_POST" thing...

I'm just a newbie in PHP, so I don't know much yet in PHP and mySQL...
When this is the level you want to discuss a PHP problem, you'd better think twice and follow some PHP tutorials before you continue any coding. Start with the w3schools.com tutorials and you'll get there.

Ronald
May 4 '08 #3
yenfa
2 New Member
Did you try that with MySQL Update query?
Yeah, I know that, but how could I edit through a PHP form?
May 4 '08 #4
lokie538
5 New Member
Pass the edited info from the form to another page and then use a update quiery to store the info and then use the header function to relocate the browser to what ever page.
May 4 '08 #5
rpnew
188 New Member
Hi,
It is similar to what you've done so far. Instead of INSERT query you need to use UPDATE query in your code which you've shown as an example. The steps are similar to what you are doing just replace INSERT with PROPER UPDATE statement.

Regards,
RP
May 5 '08 #6
hsriat
1,654 Recognized Expert Top Contributor
First fetch the same data from database by SELECT query. Then fill that data in the value attribute of the inputs in your form, and then after user clicks submit, run the UPDATE query.[php]$sql = mysql_query("SE LECT * FROM.......") or die(mysql_error ());
$info = mysql_fetch_arr ay($sql); //if your data is only on one row
echo "<input type=\"text\" name=\"data\" value=\"".$info['data']."\" />";
//--- and in the updating portion
$sql = mysql_query("UP DATE ........") or die(mysql_error ());[/php]

Hope it helps...
May 5 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
16138
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? 1) simply UPDATING the values for all fields in the table, whether or not any particular field has actually changed 2) running a second SELECT statement and comparing the $_POST vars to the returned values, and only UPDATING those that have...
7
2489
by: Paige | last post by:
I have a database on my local machine that I make entries and corrections on. I'd like to be able to upload that to my server and have that update the database that's on the server. What I've been doing is saving the local file as a backup. Then I have to edit the backup, deleting the create file info and all previously uploaded entries before I can import the text file to the server. Is there an easier way to do this so I won't get...
17
2882
by: chicha | last post by:
Hey people, I have to convert MS Access 2000 database into mysql database, the whole thing being part of this project I'm doing for one of my faculty classes. My professor somehow presumed I knew db's and gave me long list of things to do with that particular database, first thing being that particular conversion. Truth is that I don't know a first thing about db's, let alone using mysql... I downloaded mysql form www.mysql.com and...
2
3443
by: Sam White | last post by:
I have set up a MySQL db on one server, IIS 6.0 on another. Using Frontpage I created some forms to input data. On a test page I made, I have 4 fields. First is the ID which is autonumber (I leave alone). The second is marked as TEXT, the third is MEDIUMTEXT, and the fourth is DATE. This is just an example though, the problem exists in no matter what manner I create the form. Now here is the issue. In the TEXT fields nothing is saved...
3
3580
by: Kathryn Gill | last post by:
I;m having probs with this script. when i click update form the values from the text boxs that javascript updates won't be saved in the data base. Can any1 help? Thanks Kat <script type="text/javascript"> function ptotal(x,z,r,h,g) {
10
2493
by: help4me | last post by:
I am having trouble updating a table. The logic seems so simple but I just can’t get it to work. The table is named test. The column names are passcode, name, address, city, state, zip and email. First you have to sign into my site (name and passcode). This is a password protection page. The next php page holds the instructions to insert that data into the mysql table named test. At this time I am also inserting “fake data” into the...
221
367307
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
1
2360
by: jonbartlam | last post by:
Hi There I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will need updating with 'CLOSED' where necessary.) I have been trying to use the OLEDB command builder to build the statement to update the database however it is returning an error whenever I try to do this. I already have a dataset full of data, 1...
1
4788
by: Kurt Jakobsen | last post by:
Hi, I have problem opening an MySql connection from an win console application. I am using SharpDevelop as IDE. Previously I've been working with MySql through C# aspx and am new to writing exe programs in C#, so I assume that I might be missing something in the IDE / project configuration. I am successfully opening a connection and reading data from the table using adapter (window panel application binding to a grid), but when trying the...
0
8016
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8440
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6773
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5466
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3937
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1300
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.