PDA

View Full Version : Help with allowing users to update their listings on php....


nanny
04-28-2006, 04:52 AM
Hi I have php and mysql and have users allowing to register and then place a listing.
I have a regid table for registration and class_ad table for the listings.
I have successfully done the user registration, edit and delete pages. Also the Insert Record for the listings. I have the search and results working really well but I cannot for the life of me find a way to allow the registered users to edit their listings.
I tried to do a search form - didn't work, tried update record - didn't work.
The foreign key is the regid on the class_ad table.
For the registration pages edit/delete I used the username from regid as a variable e.g. Select* from regid WHERE regid.reg_username = 'varUsername' varUsername = $_SESSION['MM_Username']
I tried to do that with inner join and all sort of filters with the users listing edit pages but it wouldn't work. I either got all listings results in the program or none.
I can't seem to get the connection between the registerd user and their listings.
Any suggestions please????
I would really appreciate it.

davidj
04-28-2006, 08:42 AM
first you need to treat the update page as a detail page

if you can pass a users details to another page then you almost there

can you do this?

nanny
04-29-2006, 06:54 AM
Thanks for your reply. That is my ultimate aim. I can do this with the registration page as I am using the $_SESSION['MM_Username'] variable. I can't get this to work the same to show all listings by the user.
I imagine my users will have multiple listings, this is the problem. I can't seem to show the listings the users have. I seem to get either all listings from all users or none at all.
From there I thought I could do the link to detail to update or delete. The foreign key in the listings page is the regid not the reg_username being used for the session.
Should I change the $_SESSION['MM_Username'] variable to $_SESSION['regid']
I have tried that however and the result gives all users listings not just the registered user within the session.
Hope that makes sense.
Thank you.

davidj
04-29-2006, 11:46 AM
post the code that makes up this recordset

nanny
04-30-2006, 01:16 AM
Hi I will give you the code and the tables to see if it makes better sense.

CREATE TABLE class_ad
(
classid INT(5) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (classid),
regid INT(5) NULL,
class_category VARCHAR(50) NULL,
categorytype VARCHAR(50) NULL,
classTitle CHAR(50) NULL,
classDescription text NULL,
classbusinessname VARCHAR(80) NULL,
stateCode VARCHAR(80),
countryid INT(5),
contactname VARCHAR(120) NULL,
contactphone1 VARCHAR(10) NULL,
contactphone2 VARCHAR(10) NULL,
contactfax VARCHAR(10) NULL,
contactemail VARCHAR(100),
contactwebsite VARCHAR(80),
picture1 text,
picture2 text,
picture3 text,
product1 VARCHAR(50) NULL,
product2 VARCHAR(50) NULL,
product3 VARCHAR(50) NULL,
product4 VARCHAR(50) NULL,
bushours_m VARCHAR(50) NULL,
bushours_m2 VARCHAR(50) NULL,
bushours_t VARCHAR(50) NULL,
bushours_t2 VARCHAR(50) NULL,
bushours_w VARCHAR(50) NULL,
bushours_w2 VARCHAR(50) NULL,
bushours_th VARCHAR(50) NULL,
bushours_th2 VARCHAR(50) NULL,
bushours_f VARCHAR(50) NULL,
bushours_f2 VARCHAR(50) NULL,
bushours_s VARCHAR(50) NULL,
bushours_s2 VARCHAR(50) NULL,
bushours_sun VARCHAR(50) NULL,
bushours_sun2 VARCHAR(50) NULL,
classsell_point VARCHAR(120) NULL,
voucher VARCHAR(100) NULL,
adscreation_date date NULL,
adsexpiration date NULL,
expires date NULL default '',
UNIQUE KEY regid (regid),
KEY class_category (class_category ),
KEY categorytype (categorytype ),
KEY stateCode (stateCode),
KEY countryid (countryid)

);

CREATE TABLE regid
(
regid INT(5) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (regid),
reg_fullname VARCHAR(50) NULL,
reg_busname VARCHAR(80) NULL,
reg_username VARCHAR(100) NULL,
reg_password VARCHAR(6) NULL,
reg_industry VARCHAR(50) NULL,
reg_phone VARCHAR(10) NULL,
);
The reg_username is the email address so it will be easy for users to remember their username.

This is the recordset code for the register update page to edit or delete. This works really well.

$varUsername_register = "=";
if (isset($_SESSION['MM_Username'])) {
$varUsername_register = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_config, $config);
$query_register = sprintf("SELECT * FROM regid WHERE regid.reg_username = '%s'", $varUsername_register);
$register = mysql_query($query_register, $config) or die(mysql_error());
$row_register = mysql_fetch_assoc($register);
$totalRows_register = mysql_num_rows($register);


This is the code for the dynamic table I am trying to display for the registered users listings to go to either a detail page or to edit/delete listing.

$varUsername_reglisting = "=";
if (isset($_SESSION['MM_Username'])) {
$varUsername_reglisting = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_config, $config);
$query_reglisting = sprintf("SELECT * FROM regid, class_ad WHERE regid.reg_username = '%s' GROUP BY regid.regid = class_ad.regid", $varUsername_reglisting);
$query_limit_reglisting = sprintf("%s LIMIT %d, %d", $query_reglisting, $startRow_reglisting, $maxRows_reglisting);
$reglisting = mysql_query($query_limit_reglisting, $config) or die(mysql_error());
$row_reglisting = mysql_fetch_assoc($reglisting);

if (isset($_GET['totalRows_reglisting'])) {
$totalRows_reglisting = $_GET['totalRows_reglisting'];
} else {
$all_reglisting = mysql_query($query_reglisting);
$totalRows_reglisting = mysql_num_rows($all_reglisting);
}
$totalPages_reglisting = ceil($totalRows_reglisting/$maxRows_reglisting)-1;



Hope this is what you are after. I get only one listing with this and it is the same listing showing for every user.
Thank you.