Page 1 of 1

Direct access from the main menu to a record if existed

Posted: 2019-10-22 16:00
by tchristophe
Hi everyone,

I have a table 'adherents' with a single record possible for a user.
If the record do not exist, the view of the table is empty and it's possible to complete the form and save it.
If a record still exited I want the user directly connect to the single record (he can modify and save the informations in the form)...
I need to verify if a record exist or not to drive the user in the good case when he click on button from the main menu.
I have tried the code below but I dont know how use 'set_record_owner'...

Code: Select all

$email = $memberInfo['email'];
$resultat = sqlValue("SELECT ads_adherents.courriel FROM ads_adherents WHERE ads_adherents.courriel = '$email'");
*if($resultat !== ''){	
	set_record_owner("Adherents", $email, $courriel);
	}
	else
	{
	}	
Any information on the 'set_record_owner' function is welcome !
Thank for your help, ideas, etc.
Chrsitophe

Re: Direct access from the main menu to a record if existed

Posted: 2019-10-22 19:04
by pbottcher
Hi,

the usage is:

set_record_owner($tn, $pk, $user) -- Set/update the owner of given record

where $tn is your tablename, $pk the primary key of that table, $user the username to set as owner

Re: Direct access from the main menu to a record if existed

Posted: 2019-10-23 09:57
by tchristophe
Hi pböttcher,

I try this way...
Thank you very mutch
Christophe

Re: Direct access from the main menu to a record if existed

Posted: 2019-10-23 16:19
by tchristophe
Hi everyone,

In fact, I want to call the single record of the user in the table ' adherents' from the home page button link with the 'ads_adherents.idAdherent' number key... ( hope I'm understandinable...) :?:

Code: Select all

$email = $memberInfo['email']; // Only one possible
$selectedID = sqlValue("SELECT ads_adherents.idAdherent FROM ads_adherents WHERE ads_adherents.courriel = '$email'");
if($selectedID > 0){

		// How can I config my URL here to call the single record view ?
		
		=> http://localhost/busistone/ads_adherents_view.php?SelectedID=$selectedID
				
		}	
Thank gain for your help, ideas, suggestions, etc.
Regards
Christophe

Re: Direct access from the main menu to a record if existed

Posted: 2019-10-23 19:27
by pbottcher
Hi,

use

redirect($url);

where $url is your url

$url='http://localhost/busistone/ads_adherent ... selectedID

Re: Direct access from the main menu to a record if existed

Posted: 2019-10-24 09:10
by tchristophe
Thank again pböttcher !

Re: Direct access from the main menu to a record if existed

Posted: 2019-10-24 15:29
by tchristophe
Humm,

I've insert the code below...

Code: Select all

// Redirection sur enregistrement en page wiew si existant
			if($selected_ID > 0){				
				$URL = 'ads_adherents_view.php?SelectedID=$selected_ID';
				redirect($URL);
			}
And I receive the answer "ERR_TOO_MANY_REDIRECTS" from the serveur (Wamp)
Any Idea ?

Thank you
Christophe

Re: Direct access from the main menu to a record if existed

Posted: 2019-10-24 16:46
by pbottcher
Hi,

well, you check if there is a record and if there is one, you redirect to the page with the record.
When reaching the page, you check if there is a record and if there is one, you redirect to the page with the record.

This results in the looping redirects.

You need to catch that situation to understand from where the page was called (or what parameters are in the url).