Solved

Edit MySQL Data from Browser with PHP

Posted on 2011-03-07
1
334 Views
Last Modified: 2012-06-21
Is it possible for me to edit mysql data from a browser with php? In the attached code, it will display the data from the mysql database in a browser. Notice line:

echo '<td><a href="edit_g.php"><center>EDIT</center></a></td>';

If I have a file named edit_g.php, could I add some type of code to it so I could edit the mysql data for that particular record?
<p> To go back <a href="http://mysite/flow/index.html">click here</a>.</p>
<?php
$con = mysql_connect("localhost","uname","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("psrflow", $con);

$result = mysql_query("SELECT * FROM orderinfo WHERE status = 'office a'");


echo "<table border='7'>
<tr>
<th>Cust No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Status</th>

<th></th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td align='center'>" . $row['custno'] . "</td>";
  echo "<td align='center'>" . $row['fname'] . "</td>";
  echo "<td align='center'>" . $row['lname'] . "</td>";
  echo "<td align='center'>" . $row['status'] . "</td>";
  echo '<td><a href="edit_g.php"><center>EDIT</center></a></td>'; 
  
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Open in new window

0
Comment
Question by:wantabe2
1 Comment
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35060098
You would have to wrap it into <form> and for example pass the record id in <input type="hidden" value="<?php echo'$row[id]';?>" />
Then the file edit_g.php would have to do
$query = "update table set v1=$_POST[custno], .... WHERE id = $_POST[id]";
$result = mysql_query($query) or die(mysql_error);
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
what is best version of php to use 6 46
FIELDSETs and LEGENDs in email markup 1 13
CSS Logo Problem. 2 8
php construct 4 0
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now