It's just a testing script and a testing database but I can't get it to work. It's using an edit-in-place script that allows users to edit their data, then it calls this save php script which is supposed to save it and update it within the database. It does neither. Any help would be greatly appreciated.

<?php
       $loggedIn = 1;
    
        if($loggedIn == 1) {
        
            $part = mysql_escape_string($_GET['part']);
            
            $val = mysql_escape_string($_GET['val']);
            
            $id = $userId;
            
            
            //include 'database_connect.php';
          
		
			$con = mysql_connect("localhost","root","root");
			if (!$con)
  				{
  			die('Could not connect: ' . mysql_error());
  					}

			mysql_select_db("johnDoe", $con);




            
            if($part == "name") {
                $array = split(" ",$val);
          		$name = mysql_escape_string($array[0]);
                $sql = "UPDATE johnDoe SET name = '$name' WHERE id=$id";
            }
            else if($part == "email") {
             $sql = "UPDATE johnDoe SET email = '$val' WHERE id=$id";
            }
            else if($part == "desc") {
             $sql = "UPDATE johnDoe SET description = '$val' WHERE id=$id";
            }
            else if($part == "phone") {
              $sql = "UPDATE johnDoe SET phone = '$val' WHERE id=$id";
            }
            mysql_query($sql);
            
            mysql_close();
            echo $part;
        }

?>

first of all, mysql_escape_string is depreciated. use mysql_real_escape_string instead.

is the script throwing any errors?

No, no errors. It just doesn't change any data in the database. So I suppose it is connecting?

i started to rewrite the code and saw that the $id is not being set with a value. where is $userId coming from?

I don't know. Here is the index.php page.

<html>
<head>
<title>John Doe Test</title>

<style>
input.editMode {
background-color : #FFFF99;
}
textarea.editMode {
background-color : #FFFF99;
}
.savingAjaxWithBackground {
background-color : #FFFF99;
}
.superBigSize {
    font-size: 45px;
    font-weight: bold;
}
td.underlinedTD {
	border-bottom:1px #000000 dashed;
}
table.infoBox {
background-color:#F6F6F6;
border:#999999 double 1px;
font-size:11px;
padding:2px;
}
</style>

<script type="text/javascript">
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq(action) {
    http.open('get', action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        if(http.responseText=="name") {
        	var replaceText = document.getElementById('person_name').value;
        	document.getElementById('name_rg_display_section').innerHTML = replaceText;
        	document.getElementById('name_rg').style.display = '';
        	document.getElementById('name_hv').style.display = 'none';
        }
        else if(http.responseText=="email") {
        	var replaceText = document.getElementById('email_value').value;
        	document.getElementById('email_rg_display_section').innerHTML = "<b>Email:</b> " + replaceText;
        	document.getElementById('email_rg').style.display = '';
        	document.getElementById('email_hv').style.display = 'none';
        }
        else if(http.responseText=="phone") {
        	var replaceText = document.getElementById('phone_value').value;
        	document.getElementById('phone_rg_display_section').innerHTML = "<b>Phone:</b> " + replaceText;
        	document.getElementById('phone_rg').style.display = '';
        	document.getElementById('phone_hv').style.display = 'none';
        }
    }
}
		function flashRow(obj) {	
			obj.bgColor = "#FFFF99";
		}
		function unFlashRow(obj) {	
			obj.bgColor = "#F6F6F6";
		}
</script>	
</head>



<body>

