Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data checking and redirection

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
HI all,

I have a form with three fields it.

dlid (primary key, auto increment)
Surname
firstname
email

it routes to a switch that checks to see if the person completing the form has done so already, (sort of a login form if you will.) however if the person HAS NOT completed the form previously, it will add the data to a database. All of this works fine.

What I want to do next, is once the person has entered the details into the form, regardless of whether they have just been created or if they were already in the database, I want to redirect to an update form with their details in the fields.

I can't post the form back to itself because there are times I need to add the records.

Here is the code that I have so far:

Code:
//the int_login function
function int_login($surname,$firstname)
	{
		$connection = db_connect();
		$query =mressf(" SELECT * FROM coll_downloads WHERE surname = '%s' AND  firstname = '%s'",
($surname),($firstname));
	
	$result = mysql_query($query);
	
	//counts the number of rows in the query
	$number_of_posts = mysql_num_rows($result);
	if($number_of_posts == 0)
	{
		return false;	
	}
	else
	
	
	$row = mysql_fetch_array($result);
	
	$_SESSION['int'] = $row;
	
	return true;
	
	}



//the switch
case "create":
			if (int_login($params['int']['surname'],$params['int']['firstname']))
	{
		flash_notice('welcome back');	
		$post = $_SESSION['int'];
		$route['view']='edit';
	}
	else
	{
		create_int($params['int']);
		
		redirect_to('interest/edit');
		
	}
		
	break;

I don't expect the user to update their info if they don't need to, but there will be download options relating to their profiles.

How do I get the users data into the update fields, based on the primary key from either a new record or from finding an old one?

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
at a very basic level, show them a form and add a hidden field that contains the unique ID for that user.

not great security though. next level up is to store the unique key in a session variable (which you might do anyway if there is login management).
 
I think you want to insert into the database and then go to a complety different form which you want populating with data from the DB (however it got there) ???
I think in the form that inserts the data when the php has done the inserts you can get the autoincremement id and use this as a value on the query string of the redirect i.e.
Code:
header("location:", "http:/newpage.php?key=4567")
hope the syntax is correct.
If you enter from a diffeent route e.g. the data already exists you just need to get the key value
When you execute newpage.php get the data from the database using the key. Fetch the data in data items e.g.$surname.
In the HTML part of the form you then display/amend the value in a line like:
Code:
<form...>
<input type=text><?php echo $surname?>
</form>
My syntax will be way off but you get the idea.
Is this what you wanted to do ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top