close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Redirect on Insert Failure

Thread began 2/01/2012 9:32 am by Mike Perry | Last modified 2/10/2012 9:45 am by Mike Perry | 2714 views | 9 replies |

Mike Perry

Redirect on Insert Failure

I looked but couldn't find a previous solution.

I am adding an Admin section that includes a Product Insert page created with DA 2.1. The product names must be unique, and are set up as a Unique field in the db. I want to trap the MySQL error that occurs if someone tries to add an already existing product name and display my own error page.

What code should I use to redirect to the error page, and where in the form processing code should I place it??

Thanks,

Mike

Sign in to reply to this post

Jason ByrnesWebAssist

you will need to use server validation from either CSS Form Builder or Form Toolkit for this.


see this post for details:
showpost.php?p=20725&postcount=3

Sign in to reply to this post

Mike Perry

Originally Said By: Jason Byrnes
  you will need to use server validation from either CSS Form Builder or Form Toolkit for this.


see this post for details:
showpost.php?p=20725&postcount=3  


Thanks, Jason. . .

:)

Sign in to reply to this post

Mike Perry

Hey Jason -- this validation checks for a value in EITHER field. I need to check for both being present in the same record.

Example:

brand: tester
product: tapeit

I need to find both items in the same record.

Thoughts?

Sign in to reply to this post

Jason ByrnesWebAssist

create the recordset to check for both fields, it;s all in how you set the recordset filter up.

Sign in to reply to this post

Mike Perry

Originally Said By: Jason Byrnes
  create the recordset to check for both fields, it;s all in how you set the recordset filter up.  


Hi Jason -- I got this working, but i found I have another challenge to overcome before I can check it.

I need to include a brandID in the data for the Insert Record. The brandID is available in both the brands table and the products table (from current product records). I expect the best way to determine the proper brandID for the brand of the product being added is to query either the brands or the products table for the brandID where the brandName = the brandName from the form. However the code for the attached page inserts a (NULL) in the brandID column.

How can I extract the right brandID and add it to the Insert code?? I have excluded the recordset filtering code for now. . .

Thanks

Attached Files
productsinsert.zip
Sign in to reply to this post

Jason ByrnesWebAssist

well, you should not be storing both the brand name and the brand ID in the products table, you should only store the brand ID. the brand name will be defined in the brand table.

you can get the brand name back when displaying the product info using a joined query.


see the following page for details on using join queries:
sql_join.asp

Sign in to reply to this post

Mike Perry

Originally Said By: Jason Byrnes
  create the recordset to check for both fields, it;s all in how you set the recordset filter up.  


Back to this one:

I'm having trouble figuring out how to set up the filtered RS for the validations.

I have three fields on the form: brandName (a dynamic select field), productName (a text field), and bName (a hidden dynamic select to capture the brandName for the record insert). Record Insert is working properly.

How do I create a useful recordset for the server validation validation? If I understand the flow, the RS needs to be create on the POST, and the validation needs to occur after the RS is created. Do I create (or copy) the recordset code inside the code for the validation, or is there a simpler way??

Current page code attached - throws an error even though I try to insert a brandName/productName combo that I know doesn't exist..

Thanks,

mp

Attached Files
productsinsert.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the problem is code order.


the code for the validation is at lines 5 - 19

php:
<?php 

if ($_SERVER["REQUEST_METHOD"] == "POST")  {
  
$WAFV_Redirect "";
  
$_SESSION['WAVT_productsinsert_231_Errors'] = "";
  if (
$WAFV_Redirect == "")  {
    
$WAFV_Redirect $_SERVER["PHP_SELF"];
  }
  
$WAFV_Errors "";
  
$WAFV_Errors .= WAValidateNM($totalRows_validate "",-1,0,"",",.",true,1);

  if (
$WAFV_Errors != "")  {
    
PostResult($WAFV_Redirect,$WAFV_Errors,"productsinsert_231");
  }
}
?>




this needs to be moved to line 87, so that validation occurs after the recordset and before the insert.

Sign in to reply to this post

Mike Perry

Originally Said By: Jason Byrnes
  the problem is code order.


the code for the validation is at lines 5 - 19

php:
<?php 

if ($_SERVER["REQUEST_METHOD"] == "POST")  {
  
$WAFV_Redirect "";
  
$_SESSION['WAVT_productsinsert_231_Errors'] = "";
  if (
$WAFV_Redirect == "")  {
    
$WAFV_Redirect $_SERVER["PHP_SELF"];
  }
  
$WAFV_Errors "";
  
$WAFV_Errors .= WAValidateNM($totalRows_validate "",-1,0,"",",.",true,1);

  if (
$WAFV_Errors != "")  {
    
PostResult($WAFV_Redirect,$WAFV_Errors,"productsinsert_231");
  }
}
?>



this needs to be moved to line 87, so that validation occurs after the recordset and before the insert.  


I always forget to check the code sequence -- thanks Jason. . .

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...