Jump to content

cspgsl

Members
  • Posts

    26
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://

Profile Information

  • Gender
    Not Telling
  • Location
    Malagash Nova Scotia

cspgsl's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have found a php script that allows a user to download a file and then prevent further downloads for a set amount of time. You can find it here http://www.web-development-blog.com/archives/limit-the-number-of-downloads-per-client/ As I am not very strong in coding, I am hoping with some assistance to modify the concept so that it will not allow a registered user to print a coupon I offer more than once. The process would work as such: the user registers (I am developing in Joomla using the Community Builder login / member component) the user clicks a link in the activation email welcome page opens with a link to the coupon user clicks the coupon link the link opens a page with the coupon and a print button in the same window to get around a popup blocker user clicks the print button and the page prints out the coupon print button also advances the page to a thank you page if the user clicks on the back button to access the link again the script prevents the user from opening the coupon window again with the message that there is only one coupon per user) I am assuming that this is doable but don't mind being told otherwise. I would be very grateful if there are any coders out there that could assist. Thanks
  2. it was really just a matter of closing and reopening the php tags. it then worked fine. so simple... thanks for the response
  3. the following error is returned from the code below Parse error: syntax error, unexpected '<' in ....line 19 the problem is between the <span></span>tags darned if i can see it... i'm too new [code] <? if ($_SESSION['loggedin'] === true):     //do nothing elseif (remembereduser()):     loginremembereduser(); else:     $form="";     render_login_form(); endif; function render_login_form() {     global $form;     $attribs = array();     require_once "HTML/QuickForm.php";     $form = new HTML_QuickForm('loginform', 'post', $_SERVER['PHP_SELF'],"",NULL,TRUE);     $form->addElement("header", "","Login here");     $form->addElement("hidden","freshtest", getfreshtestid()); <span style="color:darkblue;"<?Hello : =empty($_SESSION['bsd_username'])?>" We'd really like to learn your name.  Please login or register" : $_SESSION['bsd_username'] . " ( ".$_SESSION['bsd_profession'] .")" > </span> $_SESSION['bsd_username'] . " ( ".$_SESSION['bsd_profession'] .")" ?</span>     $form->addElement("text", "username", "Username:", $attribs);         $form->addElement("password", "pwd", "Password:", $attribs);     $form->addElement("checkbox", "rememberme", "", "Remember me", $attribs);     $buttons[] = &HTML_QuickForm::createElement("reset", "reset", "Clear");     $buttons[] = &HTML_QuickForm::createElement("submit", "submit", "Login");     $form->addGroup($buttons, null, null, " ");     $form->addElement("link", "","", FULLPATH."?action=forgottenpassword","Forgotten your password?", $attribs);     $form->addRule("username", "You must supply a username", "required");     $form->addRule("pwd", "You must supply a password", "required");     $form->registerRule('freshtest', 'callback', 'isfreshsubmission');     $form->registerRule('passwordverify', 'callback', 'verifypassword');     $form->addRule("freshtest", "You cannot use the backbutton to login", "freshtest");     $form->addRule("pwd", "Either the username or password is incorrect", "passwordverify");             if ($form->validate()):         return $form->process("login");     else:         $contents = '<div class="loginform">'. $form->tohtml().'</div>';         require_once "template.php";         exit;     endif; } function login($value=null){     global $form;     unset($_SESSION['freshtest']);     $_SESSION['loggedin'] = true;     $_SESSION['username'] = $form->exportvalue("username");     $rm = &$form->getelement("rememberme");     setrememberme($rm->getchecked()); } function setrememberme($state) {     global $db, $dbusertable;     if ($state === true):         $str =  "setting oookie";         $expiry = time() + 31536000;         $dbexpiry = $expiry;     else:         $str =  "deleting cookie";         $expiry = time()  -3600;         $dbexpiry = null;     endif;     $result = $db->query("update $dbusertable set rememberme=? where username=?", array($dbexpiry, $_SESSION['username']));     setcookie("bsd_username", $_SESSION['username'], $expiry); } function remembereduser() {     global $db, $dbusertable;     if (!isset($_COOKIE['bsd_username'])) return false;     $num = $db->getOne("Select count(*) from $dbusertable where username=? and rememberme > ?", array (trim($_COOKIE['bsd_username']), time()));     return ($num == 1); } function loginremembereduser() {     $_SESSION['loggedin'] = true;     $_SESSION['username'] = trim($_COOKIE['bsd_username']);     setrememberme(true); }     function verifypassword($value) {          //note you cannot use this for crypted passwords, but md5 passwords work ok.          global $form, $db, $dbusertable;     $pwd=trim($value);     $submittedusername = trim($form->exportvalue("username"));     $num = $db->getOne("select count(*) as cnt from $dbusertable where username=? and pwd=?", array($submittedusername, md5($pwd)));     return  ($num == 1); } function logout() {     unset ($_SESSION['username']);     unset ($_SESSION['loggedin']);     setrememberme(false); } ?> [/code]
  4. Sorry, I am afraid you lost me. Are you suggesting that I use the code as in the following post? (your quote): [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]but work on the following posted code: [a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=92839&view=findpost&p=371846\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=371846[/a] [/quote] That is going back to the beginning, isn't it? [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I see you have fallen back to another one :)[/quote] I am using the last one you sent with the opening comments[code]//require("secret/db_connection.php"); // $kt_login_user = "tom"; // replaces the SESSION to test [/code] I also tried the code you sent where you indicated there was a parse error [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--][a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=92839&pid=371771&mode=threaded&show=&st=30&#entry371771\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...30&#entry371771[/a][/quote] and I was indicating that it was returning the contents of the user's record without error. The only thing was if I changed it it was not updating the user's record. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Remember also that when you set/start a new session, it wont take effect untill the next pageload, meaning setting a session and using it on the same code without reloading the page wont work[/quote] Are you referring to seeing the changes made without logging out and restarting the session? i am beginning to think you might have several different issues [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] not the leaset of which is being very green[/quote] that all needs to be fixed Thanks
  5. Good morning again. It's now questionable as to who I am talking with more... you or my wife #lol It would appear that this change has made all the difference with respect to eliminating any errors on opening the update page. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] try changing --> require_once('../../Connections/connBSD.php'); to --> require('../../Connections/connBSD.php'); [/quote] I added this too [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Also change your content of connBSD.php to this $selectDB = mysql_select_db("$database_connBSD") or die("Unable to select db"); [/code][/quote] I went back and inserted your post from yesterday morning (below) where you indicated there was a parse error and it is now working without error except that it isn't updating the user's record. [code]  <?php print "<p> </p>"; if(isset($_POST['update'])) { $new_msg = htmlspecialchars($_POST['welcome']); $sql = mysql_query("update users set welcome = '$new_msg' where username = '$kt_login_user'"); if($sql) {   print "<b>Saved!</b>"; } } $qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user' limit 1"); $r = mysql_fetch_array($qry); $kt_welcome = $r['welcome']; if(!$kt_welcome) { $kt_welcome = "My default text"; } echo <<<__HTML_END <form method="post" action="entree.php"> <textarea name="welcome" cols="80" rows="20">$kt_welcome</textarea> <br /> <input type="submit" name="update" value="Save" /> </form> __HTML_END; mysql_close(); ?> [/code] Also, your last code starting [code]// require("secret/db_connection.php");[/code] also works but, it does not updating the user's record either. I have printed out your code and I am now trying to understand what each line does. I'm sure I will be back to you with questions.
  6. [code] <? session_start();         if (!isset($_SESSION['kt_login_user'])):         $_SESSION['kt_login_user'] = "Anonymous";         $_SESSION['kt_name'] = $_POST['kt_name'];         $_SESSION['kt_welcome'] = $_POST['kt_welcome']; endif; error_reporting(E_ALL); ?> <?php require_once('../../Connections/connBSD.php'); ?> [/code] Contents of Connections/connBSD.php [code]<?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_connBSD = "localhost"; $database_connBSD = "pencils_users"; $username_connBSD = "pencils_cspgsl"; $password_connBSD = "drtlk001"; $connBSD = mysql_pconnect($hostname_connBSD, $username_connBSD, $password_connBSD) or trigger_error(mysql_error(),E_USER_ERROR); ?>[/code] The No database selected only appears after I click on Save. Even then, the echo $kt_login_user; returns a result Wife is off antique hunting and has the dog's leads in the car... no my fault. I let them out in the backyard, that should keep the carpets clean but there goes the grass (oh my). See last post [!--quoteo(post=371867:date=May 6 2006, 03:56 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 6 2006, 03:56 PM) [snapback]371867[/snapback][/div][div class=\'quotemain\'][!--quotec--] could you provide how you connect to your db, and if you are including this as a file with include(), require(), require_once() etc.[/quote] [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]using --> require("path/dbfile.php"); where dbfile.php contains my previous db connection setup is tested and is working. Form action you put to $_SERVER[PHP_SELF] or the actual name you have chosen for this file, for example "update_welcome.php" or whatever.[/quote] I changed it to return to the page opened from logging on (with the multiple links)
  7. [!--quoteo(post=371861:date=May 6 2006, 03:31 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 6 2006, 03:31 PM) [snapback]371861[/snapback][/div][div class=\'quotemain\'][!--quotec--] If your session username finds a valid user it should work - the code i suplied has form action pointed on itself - one file handling both view stored and update. You dont get any mysql errors either ?? [/quote] If you are referring to [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]action="this_page.php"[/quote] it consistently returns "No Database selected" regardless of teh user I log in with. My process goes from a login page to a page with sevearl links, one of which is a link to the update page (there will be a few update pages by the time I'm done). Could it have anything to do with that? I don't get the mysql error that the @ sign fixed (the @ sign is [u]no longer[/u] in the page) Alpine: I have to walk the dogs or else they will pee on my carpets and the wife will get mad; you know, she who must be obeyed... Back in about an hour. Thanks.
  8. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] dont worry - we are solving a problem. [/quote] Humble thanks [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]end a variable set with ;[/quote] I should have caught that one... [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]no misspelling in column names used?? [/quote] I take it that the names are as in the session list in the bindings window (I am using Dreamweaver MX and MX Kollection). There are no errors as the selections are made from the session in bindings [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--](don't mis-use @)[/quote] good point, thanks [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] following i have tested[/quote]I took this and pasted it into the page changing the form action to a page in my site. Upon opening the page the text from the user's record is there and has not failed. When I click Save it opens the file I specified. In reading through the code it would appear that it should update the record however, it does not. Instead what happens is if I go back to the update page I get a message "No database selected" and the balance of the page below echo $kt_login_user; is blank (view source reveals no content). If I click on Back and then return to the update page the same No database message is there. It requires logging out once to reset it to work again. In any event, the field is not updated.
  9. Good day Alpine, it seems you sleep like I do. Your last code yesterday was working brilliantly until I resumed my online session this morning. For whatever reason the code broke overnight (internet gremlins???) which is strange as it worked for the hour or so of testing done at the end of yesterday's dialogue. The message I was getting this morning [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pencils/public_html/interview/home_page.php on line 56 [/quote] was familiar so I placed an @ sign in front of [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]mysql_fetch_array($qry);[/quote] and it resolved the problem and it worked for a short time. I then retested it several more times. Logged in and out several times, closed and re-opened the browser, tried it in IE and FX and Netscape and found that "My default text" is returned regardless of the user. I tried your latest post but get the following error [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected T_VARIABLE in /home/pencils/public_html/interview/home_page.php on line 57[/quote] where this is the line of offending line [code]$sql = mysql_query("update users set welcome = '$new_msg' where username = '$kt_login_user'"); [/code] Sorry to be such a pain...
  10. I have always thought it better to be born lucky than smart however, this learning curve is very enjoyable. I would just like to learn at a little more competent rate though... That seems to have resolved it, [b]thank you, thank you[/b] Now if someone could point me in the direction of creating an update record form and incorporating the code I could go to bed and actually sleep tonite. [!--quoteo(post=371715:date=May 5 2006, 05:24 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 5 2006, 05:24 PM) [snapback]371715[/snapback][/div][div class=\'quotemain\'][!--quotec--] As far as i know, no-one is born with programming skills :) - we all learn something new almost every single day we do this. [/quote]
  11. Apart from the code, I must admit that I'm having trouble visualizing how to put this in an update record form...
  12. Sorry... back to the original scenario... now only returning "MY default text" for both users [!--quoteo(post=371706:date=May 5 2006, 05:03 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 5 2006, 05:03 PM) [snapback]371706[/snapback][/div][div class=\'quotemain\'][!--quotec--] *lol* so simple and yet so hard - but THIS TIME..... [code] <?php $kt_welcome = "My default text"; echo $kt_login_user; print "<p>&nbsp;</p>"; $qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user' limit 1"); if($qry) { $r = mysql_fetch_array($qry); $kt_welcome = $r['welcome']; } ?> <textarea name="welcome" cols="80" rows="20"><?php echo $kt_welcome; ?></textarea> <?php mysql_close(); ?> [/code] [/quote]
  13. Same problem, not returning "My default text" when field is empty. I tested it by putting something into the empty field and it returned the new value. I very much appreciate everyone's time btw. [!--quoteo(post=371700:date=May 5 2006, 04:54 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 5 2006, 04:54 PM) [snapback]371700[/snapback][/div][div class=\'quotemain\'][!--quotec--] okay, something weird with your num_rows, and thats causing your problem, new one here: [code] <?php echo $kt_login_user print "<p>&nbsp;</p>"; $qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user' limit 1"); if($qry) { $r = mysql_fetch_array($qry); $kt_welcome = $r['welcome']; if(!$kt_welcome OR $kt_welcome =="") { $kt_welcome = "My default text"; } } ?> <textarea name="welcome" cols="80" rows="20"><?php echo $kt_welcome; ?></textarea> <?php mysql_close(); ?> [/code] !$kt_welcome OR $kt_welcome =="" checks if variable dont exist or is empty/doesnt contain any values (you can prefer to use the function empty() in some cases) I assume you only have unique usernames in your db.... else this will fail for sure [/quote] only two usernames and they are unique
  14. Hope I haven't upset anyone...
  15. [!--quoteo(post=371682:date=May 5 2006, 04:06 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 5 2006, 04:06 PM) [snapback]371682[/snapback][/div][div class=\'quotemain\'][!--quotec--] unless i misunderstood this problem, i suggest: [code] $qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user'"); if(mysql_num_rows($qry) == 1) { $r = mysql_fetch_array($qry); $kt_welcome = $r['welcome']; if(!$kt_welcome OR $kt_welcome =="") { $kt_welcome = "My default text"; } } [/code] ** EDITED a query cut'n paste error *lol* [/quote] I changed the code to reflect your edit I received [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/pencils/public_html/interview/home_page.php on line 47 [/quote] so I added @ to [code]if(@mysql_num_rows($qry) == 1)[/code] With the change to your suggested the problem is reversed. Now the textarea contains the correct data for the user with data in the field and no entry for the user with no data in the field (which I assume is returning what it sees (empty) in the field. It should return "My default text" if there is no data in the users field. Code update: [code]<?php echo $kt_login_user ?> <p>&nbsp;</p> <?php $qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user'"); if(@mysql_num_rows($qry) == 1) { $r = mysql_fetch_array($qry); $kt_welcome = $r['welcome']; if(!$kt_welcome OR $kt_welcome =="") { $kt_welcome = "My default text"; } } ?> <textarea name="welcome" cols="80" rows="20"><?php echo $kt_welcome; ?></textarea> <?php mysql_close(); ?> [/code] Alpine: I don't understand this line [code]if(!$kt_welcome OR $kt_welcome =="") [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.