|
Joined: Feb 2002
Posts: 1,759
Addict
|
Addict
Joined: Feb 2002
Posts: 1,759 |
Ok, for one of my mods to my site I need a little help. Basically, its an extension of the users table. I already created the added fields to my w3t_Users table, and they are: U_Phonehome U_Phonework U_Phonecell U_Winch U_Coverage U_Calltime So, this is what I have so far: code:
// Require the library require ("/home/michiganjeepers/www/forums/main.inc.php"); $userob = new user; $user = $userob -> authenticate(); $Username = $user['U_Username']; $Password = $user['U_Password'];
// --------------------- // Send the page to them $html = new html; $html -> send_header("Recovery List",$Cat,0,$user); $html -> table_header("Recovery List"); $phpurl = $config[phpurl]; $html -> open_table();
That just pulls all the required info and checks to see who is accessing the page. So basically, what I want to do is have a form to fill out completing the information required to fill those new fields in the users table. Well, actually, I would like to query the DB first to see if they have any of this already filled out. If they do, it displays that info in the form box already, if not, it is just blank. I've tried looking at various parts of the editbasic.php for ideas on how to accomplish this, but I'm just not php savvy 
|
|
|
|
Joined: Jun 2001
Posts: 3,273
That 70's Guy
|
That 70's Guy
Joined: Jun 2001
Posts: 3,273 |
Something like: code:
$Username_q = addslashes($Username); $query = "SELECT U_Phonehome,U_Phonework,U_Phonecell,U_Winch,U_Coverage,U_Calltime FROM {$config['tbprefix']}Users WHERE U_Username = '$Username_q' "; $sth = $dbh -> do_query($query); list ($HomePhone,$WorkPhone,$CellPhone,$Winch,$Coverage,$Calltime) = $dbh -> fetch_array($sth); $dbh -> finish_sth($sth);
echo <<<UBBTPRINT
<form method="post" action="{$config['phpurl']}/addrecovery.php"> <table width="80%" border="1" cellpadding="3" cellspacing="0" align="center"> <tr> <td> Home Phone: </td> <td> <input type="text" name="homephone" value="$HomePhone" /> </td> </tr> <tr> <td> Work Phone: </td> <td> <input type="text" name="workphone" value="$WorkPhone" /> </td> </tr> <tr> <td> Cell Phone: </td> <td> <input type="text" name="cellphone" value="$CellPhone" /> </td> </tr> <tr> <td> Winch: </td> <td> <input type="text" name="winch" value="$Winch" /> </td> </tr> <tr> <td> Coverage: </td> <td> <input type="text" name="coverage" value="$Coverage" /> </td> </tr> <tr> <td> Call Times: </td> <td> <input type="text" name="calltime" value="$Calltime" /> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="submit" value="Submit" /> </td> </tr> </table> </form>
UBBTPRINT;
I think that should do it for the displaying of the info. To add the info to the database you then create another script named addrecovery.php and make it look something like this: code:
require ("$thispath/main.inc.php");
if ($GLOBALS['REQUEST_METHOD'] != "POST") { exit; } $userob = new user; $user = $userob -> authenticate(); $html = new html; if (empty($user['U_Number'])) { $html -> not_right ($ubbt_lang['NO_AUTH'],$Cat); }
$usernumber_q = addslashes($user['U_Number']); $homephone_q = addslashes($homephone); $workphone_q = addslashes($workphone); $cellphone_q = addslashes($cellphone); $winch_q = addslahses($winch); $coverage_q = addslashes($coverage); $calltime_q = addslashes($calltime);
$query = "UPDATE {$config['tbprefix']}Users SET U_Phonehome = '$homephone_q', U_Phonework = '$workphone_q', U_Phonecell = '$cellphone_q', U_Winch = '$winch_q', U_Coverage = '$coverage_q', U_Calltime = '$calltime_q' WHERE U_Number = '$usernumber_q' "; $dbh -> do_query($query);
echo <<<UBBTPRINT
Recovery information has been added.
UBBTPRINT;
I know this is very basic but I think it will get you going in the right direction.  Also, I haven't tested it and since I typed it all out in this text box while posting I am not sure how well this will work by the looks of it... lol but I think it should do the trick. 
|
|
|
|
Joined: Feb 2002
Posts: 1,759
Addict
|
Addict
Joined: Feb 2002
Posts: 1,759 |
thanks! I will try it after work today. The strange thing is, I had been working on it myself, and had the query right, as well as the list function.. and I had text boxes but nothing was showing up. Hopefully this helps 
|
|
|
|
Joined: Feb 2002
Posts: 1,759
Addict
|
Addict
Joined: Feb 2002
Posts: 1,759 |
Hey dave, thanks! Its really starting to make sense now. One slight problem. When I add info and hit submit.. it says it can't find the function addslashes. Hmm But, if I manually enter data into my user fields through phpMyAdmin, and load the main page, it does show the info in the text boxes. So.. something is slightly wrong with the add script I think. I will keep playing around with it, but if you have any ideas that would be great 
Last edited by msula; 10/11/2002 12:24 PM.
|
|
|
|
Joined: Feb 2002
Posts: 1,759
Addict
|
Addict
Joined: Feb 2002
Posts: 1,759 |
Nevermind... typo 
|
|
|
|
Joined: Jun 2001
Posts: 3,273
That 70's Guy
|
That 70's Guy
Joined: Jun 2001
Posts: 3,273 |
Yep, I see the type too... lol Glad you found it. 
|
|
|
|
Joined: Feb 2002
Posts: 1,759
Addict
|
Addict
Joined: Feb 2002
Posts: 1,759 |
Ahh.. well I have those two pages pretty much setup and formatted how I want/need them. But the most important part... people can update their info, but nobody can see their info The index page needs to basically be just a table, displaying Username, Real Name (if in their profile) and the given recovery information. The tricky part, is the only users that should be displayed are people with at least one of the new fields filled out. I don't need a big empty table with all the users who don't enter anything. That's where I'm really stuck, is how to check for that  Also.. I tried this just real quick to see if I could at least now do this on m own: code: $Username_q = addslashes($Username); $query = "SELECT U_Phonehome,U_Phonework,U_Phonecell,U_Winch,U_Coverage,U_Calltime FROM {$config['tbprefix']}Users WHERE U_Username = '$Username_q'";
$sth = $dbh -> do_query($query);
while ( list($HomePhone,$WorkPhone,$CellPhone,$Winch,$Coverage,$Calltime) = $dbh -> fetch_array($sth)) {
echo <<<UBBTPRINT
$HomePhone $WorkPhone $CellPhone $Winch $Coverage $Calltime
UBBTPRINT; }
$html -> send_footer(); $dbh -> finish_sth($sth);
That does work, but only pulls my info, I was hoping the while loop would at least somehow pull everyone's, but I don't know what I'm doing 
|
|
|
|
Joined: Jun 2001
Posts: 3,273
That 70's Guy
|
That 70's Guy
Joined: Jun 2001
Posts: 3,273 |
This should do the trick: code:
$query = "SELECT U_Username,U_Phonehome,U_Phonework,U_Phonecell,U_Winch,U_Coverage,U_Calltime FROM {$config['tbprefix']}Users WHERE U_Phonehome != '' OR U_Phonework != '' OR U_Phonecell != '' ";
$sth = $dbh -> do_query($query);
while ( list($Username,$HomePhone,$WorkPhone,$CellPhone,$Winch,$Coverage,$Calltime) = $dbh -> fetch_array($sth)) {
echo <<<UBBTPRINT
$Username $HomePhone $WorkPhone $CellPhone $Winch $Coverage $Calltime <br />
UBBTPRINT; }
$dbh -> finish_sth($sth);
Or at least give you an idea what to do next. 
|
|
|
|
Joined: Feb 2002
Posts: 1,759
Addict
|
Addict
Joined: Feb 2002
Posts: 1,759 |
wow, its amazing what a couple simple added things cna do, as from what I can tell that works perfectly! I just need to format the tables.. and it should be all set.
I know this is trivial to you dave, but it seems like magic to me, lol
|
|
|
|
Joined: Jun 2001
Posts: 3,273
That 70's Guy
|
That 70's Guy
Joined: Jun 2001
Posts: 3,273 |
hehe glad I could help 
|
|
|
|
Joined: Feb 2002
Posts: 1,759
Addict
|
Addict
Joined: Feb 2002
Posts: 1,759 |
Seems to be working great so far, I had to adjust a few things but at least it is useable! (better t han recieving a million emails with people wanting me to add their info by hand!) Anyway, just a few cosmetic questions. How can I get rid of the 2px black line between each row? I know it is stacking the tables from the loop.. but can that be changed? I basically would like it to look like the list of threads in my forum. Even with the alternating colors, that would be ideal  I tried looking at postlist.php to see how they accomplished it, but I can't obviously see where it was done. Also, not sure if this is easy to acomplish or not, but my users have been requesting the output in plain text as an option for those who want to load this info into their PDA. So I wanted to make a link on the index page say "Download PDA Friendly Version" and have it generate a plain text file they can just save. It should be fairly easy I thought since all the functions are there to pull the info, but I don't know how to stick it into a blank file to be saved  But again, thanks for your help. This little exersize has really helped me understand php/mysql
|
|
|
|
Joined: Jun 2001
Posts: 3,273
That 70's Guy
|
That 70's Guy
Joined: Jun 2001
Posts: 3,273 |
If I get some spare time today I'll see if I can put something together.
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 69
Joined: January 2001
|
|
Forums63
Topics37,575
Posts293,931
Members13,823
|
Most Online6,139 Sep 21st, 2024
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|