Solved

Edit MySQL Data from Browser with PHP

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 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