Hi all,
I tired searching the entire forum and was unable to find the answer i was looking for so i decided to post a new thread, if a thread explaining this already exists than i'm sorry for not finding it and posting there.
any how my problem is that i don't manage the update part of this i have attached all the files i'm using to try get this to work. what happens is that i'm able to get all the variables that i want to use into the URL address using the ajax and javascript, but i don't seem to be able to update even though after checking the php file is access just not updated.
Main Page:
PHP Code:
<?php function ConnectDB() { $con=mysql_connect("localhost","xxxx","xxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("test", $con); } ?>
<?php function CloseDB() { $con=mysql_connect("localhost","xxxx","xxxx"); mysql_close($con); } ?>
<html> <head> <script src="selectuser.js"></script> </head> <body>
<form> Select a User: <select name="users" onChange="showUser(this.value)"> <option value="1">Peter Griffin</option> <option value="2">Lois Griffin</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> </select> </form>
<table width="800" height="auto" border="1"> <?php ConnectDB(); $result = mysql_query("SELECT * FROM user ORDER BY id ASC"); while($row = mysql_fetch_array($result)) { ?> <tr> <td> <a href="Commands/deleteAdminNavigation.php?cmd=delete&id=<?php echo $row['id']; ?>"> Delete </a> </td> <td><input type="text" value="<?php echo $row['id']; ?>" /></td> <td><input type="text" value="<?php echo $row['FirstName']; ?>" onFocus="Old=this.value;" onChange="showUser(Old,this.value)" /></td> <td><input type="text" value="<?php echo $row['LastName']; ?>" /></td> <td><input type="text" value="<?php echo $row['Age']; ?>" /></td> <td><input type="text" value="<?php echo $row['Hometown']; ?>" /></td> <td><input type="text" value="<?php echo $row['Job']; ?>" /></td> </tr> <?php } CloseDB(); ?> </table>
<p> <div id="txtHint"><b>User info will be listed here.</b></div> </p>
</body> </html>
Javascript Code:
Code:
var xmlHttp;
function showUser(str,str2)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
alert(str);
var url="getuser.php";
url=url+"?q="+str;
url=url+"&a="+str2;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
PHP command page Updater page:
PHP Code:
<?php $q=$_GET['q']; $new=$_GET['a'];
$con = mysql_connect('localhost', 'xxxx', 'xxxx'); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("user", $con);
mysql_query("UPDATE user SET FirstName = $new WHERE FirstName = 'test'");
echo "changed"; echo "<br />"; echo $q; echo "<br />"; echo $new;
mysql_close($con); ?>
All help is highly appreciated thank you in advance
P.S. - Right now the code is set to update without new information that has been given by the user, this works fine to update but when i start involving variables its stops working. Really grew some new white hairs because of this bug, i have been busy on it for a couple of days now and must find a solution fast.
__________________
Mayan
Last edited by mayan.sneh; 03-31-2009 at 06:01 AM..
Reason: add some more breif to the message
|