Jump to content

Form Submit Help


herghost

Recommended Posts

Hi all,

 

I have the below form:

<?php
session_start();
//Customer Details
include('../config/connect.php');

$title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
$forename = (isset($_POST['forename'])) ? trim($_POST['forename']) : '';
$surname = (isset($_POST['surname'])) ? trim($_POST['surname']) : '';
$company = (isset($_POST['company'])) ? trim($_POST['company']) : '';
$nameno = (isset($_POST['nameno'])) ? trim($_POST['nameno']) : '';
$fline = (isset($_POST['fline'])) ? trim($_POST['fline']) : '';
$sline = (isset($_POST['sline'])) ? trim($_POST['sline']) : '';
$city = (isset($_POST['city'])) ? trim($_POST['city']) : '';
$state = (isset($_POST['state'])) ? trim($_POST['state']) : '';
$zip = (isset($_POST['zip'])) ? trim($_POST['zip']) : '';
$country = (isset($_POST['country'])) ? trim($_POST['country']) : '';
$tax = (isset($_POST['tax'])) ? trim($_POST['tax']) : '';

//Contact Details
$email = (isset($_POST['email'])) ? trim($_POST['email']) : '';
$phone = (isset($_POST['phone']))? trim($_POST['phone']) : '';
$fax = (isset($_POST['fax'])) ? trim($_POST['fax']) : '';

//Account Details
$username = (isset($_POST['username'])) ? trim($_POST['username']) : '';
$password = (isset($_POST['password'])) ? md5($_POST['password']): '';


$query = "INSERT INTO customers (title, forename, surname, company, nameno, fline, sline, city, state, zip, country, tax, email, phone, fax, username, password) 

VALUES

('$title', '$forename', '$surname', '$company', '$nameno', '$fline', '$sline', '$city', '$state', '$zip', '$country', '$tax', '$email', '$phone', '$fax', '$username', '$password')
";
$result = mysql_query($query);
if (mysql_affected_rows() == 1) 

{
$caok = 'caok';
$coak = $_SESSION['caok'] ;
header ('Location http://localhost/jolly/office/home.php');
} 

else 
	{
		die('Error: ' . mysql_error());
	 	}

?>

 

 

 

 

I have a couple of problems that may be linked.

 

To explain a bit further, my form appears in a div tag using ajax.

 

Basically me source would look like this:

 

<div id=header>include header.php</div>

<div id =links>include links.php</div>

<div id = body></div>

<div id = footer>include footer</div

 

When you click a link from link.php the result appears in the body <div> tags.

 

Now my form is called addcustomer.php, however the browser url always shows as home.php

 

Basically the form above should enter information into the database (which works) set a session called caok if succesful and redirect to the base of home.php

 

if fails should show mysql error.

 

The problem I am getting is that the browser is redirecting to /addcustomer.php regardless of if the form is succesfull or not.

 

What am I doing wrong?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/194126-form-submit-help/
Share on other sites

I have no idea of the TRUE/FALSE of your if or not but to set a session what you have is not correct.

$caok = 'caok';

$coak = $_SESSION['caok'] ;

 

fixed

$caok = 'caok';

$_SESSION['caok']=$caok ;

 

Why not set a var to mysql_affected_rows

$whats_up=mysql_affected_rows;

and echo  it out before the if so you can see, whats up? and why the statement fails.

 

 

HTH

Teamatomic

Link to comment
https://forums.phpfreaks.com/topic/194126-form-submit-help/#findComment-1021517
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.