Hi All,
This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description:
1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one record to EDIT.
2)Now if he selects ONLY ONE record, then in the SECOND page where he will enter NEW values for record and submit the form then the JavaScript which I had written there in is not working. It is not getting the FORM values in variables.
3)But if he selects more than one then the script is working fine and giving me correct values for all the records.
4)Suppose he selects 2 records and enters new values for them and hit the submit button then both the record should get processed sequentially, means, first Record A should get into processing and for this a message should get displayed as "Processing " and when it gets done then the message should appear as "Processed" and then starts the cycle for the next record in line. In between if any error occurs for any record the Erros message should get displayed but processing should carry on for subsequent records, if present.
As far as I've understood my requirement I know I have to use AJAX for this and below is my attempt to this but here also I'm confused about the strange behaviour. Whats happening here is, though the Ajax function is called once for each record but in the function the statements inside
"if(xmlObj.read yState == 4 && xmlObj.status == 200)" is executing twice for each record. Below is my code. Can anyone point me out what mistake am I doing. -
/*edit_process.php starts here*/
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
<HTML>
-
<script type="text/javascript">
-
function ajaxFunction()
-
{
-
var xml;
-
try
-
{
-
xml=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
-
}
-
catch (e)
-
{
-
try
-
{
-
xml=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer 6.0+
-
}
-
catch (e)
-
{
-
try
-
{
-
xml=new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 5.5+
-
}
-
catch (e)
-
{
-
alert("Your browser does not support AJAX!");
-
return false;
-
}
-
}
-
}
-
return xml; // Mandatory Statement returning the ajax object created
-
} //ajaxFunction closes
-
-
function postValues(params, div, xmlObj)
-
{
-
var url="edit_trailer.php";
-
var flag;
-
//alert(params);
-
-
xmlObj.open("POST", url, true);
-
xmlObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-
xmlObj.setRequestHeader("Content-length", params.length);
-
//xmlObj.setRequestHeader("Connection", "close");
-
-
xmlObj.onreadystatechange = function()
-
{
-
alert("Ready state is: " + xmlObj.readyState);
-
if(xmlObj.readyState != 4)
-
{
-
alert('processing for ' + div);
-
document.getElementById(div).innerHTML = '<img src="http://bytes.com/images/loader.gif">';
-
}
-
-
if(xmlObj.readyState == 4 && xmlObj.status == 200)
-
{ //All below statements are executing twice for each record
-
alert('processed for ' + div);
-
document.getElementById(div).innerHTML = '<img src="http://bytes.com/images/loader2.gif">';
-
alert(xmlObj.responseText);
-
flag=true;
-
alert('returning from callback ' + flag);
-
return;
-
}
-
}
-
xmlObj.send(params);
-
alert('returning after send ' + flag);
-
return flag;
-
} //postValues closes
-
-
function submit_data()
-
{
-
document.getElementById('update').disabled = true;
-
-
var xmlHttp;
-
xmlHttp=ajaxFunction();
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request");
-
return;
-
}
-
//alert("Ajax created");
-
-
var name, id, synop, thumb, url, recID;
-
name = document.edit.elements["name[]"];
-
-
if (name.length==undefined) //this part is not working when there is one record
-
{
-
alert('only one element');
-
name = document.edit.name;
-
id = document.edit.id;
-
synop = document.edit.synop;
-
thumb = document.edit.thumb;
-
url = document.edit.url;
-
recID = document.edit.recID;
-
-
alert('Name ' + name.value);
-
alert('Id ' + id.value);
-
alert('Syn ' + synop.value);
-
alert('thumb ' + thumb.value);
-
alert('url ' + url.value);
-
}
-
else //this part is working when there are more then one record
-
{
-
id = document.edit.elements["id[]"];
-
synop = document.edit.elements["synop[]"];
-
thumb = document.edit.elements["thumb[]"];
-
url = document.edit.elements["url[]"];
-
recID = document.edit.elements["recID[]"];
-
-
flag=true;//set flag to true to call function for the first record
-
for(i=0;i<name.length;i++)
-
{
-
var param="name="+name[i].value+"&id="+id[i].value+"&syn="+synop[i].value;
-
param+="&thumb="+thumb[i].value+"&url="+url[i].value+"&recId="+recID[i].value;
-
-
var div='div'+(i+1);
-
-
if(flag)
-
{
-
alert(flag + ' bfore calling');
-
flag=false;//set flag to false and get its value from the function
-
flag=postValues(param, div, xmlHttp);//call function
-
alert(flag + ' after calling');
-
}
-
-
} //for loop closes
-
-
}// else closes
-
-
return false;
-
}
-
</script>
-
</HEAD>
-
-
<BODY>
-
<?php
-
require("db_connect.php");
-
require("db_open.php");
-
if (!$conn)
-
{
-
exit("Error connecting to the database: " . $conn);
-
}
-
-
//This value is coming from FIRST page where admin select record for editing
-
$record = $_POST['record'];
-
$query = "select mov_name, mov_id, mov_synop, mov_thumb, page_name ";
-
$query.= "FROM bhod_test_trailers WHERE mov_nos=";
-
?>
-
<FORM method="post" id="edit" onSubmit="return submit_data()" NAME="edit" enctype="multipart/form-data">
-
<TABLE border="0" cellspacing="0" cellpadding="0" align="center" width="500">
-
<?php
-
$divid=1;
-
foreach ($record as $rec)
-
{
-
$sql = $query . $rec;
-
$result = mysql_query($sql);
-
if (!$result)
-
{
-
echo 'Could not run query: ' . mysql_error();
-
exit;
-
}
-
$row = mysql_fetch_row($result);
-
?>
-
<TR>
-
<TD width="96" align="left" valign="top">
-
<img src="trailers/<?php echo $row[3]; ?>.jpg" border="0" width="92" height="85">
-
</TD>
-
<TD width="254" align="left">
-
<TABLE border="0" cellspacing="0" cellpadding="0" width="254">
-
<input type="hidden" name="recID[]" value="<?php echo $row[1]; ?>" />
-
<TR>
-
<TD align="left" valign="top">
-
<label for="mov_name">Movie Name:</label>
-
<input type="text" name="name[]" value="<?php echo $row[0]; ?>" />
-
</TD>
-
</TR>
-
-
<TR>
-
<TD align="left" valign="top">
-
<label for="mov_synop">Synopsis:</label>
-
<textarea name="synop[]" cols="20" rows="3"><?php echo $row[2]; ?></textarea>
-
</TD>
-
</TR>
-
-
<TR>
-
<TD align="left" valign="top">
-
<label for="mov_id">Clip ID:</label>
-
<input type="text" name="id[]" value="<?php echo $row[1]; ?>" />
-
</TD>
-
</TR>
-
-
<TR>
-
<TD align="left" valign="top">
-
<label for="page_name">URL:</label>
-
<input type="text" name="url[]" value="<?php echo $row[4]; ?>" />
-
</TD>
-
</TR>
-
-
<TR>
-
<TD align="left" valign="top">
-
<label for="mov_thumb">Thumbnail:</label>
-
<input type="file" name="thumb[]" />
-
</TD>
-
</TR>
-
</TABLE>
-
</TD>
-
<TD width="150" align="left" valign="top">
-
<div id="div<?php echo $divid; ?>"></div> //this div will hold our process status
-
</TD>
-
</TR>
-
-
<TR>
-
<TD colspan="3"><BR></TD>
-
</TR>
-
-
<?php
-
$sql = '';
-
$divid++;
-
}//for loop closes
-
?>
-
<TR>
-
<TD colspan="3">
-
<input type="submit" id="update" value="Update" />
-
</TD>
-
</TR>
-
</TABLE>
-
</FORM>
-
</BODY>
-
</HTML>
-
/*edit_process.php ends here*/
-
1 4608 acoder 16,027
Recognized Expert Moderator MVP
It's executed twice because you're calling the Ajax function twice.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ryan Hubbard |
last post by:
I'm inserting a record into MySQL 4.0 using Visual Basic ADO. When
using the AddNew and Update method I am unable to retrieve the value
of a Auto incrment field (Yes I know I can MoveLast but this icreases
the update time by a factor of 10 and when your talking about 200,000
inserts its way to long). Is there a way to insert the record into
multiple tables in one statement where you can use the value of the
auto incremented field as the...
|
by: Greg Ofiesh |
last post by:
Anyone who can help,
I have two tables T1 and T2. T1 has fields K1 and F2 and T2 has fields
K2 and F1. F1 is the foreign key relating to K1 and F2 is the foreign
key relating to K2.
My initial question has been how can I add a row to both tables with
accurate Fx values in one SQL INSERT statement? I have been told it
cannot be done.
|
by: DG |
last post by:
Hi,
Can anyone advise how to execute multiple statements in a single query
batch. For example-
update customers set customer_name = 'Smith' where customer_name =
'Smyth';
select * from customers;
I can execute each statement individually but get the 'you have an error in
|
by: Roger Withnell |
last post by:
I'm using ASP, VBScript and SQL Server.
I'm also using UTF-8 character set and so my codepage is 65001 and SQL
Server datatype nvarchar.
I can insert unicode characters correctly into the database table using
INSERT.... (field1) ...VALUES ......... (N'Characters').
How do I do this using Rs.Update viz-a-viz:
|
by: csgraham74 |
last post by:
Hello,
im using MS Access as a front end to link to MYSQL. although this is
possibly an Access issue i thought someone would be able to help me.
the error message "ODBC--insert on a linked table 'tablname' failed" is
displayed when i attempt to insert records to the MYSQL table.
Does anyone know of a way round this ?? im using the most recent MYSQL
driver and i have only text fields in my insert statement.
| |
by: MP |
last post by:
Hi
trying to begin to learn database using vb6, ado/adox, mdb format, sql
(not using access...just mdb format via ado)
i need to group the values of multiple fields
- get their possible variations(combination of fields),
- then act on each group in some way ...eg ProcessRs (oRs as RecordSet)...
the following query will get me the distinct groups
|
by: ebindia0041 |
last post by:
This is like the bug from hell. It is kind of hard to explain, so
please bear with me.
Background Info: SQL Server 7.0, Asp.net 1.1 with c#
I'm inserting simple records into a table. But one insert command is
placing 2 or 3 records into the table. The 'extra' records, have the
same data as the previous insert incident, (except for the timestamp).
Here is an example. Follow the values of the 'Search String' field:
|
by: WATYF |
last post by:
Hi there... I have a huge text file that needs to be processed. At the
moment, I'm loading it into memory in small chunks (x amount of lines)
and processing it that way. I'd like the process to be faster, so I'd
like to try creating multiple threads, and having them load different
chunks of the file at the same time and process it asynchronously.
Is it possible to do something like that, and if so, what would be
needed to do so?
|
by: djmeltdown |
last post by:
I'm having trouble getting a foreach() loop to insert a record into a MySQL Database. Which I've never had any trouble before, it just seems quirky.
I've tried the mysql_query statement without a preceeding variable as well.
System information
Server
Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8e mod_autoindex_color PHP/5.2.3 Time: 12/07/2007 01:20:06 PM
PHP
PHP Version: 5.2.3 Safe Mode activated: no PHP Memory...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |