
01-02-2005, 05:09 AM
|
|
Newbie
|
|
Join Date: Sep 2004
Posts: 20
|
|
How Can I Edit Mysql Database Records By Using PHP:
Hi All
I want to edit the Mysql Database records by using php. Any body can send me the PHP code for this I actually don't have enough knowledge about it. Please help me in this regards. Looking for your kind favor.
Thanks
|

01-02-2005, 06:44 AM
|
|
Newbie
|
|
Join Date: Dec 2004
Posts: 12
|
|
Well, if you want to edit the contents of your MySQL databases, I would reccomend PHPMyAdmin ( http://www.phpmyadmin.com). It is a free script that allows you to manage MySQL databases.
|

01-02-2005, 05:42 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Nov 2004
Location: Cairo
Posts: 30
|
|
man,
SEAL31 is aiight, but:
I guess it suits you if you're about to make lots of changes.
For small changes use:
<?php
$username="user";
$password="password";
$domain="domain.com";
// Connecting to MySQL
// This line will shoot you errors wherever found
$link=mysql_connect($username, $password, $domain);
// for silent mode use
$link=@mysql_connect($username, $password, $domain);
// creating a query
$query="UPDATE table_name SET fieldname=filedvalue WHERE fieldname2=value2";
// Querying MySQL
$result=mysql_query($query);
$result? print "Done Updating MySQL" : print "Error Querying";
?>
HTH
|

01-03-2005, 01:40 AM
|
|
WHT Addict
|
|
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 158
|
|
Quote:
Originally posted by dmxo
man,
SEAL31 is aiight, but:
I guess it suits you if you're about to make lots of changes.
For small changes use:
<?php
$username="user";
$password="password";
$domain="domain.com";
// Connecting to MySQL
// This line will shoot you errors wherever found
$link=mysql_connect($username, $password, $domain);
// for silent mode use
$link=@mysql_connect($username, $password, $domain);
// creating a query
$query="UPDATE table_name SET fieldname=filedvalue WHERE fieldname2=value2";
// Querying MySQL
$result=mysql_query($query);
$result? print "Done Updating MySQL" : print "Error Querying";
?>
HTH
|
I'd think it would be better if we first selected a database to work with, don't you? Here's a revised version:
PHP Code:
<?php
$db_user = "user"; // Database Username
$db_pass = "password"; // Password for the username
$db_name = "database"; // Database Name
$db_host = "localhost"; // Host (localhost should suffice)
// Connect to the MySQL Server
$link = mysql_connect("$db_host", "$db_user", "$db_pass") or
die("Could not connect: " . mysql_error());
// Select a Database
$database = mysql_select_db("$db_name") or
die("Could not select the database '$db_name'! " . mysql_error());
// Query the table
$result = mysql_query("UPDATE table_name SET fieldname = fieldvalue WHERE something = something_else");
$changes = mysql_affected_rows();
$result ? print "$changes Record(s) Updated" : mysql_error();
?>
I haven't tested it, but it should work.

|

01-04-2005, 09:02 AM
|
|
Newbie
|
|
Join Date: Jun 2004
Posts: 10
|
|
Quote:
Originally posted by SEAL31
Well, if you want to edit the contents of your MySQL databases, I would reccomend PHPMyAdmin (http://www.phpmyadmin.com). It is a free script that allows you to manage MySQL databases.
|
http://www.phpmyadmin.net
|

01-04-2005, 12:29 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Dec 2004
Location: Back side of the Moon
Posts: 38
|
|
|

01-04-2005, 01:42 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Dec 2004
Posts: 55
|
|
PeterS
all you need is :
read some SQL and mysql functions in PHP
|

01-04-2005, 03:00 PM
|
|
Web Hosting Guru
|
|
Join Date: Nov 2003
Posts: 297
|
|
here's my stab at it...
PHP Code:
<HTML>
<?
function return_query($query) {
$user = "root";
$pass = "mypass";
$db = "test";
$link = mysql_connect("localhost", $user, $pass);
mysql_select_db($db);
$result = mysql_query($query);
return $result;
}
?>
<form method="post">
<input type="text" name="query">
<input type="submit">
</form>
<table border="1">
<?
// run the query
if (isset($_POST["query"])) {
$result = return_query($_POST["query"]);
$i = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($i == 0) {
echo "<tr>
";
foreach (array_keys($line) as $head) echo "<th>$head</th>";
echo "</tr>
";
}
echo "<tr>
";
foreach ($line as $col) echo "<td>$col</td>";
echo "</tr>
";
$i++;
}
}
?>
</table>
</HTML>
|

01-04-2005, 04:04 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Nov 2004
Posts: 67
|
|
I guess I would first ask why and how you are trying to edit. Is it just for you, to administrate your database? If that's the case, I too like phpMyAdmin.
|

01-04-2005, 09:33 PM
|
|
Temporarily Suspended
|
|
Join Date: Jan 2005
Location: Canada, AB
Posts: 11
|
|
Who is currently host you?, im surpized they dont offer something like phpMyAdmin.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|