We help IT Professionals succeed at work.
Get Started

Update Data in a Database by PHP

Last Modified: 2012-04-23
This is what it is on a Database but a location that read: Aungier Street, 4037 on a first row of a database and it is incorrect. It should read as Aungier Street, 4031.

moduleNo 	moduleName 	dueDate 	        location[/b][/u]
999001 	        Dynamic Web  	2012-05-14 	Aungier Street, 4037
999006 	        Digital Audio 	  	2012-05-10 	Aungier Street, 3025

Open in new window

I've corrected it as below and followed the instructions with a link: http://www.w3schools.com/php/php_mysql_update.asp it did not work as expected.
mysql_query("UPDATE moduleTable SET location=Aungier Street, 4031
WHERE dueDate='2012-05-14'");

This is PHP as below

// 1 create a database connection
$conn = mysql_connect('localhost', 'root', 'root') or die ('Error connecting to mysql');

// 2 select a database to use
$databaseName = "collegeData"; 
$tableName = "moduleTable";	
$conn = mysql_select_db($databaseName) or die( "Unable to select database");

//$sql="SELECT * FROM moduleTable WHERE moduleName= '".$q."'"; //change FROM user to studentTable
$sql="SELECT * FROM moduleTable WHERE moduleName= '".$q."'"; //change FROM user to studentTable
mysql_query("UPDATE moduleTable SET location=Aungier Street, 4031
WHERE dueDate='2012-05-14'");

//$query="SELECT * FROM studentTable ORDER BY moduleNo1 DESC LIMIT 10 ";
//<table style="width100%">

$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
	echo "<hr/><table><tr><td>Start Date:</td><td>" . $row['dueDate'] . "</td></tr></table><hr/>
    <table><tr><td>Location:</td><td>" . $row['location'] . "</td></tr></table><hr/>";


Open in new window

It may not be necessary to add this as below. For your information as below.

<script type="text/javascript" src="js/getusermodule.js.js"></script>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a module:</option>
<option value="Production Skills">Production Skills</option>
<option value="Digital Audio">Digital Audio</option>
<br />
<div id="getmodule">Starting date will be listed here.</div>

Open in new window

function showUser(str)
if (str=="")
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)

Open in new window

Watch Question
Top Expert 2010
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE