Solved

Edit MySQL Data from Browser with PHP

Posted on 2011-03-07
1
332 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

760 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

22 Experts available now in Live!

Get 1:1 Help Now