Form submission and stopping on errors

I have the same header on another page that deletes entries from the database and it redirects fine which makes me thing there is something wrong with the rest of the code?

Thanks

[php]
if ( $valid == 1 ) {

  // If we don't, run the insert query
$dbid = mysql_connect ('localhost', 'usernamr', 'password');
          mysql_select_db('database',$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`, `state`, `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: thanks.php');
    exit;
  
  }

}
[/php]

Here is what I am going to guess, your insert or connection is causing an error and your not seeing it. This would stop the rest of the page from loading.

I could be wrong, but I haven’t ever seen it written with 2 arguments:
Try that and see if that changes anything -

$result = mysql_query($query) or die(“INSERT error:”. mysql_error());

Also, is req_id an auto_incremented field?? If so leave it out of your query all together. Both the field and the value and MySQL will auto fill this for you.

[size=99px]EDIT: Upon looking into this function I see you can do it the way you have, but I believe you don’t need it as it will just use the last connetion that was opened. In referance to - mysql_query()[/size]

I was also looking at your query and place the values under the fields and noticed that you have all correct except there is one that says state for the field and status for the value…

You may have a field that is incorrect as well and this would throw an error as well. Just one more thing to try and change.

Also, I would place an echo right under the header() function just make sure it is even getting that far. As I said before I am guessing its not even getting there and killing out on the query.

Thanks for your replies, i’ve removed the req_id field and value from my query and have made the $result = mysql_query($query) or die(“INSERT error:”. mysql_error()); part one argument instead of two.

The state and status things i know about, i was having problems and had to change the name of the field in the database.

I put an echo after the header and it is printing it out so there can’t be anything wrong with the code above it?

I really can’t see why there is a problem with this… :-(

it must be:[php]header(‘Location: http://www.bookserv.com/thanks.php’);[/php]
(absolute URI)

but u have to create that file first of all (i get a 404):
http://www.bookserv.com/thanks.php

Doh! You guys will want to kill me when you realise what i’ve done! :smiley:

but still keep the absolute URI in mind. cause it is wrong with just the filename.
just because your browser still redirects you to the right place, it’s not said that all browsers will.

Well, glad you got it figured out! :) And that is what this is all about, learning!

Thanks very much for your help guys. :smiley:

Just some background info: headers get sent when output is generated :slight_smile: Whether it be a space at the start of the file, or an echo “html”; line, doesn’t matter. If you have headers to send (like the one you do, or cookies or sessions), do it before you send any output to the browser.

Sponsor our Newsletter | Privacy Policy | Terms of Service