Form submission and stopping on errors

Well, you’re basically saying it all here :slight_smile:

[quote author=“Zyppora”]

Well, you’re basically saying it all here :slight_smile:

one small thing mentiont by Ragster00:
change every $_REQUEST to $_POST

but i think it is ready to be uploaded.

P.S.: please post the URL here after you did upload it.

I’ve done this, what i’m planning on doing next is splitting the form into 3 parts, the actual form, the form handler and the functions part, if i’m going to use a database for the pull down menus it would make more sense to have database connections set up in another php file…

The script can be seen at

http://www.bookserv.com/request_submit.php

Oh, any ideas why my redirect isn’t working?

Thanks for your help, this site is the best! :D

No, you mistook my post: a database is the way to go. Be sure to make your anti-bot question (and answers!) random, or a botwriter could simply customize the bot to submit the correct answer contiuously. It’s best to use a database table for that as well :wink:

As for a MySQL connection, I put a PHP class (PHP5) in the Code Snippets section of this forum (it’s moderately documented too), you might want to take a look at that for MySQL connections.

Brilliant, i’ll take a look at that. With the help of various tutorials on the internet, i’ve also managed to build a log in system, hopefully it wont be too difficult to make something to manipulate the submitted data…

One thing, looking at the form, is there any reason why the redirect doesn’t work once the data has been added to the database?

Thanks

The action attribute of your form tag should point to the target page. It looks empty in the code you posted.

It is empty, i’ve fixed that now but the darn thing still isn’t redirecting when the data has been submitted…

hhhmmmmmmm

When I check the page again it still doesn’t show any value in the action attribute … did you update the page on the website?

Ahhh, i was testing it on my local network, it’s on the internet now, like you’ve suggested, i changed the action="" value and it’s still not redirecting…

Just so you know, The page submitted for me. It went to a blank page. Maybe you need to do a Shift-Refresh. This will force your browser to reload the page from the website instead of using the one in Cache.

Just a thought.

That’s what it’s doing for me, surely the address in the address bar should change when the data is submitted?

I guess I would start trying to debugg it. First thing I would is try to find out where it is getting too…

So I would comment out my header code and place something like:

echo “I am ready to redirect”; or something like that. That way you can tell if it is even getting where you think it is at.

Than if it isn’t start going through the if statements and see if it isn’t getting somewhere it shouldn’t be, like some if statement that isn’t validating as it should and its just stoping in an empty else statement.

After thought… In your if statement, of checking to make sure the color was selected, make an else statement there and put in something there that says - echo “THIS IF DID NOT VALIDATE”; or anything to tell you where you are at. This will at least tell you if your if statement condition is working properly.

PS: Sorry, I didn’t realize there was a header redirect at the bottom of the php code there.

No worries, i’ll have a play tonight and let you know how i get one… I’ve moved onto something else now, i’ve made a basic login system which is working very well, i just need to find out how to display the contents of a database in a table correctly… I think i’ll start another thread. :D

Thanks for your help.

Hi, i was wondering if i could get some help on this. I’ve gone back to working on this bit of code and still can’t get the bugger to redirect.

I’ve changed the redirect to echo ‘thanks’; when the form is submitted and that is working, it’s just whenever i do a redirect i end up with a blank page…

Any ideas guys?

Thanks

could u post that bit of code again?

P.S.: make sure to use a absolute URL with location.

I’ve tried using an absolute path and it’s still not working. What is making me scratch my head is the fact that it is doing an echo so it shouldn’t be any of the if statments breaking it…

The code is below

[php]

<?php $colour = Red; if (isset($_POST['submitted'])) { $valid = 1; // Bike details $manufacturer = mysql_escape_string(trim($_POST['manufacturer'])); if ( empty($manufacturer) ) { $valid = 0; $manufacturer_error = 'Please select a manufacturer.'; } $model = mysql_escape_string(trim($_POST['model'])); if ( empty($model) ) { $valid = 0; $model_error = 'Please enter the model of bike..'; } $capacity = mysql_escape_string(trim($_POST['capacity'])); $year = mysql_escape_string(trim($_POST['year'])); if ( empty($year) ) { $valid = 0; $year_error = 'Please select a year.'; } // Parts $part_one = mysql_escape_string(trim($_POST['part_one'])); if ( empty($part_one) ) { $valid = 0; $part_error = 'Please enter a part.'; } $part_two = mysql_escape_string(trim($_POST['part_two'])); $part_three = mysql_escape_string(trim($_POST['part_three'])); $part_four = mysql_escape_string(trim($_POST['part_four'])); $part_five = mysql_escape_string(trim($_POST['part_five'])); // Personal details, some of these don't need cleaning up, i.e the contact prefrence $full_name = mysql_escape_string(trim($_POST['full_name'])); if ( empty($full_name) ) { $valid = 0; $name_error = 'Please enter a name.'; } $telephone = mysql_escape_string(trim($_POST['telephone'])); $alt_telephone = mysql_escape_string(trim($_POST['alt_telephone'])); $email = mysql_escape_string(trim($_POST['email'])); if ( empty($email) ) { $valid = 0; $email_error = 'Please enter an email address.'; } $area = mysql_escape_string(trim($_POST['area'])); $comments = mysql_escape_string(trim($_POST['comments'])); // Fields that do not need cleaning up $status = $_POST['status']; $sent = $_POST['sent']; $contact_pref = $_POST['contact_pref']; // Does the entered number match the generated number? if ($_POST['spam_protect']!=$colour) { $valid = 0; $spam_error = 'Please try again.'; } // Do we have errors? if ( $valid == 1 ) { // If we don't, run the insert query $dbid = mysql_connect ('localhost', 'username', 'password'); mysql_select_db('table',$dbid) or die ("Cannot find database"); $query = "INSERT INTO `request_data` (`req_id`, `manufacturer`, `model`, `capacity`, `year`, `part_one`, `part_two`, `part_three`, `part_four`, `part_five`, `full_name`, `telephone`, `alt_telephone`, `email`, `contact_pref`, `area`, `status`, `sent`, `comments` ) VALUES ('', '$manufacturer', '$model', '$capacity', '$year', '$part_one', '$part_two', '$part_three', '$part_four', '$part_five', '$full_name', '$telephone', '$alt_telephone', '$email', '$contact_pref', '$area', '$status', '$sent', '$comments')"; $result = mysql_query($query,$dbid) or die("INSERT error:".mysql_error()); // If all is cool, this will redirect to a thank you page. header('Location: the thank you page goes here); exit; } } ?>

[/php]

could u post the code u are really using inside the if statement (without the placeholders)?

Do you mean the location in the header part?

yes!
in the code u posted there is a syntaxerror (no second '). But that was created by canging the code. maybe there is a small error in that is not showen in the changed code. otherwise i have no idea why it’s not working.

as you already posted the URL there should be no problem in leaving the Location as it is?
so maybe you can post the part from if($vaild till } as it is.

if u want to, u may send me a PM as well.

Sponsor our Newsletter | Privacy Policy | Terms of Service