php newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
acwe88
Forum Newbie
Posts: 24
Joined: Tue Nov 07, 2006 10:47 am

php newbie

Post 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

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php newbie

Post 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.
(#10850)
acwe88
Forum Newbie
Posts: 24
Joined: Tue Nov 07, 2006 10:47 am

Post 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
Last edited by acwe88 on Wed Nov 08, 2006 4:16 am, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I believe I explained the "customer or supplier part" part above. I am not sure there is a question in your post?
(#10850)
acwe88
Forum Newbie
Posts: 24
Joined: Tue Nov 07, 2006 10:47 am

Post 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
acwe88
Forum Newbie
Posts: 24
Joined: Tue Nov 07, 2006 10:47 am

Post 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]
Post Reply