Solved

Edit MySQL Data from Browser with PHP

Posted on 2011-03-07
1
351 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

717 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