How to Update a record in a database

Reply

Join Date: Jul 2004
Posts: 2
Reputation: alaa_steel is an unknown quantity at this point 
Solved Threads: 0
alaa_steel alaa_steel is offline Offline
Newbie Poster

How to Update a record in a database

 
0
  #1
Aug 1st, 2004
  1. if(mysql_query("update book set hometel='".$edit_hometel.",worktel='".$edit_worktel."', fax1='".$edit_fax1."',fax2='".$edit_fax2."',pobox='".$edit_pobox."',email='".$edit_email."' where name=".$row['name']." and hometel=".$row['hometel'])){
  2. echo "<font face='arial narrow' size='3' color='#ffffff'>The Record has updated succesfully.</font><br>";
  3. echo "<a href='index.php'><img src='images/buttons/continue_butt.gif' border='0'></a>";
  4. }else{
  5. echo "<font face='arial narrow' size='3' color='#ffffff'>An error has occured. Updating record failed.</font>";
  6. }

All Variables' names are right but it dosn't update the record. Please, do you have an idea how to make it work.
Last edited by digital-ether; 19 Days Ago at 9:58 pm. Reason: Fixed code tags...
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 234
Reputation: PoA is an unknown quantity at this point 
Solved Threads: 8
PoA PoA is offline Offline
Posting Whiz in Training

Re: How to Update a record in a database

 
0
  #2
Aug 1st, 2004
I assume all columns are varchar. You can try one of them. If it's not working, then post here again.

  1. if(mysql_query("update book set hometel='$edit_hometel',worktel='$edit_worktel',fax1='$edit_fax1',fax2='$edit_fax2',pobox='$edit_pobox',email='$edit_email' where name='".$row['name']."' and hometel='".$row['hometel']."'")){
  2. echo "<font face='arial narrow' size='3' color='#ffffff'>The Record has updated succesfully.</font><br>";
  3. echo "<a href='index.php'><img src='images/buttons/continue_butt.gif' border='0'></a>";
  4. }else{
  5. echo "<font face='arial narrow' size='3' color='#ffffff'>An error has occured. Updating record failed.</font>";
  6. }

or

  1.  
  2. $name = $row['name'];
  3. $htel = $row['hometel'];
  4.  
  5. if(mysql_query("update book set hometel='$edit_hometel',worktel='$edit_worktel',fax1='$edit_fax1',fax2='$edit_fax2',pobox='$edit_pobox',email='$edit_email' where name='$name' and hometel='$htel'")){
  6. echo "<font face='arial narrow' size='3' color='#ffffff'>The Record has updated succesfully.</font><br>";
  7. echo "<a href='index.php'><img src='images/buttons/continue_butt.gif' border='0'></a>";
  8. }else{
  9. echo "<font face='arial narrow' size='3' color='#ffffff'>An error has occured. Updating record failed.</font>";
  10. }
Last edited by digital-ether; 19 Days Ago at 9:58 pm. Reason: fixed code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: foxwizzy is an unknown quantity at this point 
Solved Threads: 1
foxwizzy foxwizzy is offline Offline
Newbie Poster
 
-2
  #3
20 Days Ago
Can i use one of this to update my password in the mysql db?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster
 
0
  #4
19 Days Ago
Originally Posted by foxwizzy View Post
Can i use one of this to update my password in the mysql db?
Please post your question in a new thread instead of resurrection a thread that is years old.

Here is the documentation to the syntax of a mysql update query:
http://dev.mysql.com/doc/refman/5.0/en/update.html

Here is the documentation for mysql_query:
http://www.php.net/manual/en/function.mysql-query.php

Here is an example mysql update from connection to the db, to sending an update query:

  1. <?php
  2.  
  3. // see http://www.php.net/manual/en/function.mysql-connect.php
  4.  
  5. // connect to mysql server at example.com
  6. $link = mysql_connect('example.com', 'mysql_user', 'mysql_password');
  7. if (!$link) {
  8. die('Could not connect: ' . mysql_error());
  9. }
  10.  
  11. // see http://www.php.net/manual/en/function.mysql-select-db.php
  12.  
  13. // make database_name the current db
  14. $db_selected = mysql_select_db('database_name', $link);
  15. if (!$db_selected) {
  16. die ('Can\'t use database_name: ' . mysql_error());
  17. }
  18.  
  19. // see http://www.php.net/manual/en/function.mysql-query.php
  20.  
  21. // send update query to db
  22. $result = mysql_query('UPDATE tablename set column = \'value\' where id = 1', $link);
  23. if (!$result) {
  24. die('Invalid query: ' . mysql_error());
  25. }
  26.  
  27. mysql_close($link);
  28.  
  29. ?>

Basically I just put this together from the mysql functions in the PHP.net documentation: http://www.php.net/manual/en/ref.mysql.php

PHP also has other database abstraction layers that you can use:
http://www.php.net/manual/en/refs.database.abstract.php
Last edited by digital-ether; 19 Days Ago at 10:26 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC