hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : How Can I Edit Mysql Database Records By Using PHP:
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

How Can I Edit Mysql Database Records By Using PHP:

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-02-2005, 05:09 AM
PeterS PeterS is offline
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

Reply With Quote


Sponsored Links
  #2  
Old 01-02-2005, 06:44 AM
SEAL31 SEAL31 is offline
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.

Reply With Quote
  #3  
Old 01-02-2005, 05:42 PM
dmxo dmxo is offline
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

Reply With Quote
Sponsored Links
  #4  
Old 01-03-2005, 01:40 AM
nuk3 nuk3 is offline
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.


Reply With Quote
  #5  
Old 01-04-2005, 09:02 AM
Hydrogen Hydrogen is offline
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

Reply With Quote
  #6  
Old 01-04-2005, 12:29 PM
wilcorp wilcorp is offline
Junior Guru Wannabe
 
Join Date: Dec 2004
Location: Back side of the Moon
Posts: 38
second on the phpmyadmin

Reply With Quote
  #7  
Old 01-04-2005, 01:42 PM
beecoder beecoder is offline
Junior Guru Wannabe
 
Join Date: Dec 2004
Posts: 55
PeterS
all you need is :
read some SQL and mysql functions in PHP

Reply With Quote
  #8  
Old 01-04-2005, 03:00 PM
nnormal nnormal is offline
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($resultMYSQL_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>

Reply With Quote
  #9  
Old 01-04-2005, 04:04 PM
absolethe absolethe is offline
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.

__________________
- http://www.virtualrevolution.net / Rhy

Reply With Quote
  #10  
Old 01-04-2005, 09:33 PM
ProAgramer ProAgramer is offline
Temporarily Suspended
 
Join Date: Jan 2005
Location: Canada, AB
Posts: 11
Who is currently host you?, im surpized they dont offer something like phpMyAdmin.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Amazon Adds RDS, DynamoDB Services to GovCloud Offering Web Hosting News 2012-12-24 12:18:51
Joomla Releases Version 2.5 With SQL Server Support Web Hosting News 2012-01-24 13:34:24
Web Host Rackspace Launches Private Beta for MySQL Cloud Database Web Hosting News 2011-12-01 21:09:51
Web Host DiscountASP.NET Lets Customers Keep Testing Web Matrix V2 Beta for Free Web Hosting News 2011-11-15 16:48:12
Web Host FireHost Partners with Cloud Security Firm Gazzang for Data Encryption Web Hosting News 2011-08-16 20:33:43


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?