troubleshooting Question

Update Data in a Database by PHP

Avatar of Redscrapbook
RedscrapbookFlag for Ireland asked on
3 Comments1 Solution301 ViewsLast Modified:
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

I've corrected it as below and followed the instructions with a link: 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/>";


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>

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)
Marco Gasi

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2010

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros