Page 1 of 1

php newbie

Posted: Tue Nov 07, 2006 10:54 am
by acwe88
Hi there

Apologies if my question is to much or doesnt make any sense atall

i have a php login form. When you register an account it stores all the details in a mysql database


I can get all the values into the database but not this part

<tr><td>Customer Or Supplier?<\/td><td><INPUT TYPE="radio" NAME="customer" VALUE="customer" checked>customer<INPUT TYPE="radio" NAME="customer" VALUE="supplier" \/>Supplier<\/td><\/tr>';

I need it so the radio button value is also stored alongside the rest of the details (ie user name and password) in the database

Any help will be much appreciated

Thanks
Alex


Re: php newbie

Posted: Tue Nov 07, 2006 11:32 am
by Christopher
In PHP you can specify that the value is put into an array variable by adding "[]" to the form field name like this:

Code: Select all

<INPUT TYPE="radio" NAME="customer[]" VALUE="customer" checked>customer
<INPUT TYPE="radio" NAME="customer[]" VALUE="supplier" >Supplier';
You would then check to see if $_POST['customer']['customer'] or $_POST['customer']['supplier'] are set.

Posted: Wed Nov 08, 2006 4:05 am
by acwe88
Hi there

Apologies jcart

Right OK

I have this sign up form http://nfaulkne.224.netxcellent.com/cus ... gister.php

and all works well except customer or supplier part

what i need is when a user signs up for an account they select wether they are a customer or supplier

once they have created an account and login if they are a customer they will be redirected to the customer section of the site and if they are a supplier they get redirected to the supplier part of the site.

any help will be much appreciated

Thanks
Alex

Posted: Wed Nov 08, 2006 4:14 am
by Christopher
I believe I explained the "customer or supplier part" part above. I am not sure there is a question in your post?

Posted: Wed Nov 08, 2006 4:19 am
by acwe88
apologies its just i havent got a clue what that means

so im trying to get a awnser for dumb people (like me)

You would then check to see if $_POST['customer']['customer'] or $_POST['customer']['supplier'] are set.

So would this post the value to the database?

Thank

Posted: Wed Nov 08, 2006 4:48 am
by acwe88
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


sorry for being such a pain in the arse


Ive finally got the value to store in the database So when a user signs up the customer/supplier value is stored in the DB. 

So how would i redirect a user if they login as a customer?

and how would i redirect a user if they login as a supplier?


This is my login code

Code: Select all

<?php

session_start();
session_regenerate_id(true); // Generate new session id and delete old (PHP >= 5 only)
include_once("includes/functions.php");
include_once("includes/config.php");

// Checks if user has submitted username and password through the login form.
// If so, checks authenticity in database and create session.
if(isset($_POST['subform'])){

	// check for errors
	$alertArr = array();

	if(!$_POST['user'])			$alertArr[] = $ALERT['USER_NO'];
	if (!$_POST['pass_field'])	$alertArr[] = $ALERT['PASS_NO'];

	// clean up
	$_POST['user'] = cleanString($_POST['user'], 30);
	$_POST['pass_field'] = '';
	$_POST['pass'] = cleanString($_POST['pass'], 40);
	$_POST['salt'] = '';
	$_POST['key'] = '';

	if (count($alertArr) == 0) {

		// Username and password correct, register session variables
		$_SESSION['username'] = $_POST['user'];
		$_SESSION['password'] = $_POST['pass'];

		// User has requested to remember being logged in,
		// so we set a cookies containing username, called c_name.
		// The cookie containing password, called c_pass, is set by javascript,
		// encrypted with salt, but NOT with key because the key changes every session.
		if(isset($_POST['remember'])) {
			setcookie("c_name", $_SESSION['username'], time()+60*60*24*100, "/");
		}

		// cannot redirect using header() because header is already sent with session_start()
		// using html meta refresh instead
		$refresh = "index.php";
		exit(include_once(HTML_PATH."html_refresh.php"));
	}
}

// Display the login form AFTER other header stuff like cookies.
// (Cookies should be set before sending any other header information)
$alert = displayAlert($alertArr);

if ($_POST['pass_field']) $_POST['pass_field'] = "";

// html
include_once(HTML_PATH."html_login.php");
?>
Thanks
Al


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]