Jump to content
Larry Ullman's Book Forums

sampath

Members
  • Posts

    6
  • Joined

  • Last visited

sampath's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Dear all, I have a horrible issue with one of my PHP file which generates an XML file for the AJAX response. The original file(also the correct code) is as follows. <?php # update.php header("Content-Type: text/xml"); echo '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><response>'; $error = false; if (!empty($_POST['prof_name'])) { $name = $_POST['prof_name']; } else { $error = true; echo '<field_error>prof_name</field_error>'; } if (!empty($_POST['prof_address'])) { $address = $_POST['prof_address']; } else { $address = ""; } if (!empty($_POST['prof_nic'])) { $nic = $_POST['prof_nic']; } else { $nic = ""; } if (!empty($_POST['prof_telephone'])) { $telephone = (int) $_POST['prof_telephone']; } else { $telephone = 0; } if (!empty($_POST['prof_email'])) { $email = $_POST['prof_email']; } else { $email = ""; } if (!empty($_POST['prof_post'])) { $post = $_POST['prof_post']; } else { $post = ""; } if (!$error && $_POST['cmbprofessionalid']!="Default") { //Open the database connection. require_once (dirname(__FILE__).'/../../functions/dbconnect.php'); $q = "UPDATE Professional_Table SET name = '$name', address = '$address', NIC = '$nic', telephone = $telephone, email = '$email', post = '$post' WHERE professionalID = " . $_POST['cmbprofessionalid']; $r = mysql_query($q, $dbc); $updateError = false; if (mysql_affected_rows($dbc) == 0) { // Query failure. if(mysql_errno()>0) { $updateError = true; if(mysql_error()=="Duplicate entry '" . $name . "' for key 'name'") { echo '<name_error>prof_name</name_error>'; echo '<system_error>Same professional name already exists! Please select a different name and click "Submit".</system_error>'; } } } //Start saving the professional user rights. $professionalID = $_POST['cmbprofessionalid']; //Check whether the change rights are set. if(isset($_POST['prof_changeright']) || isset($_POST['prof_viewright'])) { //Delete the old user rights from the professional_user_rights_table $q = "DELETE FROM Professional_User_Rights_Table WHERE professionalID = $professionalID"; $r = mysql_query($q, $dbc); //Extract the professional names from change rights list seperately. $line_data1 = explode("\n", $_POST['prof_changeright']); //For each extracted professional name start saving the rights. foreach($line_data1 as $key => $value1) { //Retrive the allowed professional ID from the professional table. $q2 = "SELECT professionalID FROM Professional_Table WHERE name = '$value1'"; $r2 = mysql_query($q2, $dbc); if (mysql_num_rows($r2)>0) { // Retrieve the results: $row2 = mysql_fetch_row($r2); //Prepare the professional ID. $allowedChangeProfessionalID = $row2[0]; //Professional has both change and view rights. $q3 = "INSERT INTO Professional_User_Rights_Table (professionalID, allowedProfessionalID, changeRight, viewRight) VALUE($professionalID, $allowedChangeProfessionalID, 1, 1)"; $r3 = mysql_query($q3, $dbc); if (mysql_affected_rows($dbc) == 0) { $rights_save_error = true; } } } //Extract the professional names from view rights list seperately. $line_data2 = explode("\n", $_POST['prof_viewright']); //For each extracted professional name start saving the rights. foreach($line_data2 as $key => $value2) { $q4 = "SELECT professionalID FROM Professional_Table WHERE name = '$value2'"; $r4 = mysql_query($q4, $dbc); if (mysql_num_rows($r4)>0) { // Retrieve the results: $row4 = mysql_fetch_row($r4); //Prepare the professional ID. $allowedViewProfessionalID = $row4[0]; //Check whether the user rights inserted for the selected professional under the change rights. $q5 = "SELECT allowedProfessionalID FROM Professional_User_Rights_Table WHERE professionalID = '$professionalID' AND allowedProfessionalID = '$allowedViewProfessionalID'"; $r5 = mysql_query($q5, $dbc); if (mysql_num_rows($r5)==0) { //Professional has only view right. $q6 = "INSERT INTO Professional_User_Rights_Table (professionalID, allowedProfessionalID, changeRight, viewRight) VALUE($professionalID, $allowedViewProfessionalID, 0, 1)"; $r6 = mysql_query($q6, $dbc); if (mysql_affected_rows($dbc) == 0) { $rights_save_error = true; } } } } } if(!$rights_save_error) { if(!$updateError) { echo '<result>The professional has been successfully updated.</result>'; } } else { echo '<system_error>Error occured while saving user rights!</system_error>'; } mysql_close($dbc); } else { // Errors! if($_POST['cmbprofessionalid']=="Default") { echo '<not_select_error>Please select a professional to update information.</not_select_error>'; } else { echo '<system_error>Please correct problems with the highlighted field(s) below.</system_error>'; } } echo '</response>'; exit(); ?> But after saving the file, I can see that the file is broken as follows. <?php # update.php header("Content-Type: text/xml"); echo '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><response>'; $error = false; if (!empty($_POST['prof_name'])) { $name = $_POST['prof_name']; } else { $error = true; echo '<field_error>prof_name</field_error>'; } if (!empty($_POST['prof_address'])) { $address = $_POST['prof_address']; } else { $address = ""; } if (!empty($_POST['prof_nic'])) { $nic = $_POST['prof_nic']; } else { $nic = ""; } if (!empty($_POST['prof_telephone'])) { $telephone = (int) $_POST['prof_telephone']; } else { $telephone = 0; } if (!empty($_POST['prof_email'])) { $email = $_POST['prof_email']; } else { $email = ""; } if (!empty($_POST['prof_post'])) { $post = $_POST['prof_post']; } else { $post = ""; } if (!$error && $_POST['cmbprofessionalid']!="Default") { //Open the database connection. require_once (dirname(__FILE__).'/../../functions/dbconnect.php'); $q = "UPDATE Professional_Table SET name = '$name', address = '$address', NIC = '$nic', telephone = $telephone, email = '$email', post = '$post' WHERE professionalID = " . $_POST['cmbprofessionalid']; $r = mysql_query($q, $dbc); $updateError = false; if (mysql_affected_rows($dbc) == 0) { // Query failure. if(mysql_errno()>0) { $updateError = true; if(mysql_error()=="Duplicate entry '" . $name . "' for key 'name'") { echo '</response>'; exit(); ?> ----------File is broken here--------------- <name_error>prof_name</name_error>'; echo '<system_error>Same professional name already exists! Please select a different name and click "Submit".</system_error>'; } } } //Start saving the professional user rights. $professionalID = $_POST['cmbprofessionalid']; //Check whether the change rights are set. if(isset($_POST['prof_changeright']) || isset($_POST['prof_viewright'])) { //Delete the old user rights from the professional_user_rights_table $q = "DELETE FROM Professional_User_Rights_Table WHERE professionalID = $professionalID"; $r = mysql_query($q, $dbc); //Extract the professional names from change rights list seperately. $line_data1 = explode("\n", $_POST['prof_changeright']); //For each extracted professional name start saving the rights. foreach($line_data1 as $key => $value1) { //Retrive the allowed professional ID from the professional table. $q2 = "SELECT professionalID FROM Professional_Table WHERE name = '$value1'"; $r2 = mysql_query($q2, $dbc); if (mysql_num_rows($r2)>0) { // Retrieve the results: $row2 = mysql_fetch_row($r2); //Prepare the professional ID. $allowedChangeProfessionalID = $row2[0]; //Professional has both change and view rights. $q3 = "INSERT INTO Professional_User_Rights_Table (professionalID, allowedProfessionalID, changeRight, viewRight) VALUE($professionalID, $allowedChangeProfessionalID, 1, 1)"; $r3 = mysql_query($q3, $dbc); if (mysql_affected_rows($dbc) == 0) { $rights_save_error = true; } } } //Extract the professional names from view rights list seperately. $line_data2 = explode("\n", $_POST['prof_viewright']); //For each extracted professional name start saving the rights. foreach($line_data2 as $key => $value2) { $q4 = "SELECT professionalID FROM Professional_Table WHERE name = '$value2'"; $r4 = mysql_query($q4, $dbc); if (mysql_num_rows($r4)>0) { // Retrieve the results: $row4 = mysql_fetch_row($r4); //Prepare the professional ID. $allowedViewProfessionalID = $row4[0]; //Check whether the user rights inserted for the selected professional under the change rights. $q5 = "SELECT allowedProfessionalID FROM Professional_User_Rights_Table WHERE professionalID = '$professionalID' AND allowedProfessionalID = '$allowedViewProfessionalID'"; $r5 = mysql_query($q5, $dbc); if (mysql_num_rows($r5)==0) { //Professional has only view right. $q6 = "INSERT INTO Professional_User_Rights_Table (professionalID, allowedProfessionalID, changeRight, viewRight) VALUE($professionalID, $allowedViewProfessionalID, 0, 1)"; $r6 = mysql_query($q6, $dbc); if (mysql_affected_rows($dbc) == 0) { $rights_save_error = true; } } } } } if(!$rights_save_error) { if(!$updateError) { echo '<result>The professional has been successfully updated.</result>'; } } else { echo '<system_error>Error occured while saving user rights!</system_error>'; } mysql_close($dbc); } else { // Errors! if($_POST['cmbprofessionalid']=="Default") { echo '<not_select_error>Please select a professional to update information.</not_select_error>'; } else { echo '<system_error>Please correct problems with the highlighted field(s) below.</system_error>'; } } echo ' As you will notice from the second code segment, part of the PHP code is out from the PHP end tag. I'm using Dreamweaver as the editor. The Tag Inspector in Dreamweaver is not properly referring to the tags in the PHP file. I cannot figure out the exact issue here! I expect some support from you to solve this issue. Thank you in advance!, Sampath.
  2. Thanks HartleySan! Finaly I found the issue. It was with the date field in my query and I set the date format in my jquery datepicker. My doubt was that the issue was due to the XML file error. Anyway thank you so much!
  3. Dear all, I'm getting "no element found error" in my one of php file shown below. I have noted the following points. 1. When I preview my php file, the XML output is correct and does not give any error for me. <response> <field_error>appo_appointmentsubject</field_error> <field_error>appo_appointmentvenue</field_error> <field_error>appo_appointmentdate</field_error> <field_error>appo_appointmentfromtime</field_error> <field_error>appo_appointmenttotime</field_error> <field_error>appo_professionalparticipants</field_error> <system_error>Please correct problems with the highlighted field(s) below.</system_error> </response> 2. I do not get the error message when the "error" variable is true in the code. 3. When the error variable is false, I do not get the error message up to the line called "This is the point"(It's a comment in the code). That means I have commented the rest of the code. 4. But when I uncomment the lines within the comment called "Error occurs after the following query.", I get this error. I cannot figure out the issue here! Can you find any issue in my code? <?php # submit.php header("Content-Type: text/xml"); echo '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><response>'; $error = false; $professional_participants_save_error = false; $customer_participants_save_error = false; $rights_save_error = false; if (!empty($_POST['appo_appointmentsubject'])) { $subject = $_POST['appo_appointmentsubject']; } else { $error = true; echo '<field_error>appo_appointmentsubject</field_error>'; } if (!empty($_POST['appo_appointmentdescription'])) { $description = $_POST['appo_appointmentdescription']; } else { $description = null; } if (!empty($_POST['appo_appointmentvenue'])) { $venue = $_POST['appo_appointmentvenue']; } else { $error = true; echo '<field_error>appo_appointmentvenue</field_error>'; } if (!empty($_POST['appo_appointmentdate'])) { $date = date_create($_POST['appo_appointmentdate']); } else { $error = true; echo '<field_error>appo_appointmentdate</field_error>'; } if (!empty($_POST['appo_appointmentfromtime'])) { $fromTime = $_POST['appo_appointmentfromtime']; } else { $error = true; echo '<field_error>appo_appointmentfromtime</field_error>'; } if (!empty($_POST['appo_appointmenttotime'])) { $toTime = $_POST['appo_appointmenttotime']; } else { $error = true; echo '<field_error>appo_appointmenttotime</field_error>'; } if (!empty($_POST['appo_appointmentduration'])) { $duration = $_POST['appo_appointmentduration']; } else { $duration = 0; } if (empty($_POST['appo_professionalparticipants'])) { $error = true; echo '<field_error>appo_professionalparticipants</field_error>'; } if (!$error) { echo '<system_error>Test this code......</system_error>'; //Open the database connection. require_once (dirname(__FILE__).'/../../functions/dbconnect.php'); session_start(); $username = $_SESSION['username']; //Retrive the owner professional ID from the professional table. Owner professional is the current user logged in. $q = "SELECT professionalID FROM Professional_Table WHERE userName LIKE '$username'"; $r = mysql_query($q, $dbc); if (mysql_num_rows($r)==1) { // Retrieve the results: $row = mysql_fetch_row($r); //Prepare the owner professional ID. $ownerProfessionalID = $row[0]; } //"This is the point" /* //Error occurs after the following query. //Insert the new appointment information into Appointment_Table. $q1 = "INSERT INTO appointment_table (ownerProfessionalID, subject, description, venue, date, fromTime, toTime, duration) VALUES ($ownerProfessionalID, '$subject', '$description', '$venue', $date, $fromTime, $toTime, $duration)"; $r1 = mysql_query($q1, $dbc); //End of Error occurs after the following query. if (mysql_affected_rows($dbc) == 1) { //Start saving the professional and customer participants. $appointmentID = mysql_insert_id($dbc); //Check whether the change rights or view rights are set. if(isset($_POST['appo_professionalparticipants'])) { //Extract the professional names from change rights list seperately. $line_data1 = explode("\n", $_POST['appo_professionalparticipants']); //For each extracted professional name start saving the rights. foreach($line_data1 as $key => $value1) { //Retrive the allowed professional ID from the professional table. $q2 = "SELECT professionalID FROM Professional_Table WHERE name = '$value1'"; $r2 = mysql_query($q2, $dbc); if (mysql_num_rows($r2)>0) { // Retrieve the results: $row2 = mysql_fetch_row($r2); //Prepare the professional ID. $professionalID = $row2[0]; //Professional has both change and view rights. $q3 = "INSERT INTO Appointment_Professional_Table (appointmentID, professionalID) VALUE($appointmentID, $professionalID)"; $r3 = mysql_query($q3, $dbc); if (mysql_affected_rows($dbc) == 0) { $professional_participants_save_error = true; } } } } if(isset($_POST['appo_customerparticipants'])) { //Extract the professional names from view rights list seperately. $line_data2 = explode("\n", $_POST['appo_customerparticipants']); //For each extracted professional name start saving the rights. foreach($line_data2 as $key => $value2) { $q4 = "SELECT customerID FROM Customer_Table WHERE name = '$value2'"; $r4 = mysql_query($q4, $dbc); if (mysql_num_rows($r4)>0) { // Retrieve the results: $row4 = mysql_fetch_row($r4); //Prepare the professional ID. $customerID = $row4[0]; //Professional has only view right. $q6 = "INSERT INTO Appointment_Customer_Table (appointmentID, customerID) VALUE($appointmentID, $customerID)"; $r6 = mysql_query($q6, $dbc); if (mysql_affected_rows($dbc) == 0) { $customer_participants_save_error = true; } } } } if($professional_participants_save_error) { echo '<system_error>Error occured while saving professional participants!' . mysql_error() . '</system_error>'; } else if($customer_participants_save_error) { echo '<system_error>Error occured while saving customer participants!' . mysql_error() . '</system_error>'; } else if($rights_save_error) { echo '<system_error>Error occured while saving user rights!' . mysql_error() . '</system_error>'; } else { echo '<result>The appointment has been successfully saved.' . mysql_error() . '</result>'; } } else { // Query failure. if(mysql_errno()>0) { echo '<system_error>Error occured while saving the appointment details.' . mysql_error() . '</system_error>'; } }*/ //Lines are commented up to here. mysql_close($dbc); } else { // Errors! echo '<system_error>Please correct problems with the highlighted field(s) below.</system_error>'; } echo '</response>'; exit(); ?> For your reference, I have included my dbconnect.php file also. $dbc = @mysql_connect ('localhost', 'test', 'test'); // Confirm the connection and select the database: if (!$dbc OR !mysql_select_db ('ams_db')) { // Handle the error, if desired. // Print a message to the user, complete the page, and kill the script. echo '<system_error>The site is currently experiencing technical difficulties. We apologize for any inconvenience.</system_error>'; echo '</response>'; exit(); } Your support is highly appriciated! Thanks in advance, Sampath.
  4. Dear HartleySan, I'm very happy for your quick reply for my issue and thank you very much. I worked according to your method and successfully completed my program! But for the sake of knowledge, can you just tell me whether why it does not work in the normal way as for text boxes, text areas etc.? Best Regards, Sampath
  5. Dear All, I recently started using ajax. Now I feel bit comfortable and the most problems I encounter can usually be solved referring to various support forums over the Internet. But the problem I have with check box is still could not be solved. I need to get an input from a user and save it into the database and give a message for the user for successful data saving. The input type is a check box. Following is my code segments. HTML code --------------- <td width="50%" align="left"> <input type="checkbox" id="chkadministrator" name="chkadministrator" value="on"/>Administrator </td> The code goes inside a form. Javascript code in ajax layer --------------------------------------- if(document.getElementById('submit')) { ajax.open('post', 'gui control/user_rights/submit.php'); // Function that handles the response: ajax.onreadystatechange = function() { // Pass it this request object: handleSaveResponse(ajax); } // Assemble all the form data: var fields = ['cmbprofessional', 'chkadministrator']; //var fields = ['cmbprofessional', 'chkadministrator', 'chkviewgeneralreports', 'chkaddcustomers', 'chkviewappointmentreports', 'chkscheduleappointments', 'chkscheduleappointmentsforother', 'chkcreatecalender', 'chkviewreports', 'chkdeleteprofessional', 'chkdeletecustomers']; for (var i = 0; i < fields.length; i++) { fields = fields + '=' + encodeURIComponent(document.getElementById(fields).value); } var values = fields.join('&'); // Set the request headers: ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // Send the request along with the data: ajax.send(values); return false; } submit.php file ------------------ header("Content-Type: text/xml"); echo '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><response>'; if (isset($_REQUEST['chkadministrator'])) { echo '<system_error>' . $_POST['chkadministrator'] . '</system_error>'; $administrator = 1; } else { echo '<system_error>' . $_POST['chkadministrator'] . '</system_error>'; $administrator = 0; } I need to set $administrator = 1 when user check the check box and set it to $administrator = 0 when the user uncheck the check box. The problem that I have is it is always set to $administrator = 1. As I understood, the post method sends data for the check box when only it has checked. What is actually has gone wrong with me here? Your support for this issue is highly appreciated! Thanks in advance...
×
×
  • Create New...