473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Updating mySQL data using PHP forms.

2
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 1915
hsriat
1,654 Expert 1GB
Did you try that with MySQL Update query?
May 3 '08 #2
ronverdonk
4,258 Expert 4TB
...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
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
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 100+
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 Expert 1GB
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("SELECT * FROM.......") or die(mysql_error());
$info = mysql_fetch_array($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("UPDATE ........") 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
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? ...
7
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...
17
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...
2
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...
3
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...
10
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....
221
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...
1
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.