<table  cellpadding="3" cellspacing="2" class="infoBox">
									<tr><td align="right" class="underlinedTD"><b>Contact</b></td></tr>
									<tr><td></td></tr>
																				<tr id="name_rg">
											<td onMouseOver="flashRow(this);" onMouseOut="unFlashRow(this);" onClick="
											
											document.getElementById('name_hv_editing_section').style.display = '';
											document.getElementById('name_hv_saving_section').style.display = 'none';
											document.getElementById('name_rg').style.display = 'none';
											document.getElementById('name_hv').style.display = '';
											
											
											">
											<div class="superBigSize" id="name_rg_display_section">
												John Doe											</div></td></tr>
											<tr id="name_hv"><td>

											<div id="name_hv_editing_section">
													<input type="text" class="superBigSize editMode" size="7" value="John Doe" id="person_name" /> <br /><input type="button" value="Save" onClick="document.getElementById('name_hv_editing_section').style.display='none';document.getElementById('name_hv_saving_section').style.display='';var req = 'updateProfileAjax.php?part=name&val=' + document.getElementById('person_name').value;sndReq(req);" /> Or <input type="button" value="Cancel" onClick="						
						document.getElementById('name_rg').style.display = '';
						document.getElementById('name_hv').style.display = 'none';
						"/>
											
											</div>
											<span id="name_hv_saving_section" class="savingAjaxWithBackground">
											Saving...
											</span>
											<script type="text/javascript">
												document.getElementById('name_hv').style.display = 'none';
												document.getElementById('name_hv_saving_section').style.display = 'none';
											</script>

										</td></tr>
																				
										
										
										
										
										
										
										
										
										<!--<tr><td align="right" class="underlinedTD">Email</td></tr>-->
										
										
										
										
																					<tr id="email_rg">
											<td onMouseOver="flashRow(this);" onMouseOut="unFlashRow(this);" onClick="
											document.getElementById('email_hv_editing_section').style.display = '';
											document.getElementById('email_hv_saving_section').style.display = 'none';
											document.getElementById('email_rg').style.display = 'none';
											document.getElementById('email_hv').style.display = '';
											
											">
											<div class="" id="email_rg_display_section"><b>Email:</b> john.doe@gmail.com</div>
											</td></tr>
											
											<tr id="email_hv"><td>

											<div id="email_hv_editing_section"><b>Email:</b> 
												<input type="text" class=" editMode" size="18" value="john.doe@gmail.com" id="email_value" /> <br /><input type="button" value="Save" onClick="document.getElementById('email_hv_editing_section').style.display='none';document.getElementById('email_hv_saving_section').style.display='';var req = 'updateProfileAjax.php?part=email&val=' + document.getElementById('email_value').value;sndReq(req);" /> Or <input type="button" value="Cancel" onClick="document.getElementById('email_rg').style.display = '';
								 document.getElementById('email_hv').style.display = 'none';"/>
												
											</div>
											<span id="email_hv_saving_section" class="savingAjaxWithBackground">
											Saving...
											</span>
											<script type="text/javascript">
												document.getElementById('email_hv').style.display = 'none';
												document.getElementById('email_hv_saving_section').style.display = 'none';
											</script>

										</td></tr>
																				
										
										
										
										
										
																						<tr id="phone_rg">
											<td onMouseOver="flashRow(this);" onMouseOut="unFlashRow(this);" onClick="
											document.getElementById('phone_hv_editing_section').style.display = '';
											document.getElementById('phone_hv_saving_section').style.display = 'none';
											document.getElementById('phone_rg').style.display = 'none';
											document.getElementById('phone_hv').style.display = '';
											
											">
											<div id="phone_rg_display_section"><b>Phone:</b> 555-555-1234</div>
											</td></tr>
											
											
											<tr id="phone_hv"><td>
											<div id="phone_hv_editing_section"><b>Phone:</b> 
												<input type="text" class=" editMode" size="12" value="555-555-1234" id="phone_value" /> <br /><input type="button" value="Save" onClick="document.getElementById('phone_hv_editing_section').style.display='none';document.getElementById('phone_hv_saving_section').style.display='';var req = 'updateProfileAjax.php?part=phone&val=' + document.getElementById('phone_value').value;sndReq(req);" /> Or <input type="button" value="Cancel" onClick="document.getElementById('phone_rg').style.display = '';
								 document.getElementById('phone_hv').style.display = 'none';"/>

												
											</div>
											<span id="phone_hv_saving_section" class="savingAjaxWithBackground">
											Saving...
											</span>
											<script type="text/javascript">
												document.getElementById('phone_hv').style.display = 'none';
												document.getElementById('phone_hv_saving_section').style.display = 'none';
											</script>
										</td></tr>
																		
										
</table>
</body>

I'm learning as I go. Thanks for taking a look at my problem.

to update someones profile you will need to know their unique identifier ($userId). do you have it stored in a session? there is no way to know which profile you need to update without it.

i suggest using a less complicated solution. not ajax. get the system working without it and slow integrate ajax into it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.