PDA

View Full Version : php session + get info from database then show form?


nanny
08-24-2007, 12:00 AM
Hi I have the sessions working well. What I am trying to accomplish is this:
As admin I will be submitting a lot of listings online at first to get the ball rolling.
A person then wants to edit their listing without logging in so they click the link "Update Listing"
This takes them to a form that collects their name and telephone number and if it is a match it will show the form to be edited.
Now I can get it to say their name and a form conditionally show within the session but the listing id is not carrying through to show the edit form?
Any suggestions? I have tried session and get but maybe a go to detail link is needed prior to the form showing. Is this true?

On completion of this form it will have a hidden variable to make the status not active again, as it would be active. I would then receive an email and see the listing before approving it to be active again.
I thought about just having the form and email it to me but that is double work - this way I can check and click.

davidj
08-24-2007, 08:15 AM
append the ID to the form action


action="process_form.php?id=$id"

nanny
08-24-2007, 09:11 AM
I got it working I simply had the unset session attached and for some reason it wouldn't work, so I removed it.
I am needing to however match two items in the database.
i can check them individually before continueing on with the session but I have found that I really need to check both match the same id
I am checking for a business name and a telephone number.
If someone gives a business name from id number 4 and a telephone number from id number 6 the session still continues because it starts from the business name.
How to repair this fault, should I do a session array or use

if ($_POST['businessname'] && $_POST['tel'] == $_POST['id']) { unset $error array() };

Not sure if I am doing this right. I tend to complicate things sometimes, but I am willing to learn...

davidj
08-24-2007, 09:40 AM
is the ID the telephone number?

here you are comparing the two vars

$_POST['tel'] == $_POST['id']

nanny
08-24-2007, 11:46 PM
Hi davidj
No the id of the table is separate to the telephone field and the businessname field.
But I am wanting the same telephone & business field to be searched for the same id in the table otherwise it is all over the place.

davidj
08-24-2007, 11:49 PM
But I am wanting the same telephone & business field to be searched for the same id in the table otherwise it is all over the place.

please read this back to yourself as this doesnt make sense

nanny
08-24-2007, 11:56 PM
OK I will go back to the beginning.
It is a session and in the first form for the user to fill out.
1: Business name
2: Telephone number
These are meant to match to the corresponding id of the listing.
At the moment I can place Business name for Suji Store and the telephone for Mick's Store and it will continue on the session and show the link to detail for the business name.
For a little extra security, I want the Business name for Suji Store and the Telephone for Suji Store to go together - i.e. the same listing id not just by the business name or there is no point in having two questions in the form.
Hope that makes sense.
Thanks.

nanny
08-25-2007, 03:23 AM
O.K
this is my code so far for error checking:

session_start();
$_SESSION['classbusinessname'] = $_POST['classbusinessname'];
if (array_key_exists('Continue', $_POST)) {
$classbusinessname = trim($_POST['classbusinessname']);
if (empty($classbusinessname)) {
$error['classbusinessname'] = 'Enter business name';
}
$LoginRS__query = "SELECT classbusinessname, tel FROM listingf WHERE classbusinessname='" . $classbusinessname . "' ";
mysql_select_db($database_config, $config);
$LoginRS=mysql_query($LoginRS__query, $config) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser == 0){
$error['classbusinessname'] = "$classbusinessname can not be found. Please contact SalonSpa.";
}
$tel = trim($_POST['tel']);
if (empty($tel)) {
$error['tel'] = 'Enter phone number';
}
$LoginRS__query = "SELECT classbusinessname, tel FROM listingf WHERE tel='" . $tel . "'";
mysql_select_db($database_config, $config);
$LoginRS=mysql_query($LoginRS__query, $config) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser == 0){
$error['tel'] = "$tel can not be found. Please contact SalonSpa.";
}
if (!isset($error)) {
header('Location: update_f.php');
exit;
$_POST = array();
}
}


I am not getting the two to match, i.e. businessname and tel from listingf

Any suggestions??

davidj
08-25-2007, 08:34 AM
what does this do???

$_POST = array();

as its inside the condition which EXIT's it wont run???

i cant see anything wrong with it other than your code layout is messy.

you have your tel and businessname checks apart from each other. and your using DW recordsets which im disapointed at.


1: Business name
2: Telephone number
These are meant to match to the corresponding id of the listing.


im still not sure what you want

as above you state 'name' and 'number' must match the ID? do they match the ID together as a string?