troubleshooting Question

Update Data in a Database by PHP

Avatar of Redscrapbook
RedscrapbookFlag for Ireland asked on
PHPMySQL ServerSQL
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.

[u][b]
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: 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
<?php
$q=$_GET["q"];

// 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/>";
  }

mysql_close($con);
?> 

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

HTML
<script type="text/javascript" src="js/getusermodule.js.js"></script>
<form>
<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>
</select>
</form>
<br />
<div id="getmodule">Starting date will be listed here.</div>

JS
function showUser(str)
{
if (str=="")
  {
  document.getElementById("getmodule").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("getmodule").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php/getusermodule.php?q="+str,true);
xmlhttp.send();
}
ASKER CERTIFIED SOLUTION
Marco Gasi
Freelancer

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