| | |
How to Update a record in a database
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2004
Posts: 2
Reputation:
Solved Threads: 0
php Syntax (Toggle Plain Text)
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'])){ echo "<font face='arial narrow' size='3' color='#ffffff'>The Record has updated succesfully.</font><br>"; echo "<a href='index.php'><img src='images/buttons/continue_butt.gif' border='0'></a>"; }else{ echo "<font face='arial narrow' size='3' color='#ffffff'>An error has occured. Updating record failed.</font>"; }
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...
•
•
Join Date: Jul 2004
Posts: 234
Reputation:
Solved Threads: 8
I assume all columns are varchar. You can try one of them. If it's not working, then post here again.
or
php Syntax (Toggle Plain Text)
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']."'")){ echo "<font face='arial narrow' size='3' color='#ffffff'>The Record has updated succesfully.</font><br>"; echo "<a href='index.php'><img src='images/buttons/continue_butt.gif' border='0'></a>"; }else{ echo "<font face='arial narrow' size='3' color='#ffffff'>An error has occured. Updating record failed.</font>"; }
or
php Syntax (Toggle Plain Text)
$name = $row['name']; $htel = $row['hometel']; 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'")){ echo "<font face='arial narrow' size='3' color='#ffffff'>The Record has updated succesfully.</font><br>"; echo "<a href='index.php'><img src='images/buttons/continue_butt.gif' border='0'></a>"; }else{ echo "<font face='arial narrow' size='3' color='#ffffff'>An error has occured. Updating record failed.</font>"; }
Last edited by digital-ether; 19 Days Ago at 9:58 pm. Reason: fixed code tags
0
#4 19 Days Ago
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:
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
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:
php Syntax (Toggle Plain Text)
<?php // see http://www.php.net/manual/en/function.mysql-connect.php // connect to mysql server at example.com $link = mysql_connect('example.com', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } // see http://www.php.net/manual/en/function.mysql-select-db.php // make database_name the current db $db_selected = mysql_select_db('database_name', $link); if (!$db_selected) { die ('Can\'t use database_name: ' . mysql_error()); } // see http://www.php.net/manual/en/function.mysql-query.php // send update query to db $result = mysql_query('UPDATE tablename set column = \'value\' where id = 1', $link); if (!$result) { die('Invalid query: ' . mysql_error()); } mysql_close($link); ?>
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- update record error-mysql_numrows(): supplied argument is not a valid MySQL (PHP)
- vb6 update record in the database (Visual Basic 4 / 5 / 6)
- Pls need urgent respond to Inserting Record Into the Database (Visual Basic 4 / 5 / 6)
- update the rows in the database using the same form (PHP)
- Beginner: how to add new record into database??? (VB.NET)
- Problem with update data to database (JSP)
- [Please HELP] Cannot Update Record (PHP)
Other Threads in the PHP Forum
- Previous Thread: Parse Error in Class
- Next Thread: Age Calculation
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner beneath binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube






