Javascript-onsubmit trigger event sends form data to related php for processing

Source: Internet
Author: User
Problem details: the onsubmit trigger event sends the form data to the relevant php for processing, but how can we avoid triggering the event when data is faulty? Functiondosubmit () {window. open (& #39; num3.php? Cf & #39; + window. form. cf. value + & #39; & amp; cf1 & #39; + window. form. cf1.value) ;}] phpjavascript

Problem details: the onsubmit trigger event sends the form data to the relevant php for processing, but how can we avoid triggering the event when data is faulty?

Function dosubmit () {window. open ('num3. php? Cf = '+ window. form. cf. value +' & cf1 = '+ window. form. cf1.value );}


Require_once ('appvars. php ');
Require_once ('varvars. php ');

If (isset ($ _ POST ['submit ']) {// 10th rows

$ Name = $ _ POST ['name'];
$ Score = $ _ POST ['score '];
$ St = $ _ FILES ['st'] ['name'];
$ St_type = $ _ FILES ['st'] ['type'];
$ St_size = $ _ FILES ['st'] ['size'];
$ Output_form = false;

If (empty ($ name) | empty ($ score) | empty ($ st ))
{
Echo 'something is wrong!
';
$ Output_form = true;
}
// 20th rows
Else {

If ($ st_type = 'image/GIF') | ($ st_type = 'image/jpeg ') | ($ st_type = 'image/pjeg ') | ($ st_type = 'image/png ') & ($ st_size> 0) & ($ st_size <= MAX_FILE_SIZE ))
{

If ($ _ FILES ['st'] ['error'] = 0 ){

$ Target = GW_UPLOADPATH. $ st;
// 30th rows

If (move_uploaded_file ($ _ FILES ['st'] ['tmp _ name'], $ target )){

$ Dbc = mysqli_connect (HOST, USER, PASSWORD, NAME );

$ St = $ _ FILES ['st'] ['name'];
$ Query = "insert into B (date, st, score, name )".
"VALUES (NOW (), '$ St',' $ score ',' $ name ')";
// 40th rows

Mysqli_query ($ dbc, $ query)
Or die ('uu ');

Echo 'you are success to add dates to mysql '.'
'; Echo 'name:'. $ Name .'
'; Echo 'Score:'. $ Score .'
'; Echo 'photo:'. ''; // 50th echo'

Back to index page

';

// Clear the score datas
$ Name = "";
$ Score = "";
$ St = "";

Mysqli_close ($ dbc );

} // If (move_uploaded_f

Else
{
Echo $ _ FILES ['st'] ['error'];
Echo'
File Not moved !! '; // Row 60th

}

} // If ($ _ FILES ['st'] ['error']

Else
Echo 'There is something wrong to upload the file! Plese upload it agian .';

} // If ($ st_type = 'image/GIF'

Else echo'

The screen pic must be a GIF, JPEG, or PNG image and the file '. 'size must fit'. '(MAX_FILE_SIZE/1024)'. 'kb.

';
} // Else // 70th rows

// Try to delete the temporary screen shot image file.

@ Unlink ($ _ FILES ['st'] ['tmp _ name']);

} Else $ output_form = true;

If ($ output_form ){
?>

Your name:
Your score:
Your Photo:
Commodity transactions; commodity swaps;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.