PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 25, 2014 9:51 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Jul 17, 2012 11:47 pm 
Offline
Forum Newbie

Joined: Tue Jul 26, 2011 4:55 am
Posts: 6
Hi,

I have created an input form in php which will submit data to ms access2010 database and after submitting go to another page which is mentioned in form action. But if I use the url for another page in action, data don't insert into the database. If I remove the action than the data is inserted. I am giving the code bellow-

Syntax: [ Download ] [ Hide ]
<script>
function inputvalidation()
{
if (document.getElementById('Com_Name').value == '') {
  alert('Insert Name');
  return false; // stop submission until textbox is not ''
  }
  else if (document.getElementById('Email').value == '') {
  alert('Insert Email');
  return false; // stop submission until textbox is not ''
  }
  else if (document.getElementById('Address').value == '') {
  alert('Insert Address');
  return false; // stop submission until textbox is not ''
  }
  else
  {
  this.document.form1.mode.value='submit';
  this.document.form1.submit();
   }
}
</script>

<html>
<form name="form1" method="post" onSubmit="return inputvalidation()" action="proc_detail.php?id=<?php echo odbc_result($qResult_main,'Proc_ID')?>">
<table align="center" style="font-family:Verdana; font-size:11px; color:#FF0000; font-style:italic;">
<tr>
<td width="20%"></td>
<td width="80%"><input name="Deadline" type="date" id="Deadline" size="20" value="<?php echo odbc_result($qResult_main,'Proc_Deadline')?>" style="visibility:hidden"></td>
</tr>
<tr style="background-color:#D2D2F9;"><td width="20%"><b>Company Name<font style="color:#FF0000">*</font>:</b></td>
<td width="80%"><input name="Com_Name" type="text" id="Com_Name" size="70" style="font-size:12px;"></td>
</tr>
<tr style="background-color:#D2D2F9;">
<td width="20%"><b>Email<font style="color:#FF0000">*</font>:</b></td>
<td width="80%"><input name="Email" type="text" id="Email" size="70" style="font-size:12px;"></td>
</tr>
<tr style="background-color:#D2D2F9;">
<td width="20%"><b>Address<font style="color:#FF0000">*</font>:</b></td>
<td width="80%"><input name="Address" type="text" id="Address" size="120" style="font-size:12px;"></td>
</tr>
<td>
<input type="submit" name="Submit" value="Submit" class="hilite">
<input type="hidden" name="mode" value="submit">
</td>
</tr>
<td></td><td></td></tr>
</table>
</form>
</html>
 


please guide me.


Last edited by Benjamin on Tue Jul 17, 2012 11:52 pm, edited 1 time in total.
Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.


Top
 Profile  
 
PostPosted: Wed Jul 18, 2012 5:44 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2775
Location: .za
saifphp wrote:
I have created an input form in php which will submit data to ms access2010 database and after submitting go to another page which is mentioned in form action. But if I use the url for another page in action, data don't insert into the database. If I remove the action than the data is inserted. I am giving the code bellow-

Could you clarify what you mean by "another page"?

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Thu Jul 19, 2012 3:38 am 
Offline
Forum Newbie

Joined: Tue Jul 26, 2011 4:55 am
Posts: 6
Hi,

Thanks for your replay.

Another page means the target page which I want to show after submitting data. By clicking on the submit button, two things will be happened- 1. data will go to the database, 2. another page will be displayed which I mentioned in the form action.

Thanks again.


Top
 Profile  
 
PostPosted: Thu Jul 19, 2012 4:38 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2775
Location: .za
saifphp wrote:
If I remove the action than the data is inserted

This means that the code that inserts the data into the database is on the same page as the form. It's refered to as 'calling the form on itself'. Is there any other code on the form page?
saifphp wrote:
By clicking on the submit button, two things will be happened- 1. data will go to the database, 2. another page will be displayed which I mentioned in the form action.

If you want something to display on the target page it has to be placed on the target page and (usually) be dependent on the results of something, in your instance submitting data to the database. A simple example
Code:
if (insertedIntoDatabase)
    'Data successfully added'
else
    'Data wasnt added.'

If you have the message on a totally different page than the value in the target attribute you would redirect depending on the result of something. You could use header() or perhaps a javascript alternative to achieve this.

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Thu Jul 19, 2012 6:26 am 
Offline
Forum Newbie

Joined: Tue Jul 26, 2011 4:55 am
Posts: 6
Thanks a lot for your support

Your suggestion was very very much helpful and my problem is solved. I have used a separate page for inserting data and than redirected to the target page.

Thanks again


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group