Jump to content

genista

Members
  • Posts

    149
  • Joined

  • Last visited

Everything posted by genista

  1. Ah sorry about that didn't post that, but have done it and no its still not working. Is it  something to do with?: [code=php:0] if (isset($_POST['test1']) == "on")     $test1 = "true";  else     $test1 = "null"; [/code]
  2. Unless the boxes and pictures are dynamic, ie random pictures or something like that I would think you probably just want a html tutorial and then a basic tutorial on php? You might want to be a bit more specific with your question and possibly post some code too as they are both very erroneous questions....
  3. Ok I have done that but still nothing, here are the two pages: updatedetails.php [code=php:0] $id = $_SESSION['username']; $query = "select * from suppliers where username='$id'";     //now we pass the query to the database $result=mysql_query($query, $link) or die("MySQL query $query failed.  Error if any: ".mysql_error());     //get the first (and only) row from the result     $row = mysql_fetch_array($result, MYSQL_ASSOC);     $username=$row['username'];     $password=$row['password'];     $first_name=$row['first_name']; $test1=$row['test1'];     html part: <p>test1:</td><td><input type="checkbox" name="test1" value="<?php if($test1 == "on"){" checked=\"checked\"";}?> [/code] Then we have the results page: [code=php:0] $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; if (isset($_POST['test1']) == "on")     $test1 = "true";  else     $test1 = "null"; $query = "UPDATE suppliers SET first_name='$first_name', etc etc. [/code] Hugs and kisses to all of you if you can help with this!
  4. Thanks, yes I have only posted a snippet of the html. I have edited it though with your suggestion, but still nothing. Should I move: [code=php:0] if (isset($_POST['test1']) == "on")     $test1 = "true";  //  I don't know what $test1 is supposed to be, change as needed.   else     $test1= "null"; [/code] from the results page to the page that contains the html? But then when you submit the page it runs the above routine anyway, oh I am confused now..
  5. Hi, I have checkboxes which I need a user to be able to update, the issue is that when you load the page the checkboxes are not echoing the results from the database. I have the following code which is the html: [code=php:0] <p>Beautician:</td><td><input type="checkbox" name="beautician" value="<?php if($test1 == "on"){echo" CHECKED";}?> </p> [/code] The value that checks for 'on' is actually in the page that receives the result from the above code: if (isset($_POST['test1']) == "on")     $test1 = "true";  //  I don't know what $test1 is supposed to be, change as needed.   else     $test1= "null"; [/code] So the question is how can I echo these results? Thanks, G
  6. Hi all, I want to be able to display a check box checked (if the value is checked of course) off the folowing code: [code=php:0] <p>Terms:</td><td><input type="checkbox" name="terms" value="<?php echo 'terms'; ?>" > [/code] The variable is passed like so: [code=php:0] if (isset($_POST['terms']) == "on")     $terms = "true";      $terms = "null"; [/code] What would I need to use? I am running an update users details form. Thanks, G
  7. Ok so now I have used before the $query the following code, but still no joy: [code=php:0] if (isset($_POST['submit'])) {     if (isset($_POST['test1'])) {echo 'you checked the Beautician checkbox';}     else {echo '';} } [/code] Any ideas as this is driving me nuts.... Thanks, G
  8. Ok so I now have: [code=php:0] $password=($_POST['password']);     $first_name=($_POST['first_name']); $last_name=($_POST['last_name']);     $address_line1=($_POST['address_line1']);     $address_line2=($_POST['address_line2']);     $town=($_POST['town']);     $county=($_POST['county']);     $postcode=($_POST['postcode']);     $daytime_phone=($_POST['daytime_phone']);     $mobile_phone=($_POST['mobile_phone']);     $email_address=($_POST['email_address']); $val = isset ($_POST['test1']) ? ($_POST['test1']) : 'NULL'; Test1 being a checkbox. Then we have $query = "UPDATE suppliers SET first_name='$first_name', last_name='$last_name', password='$password', address_line1='$address_line1', address_line2='$address_line2', town='$town' , county='$county', postcode='$postcode', daytime_phone='$daytime_phone', mobile_phone='$mobile_phone', email_address='$email_address', test1='$test1', etc etc [/code] I am still getting an undefined inded as before, I assume I have misunderstood your answer..
  9. Hi all, After messing around with this and making it complicated I have created a very simple script to allow a user to update their details. The problem sits with checkboxes that are not filled in come up as undefined indexes. I have a page with html that allows the user to update, it then passes all the data to this form for processing, I need some way in here of posting the data even when it is empty: [code=php:0] Session start information ect at the top then, <?php      //now we need to get the information passed into us from the edit data form      $first_name=addslashes($_POST['first_name']);      $maiden_name=($_POST['maiden_name']);     $last_name=($_POST['last_name']);     $address_line1=($_POST['address_line1']);      $address_line2=($_POST['address_line2']);      $town=($_POST['town']);      $county=($_POST['county']);     $postcode=($_POST['postcode']);     $daytime_phone=($_POST['daytime_phone']);     $mobile_phone=($_POST['mobile_phone']);     $evening_phone=($_POST['evening_phone']);     $email_address=($_POST['email_address']); $test1=($_POST['test1']); $test2=($_POST['test2']); $query = "UPDATE users SET first_name='$first_name', maiden_name='$maiden_name', last_name='$last_name', address_line1='$address_line1', address_line2='$address_line2', town='$town', county='$county', postcode='$postcode', etc etc $result=mysql_query($query) or die("Could not insert data.".mysql_error());      //$result represents the status of the operation true if it worked false if it failed      if($result){          print "Your details have been sucesfully updated. You can go back to the <a href=members.php>index</a> page now.";      }else{          print "Could not update data.";      }      //finally close the connection      mysql_close(); [/code] Thanks, G
  10. Not sure if this is what you mean, but I just added: [code=php:0] <?php //Check if $message is set, and output it if it is: if(!empty($messages)){     displayErrors($messages); } ?> [/code] Still no joy though
  11. Hi all, I have the following script for a user to update their details: [code=php:0] $id = $_SESSION['username']; $query = "select * from suppliers where username='$id'";     //now we pass the query to the database      $result=mysql_query($query, $link) or die("MySQL query $query failed.  Error if any: ".mysql_error());     //get the first (and only) row from the result      $row = mysql_fetch_array($result, MYSQL_ASSOC);  if(empty($messages)) {     updateuser ($username=$row['username'],      $password=$row['password'],     $first_name=$row['first_name'],     $last_name=$row['last_name'],     $address_line1=$row['address_line1'],      $address_line2=$row['address_line2'],      $town=$row['town'],     $county=$row['county'],     $postcode=$row['postcode'],     $daytime_phone=$row['daytime_phone'],     $mobile_phone=$row['mobile_phone'],     $email_address=$row['email_address']); } ?>  [/code] I then have html below that: [code=php:0] <form name="form1" method="post" action="<?=$_SERVER["PHP_SELF"]?>" onSubmit="return check()">  <p>Username:      <?php echo $username; ?>    </p>    <p>First Name:      <input type="text" name="first_name" value="<?php echo $first_name; ?>">    </p>   <p>Last Name:      <input type="text" name="last_name" size="10" value="<?php echo $last_name; ?>">    </p>    <p>Address Line 1:      <input type="text" name="address_line1" size="10" value="<?php echo $address_line1; ?>">    </p>    <p>Address Line 2:      <input type="text" name="address_line2" size="10" value="<?php echo $address_line2; ?>">    </p>    <p>Town:      <input type="text" name="town" size="10" value="<?php echo $town; ?>">  etc, etc  [/code] The problem is that the html is not being populated with the data and is not posting either, I have simply copied the function from a newuser function when a user signs up, the function as it is in the functions file looks like so: [code=php:0] function updateuser ($password, $username, $first_name, $last_name, $address_line1, $address_line2, $town, $county, $postcode, $daytime_phone, $mobile_phone, $email_address) { global $link; $query="UPDATE suppliers SET password='$password', username='$username', first_name='$first_name', last_name='$last_name',  address_line1='$address_line1', address_line2='$address_line2', town='$town' , county='$county', postcode='$postcode', daytime_phone='$daytime_phone', mobile_phone='$mobile_phone', email_address='$email_address' where username= '$username'"; $result=mysql_query($query, $link) or die("Died inserting login info into db.  Error returned if any: ".mysql_error()); return true; } //  [/code] Any help would be much appreciated as I am really stuck. Thanks, G
  12. Thats exactly what I have done, problem solved!
  13. Thanks for the response but this is not working, I need the code in a page that displays the success or failure of the update after the page where you fill in the html code. So in the updateresults page I have taken the code like so, but it is not working: [code=php:0] <?php if (!isset($_POST['submit'])) {     if (isset($_POST['boxes']))     {         echo 'you checked ' . implode(',', $_POST['boxes']);     }     else     {         echo 'you did not check any boxes';     } }      ?> <?php     $query = "UPDATE suppliers SET first_name='$first_name', last_name='$last_name', password='$password', address_line1='$address_line1', address_line2='$address_line2', town='$town' , county='$county', postcode='$postcode', daytime_phone='$daytime_phone', mobile_phone='$mobile_phone', email_address='$email_address', checkbox1='$checkbox1', checkbox2='$checkbox2'";         //now we pass the query to the database                     $result=mysql_query($query) or die("Could not insert data.".mysql_error());     //$result represents the status of the operation true if it worked false if it failed     if($result){         print "Your details have been sucesfully updated. You can go back to the <a href=suppliers.php>index</a> page now.";     }else{         print "Could not update data.";     }     //finally close the connection     mysql_close(); ?> [/code]
  14. Hi all, I am trying to ensure that a user can update their details thoruhg a form. the problem is that when the checkboxes are not checked I get an undefined index error for them based of the update query as detailed below: [code=php:0] $strPassword = isset($_POST['password']) ? $_POST['password'] : ""; $strfirst_name = isset($_POST['first_name']) ? $_POST['first_name'] : ""; $strlast_name = isset($_POST['last_name']) ? $_POST['last_name'] : ""; $straddress_line1 = isset($_POST['address_line1']) ? $_POST['address_line1'] : ""; $straddress_line2 = isset($_POST['address_line2']) ? $_POST['address_line2'] : ""; $strtown = isset($_POST['town']) ? $_POST['town'] : "";  $strcounty = isset($_POST['county']) ? $_POST['county'] : ""; $strpostcode = isset($_POST['postcode']) ? $_POST['postcode'] : ""; $strdaytime_phone = isset($_POST['daytime_phone']) ? $_POST['daytime_phone'] : ""; $strmobile_phone = isset($_POST['mobile_phone']) ? $_POST['mobile_phone'] : ""; $stremail_address = isset($_POST['email_address']) ? $_POST['email_address'] : "";                           $strinsurance = isset($_POST['insurance']) ? $_POST['insurance'] : ""; $strterms = isset($_POST['terms']) ? $_POST['terms'] : ""; $query = "UPDATE suppliers SET first_name='$first_name', last_name='$last_name', password='$password', address_line1='$address_line1', address_line2='$address_line2', town='$town' , county='$county', postcode='$postcode', daytime_phone='$daytime_phone', mobile_phone='$mobile_phone', email_address='$email_address', insurance='$insurance', terms='$terms' WHERE username='$username'"; [/code] It is this query that is causing me issues, any ideas? Thanks, G
  15. Ok, I have solved the problem, it was a capital V in currentvalue that was causing the problem.
  16. Thanks AndyB But that line:[code=php:0]echo '<option value="'. $lz. '" selected=".$checkedStatus.'">'.$lz.'</option>';[/code] Gives me the following error: parse error, unexpected '\"', expecting ',' or ';' Taking ou some of the marks still leaves me with the list being populated with '12'.
  17. Ok, I have removed the first leading zero, as it wasn't necessary, the problem is it is still not displaying the date off this code: [code=php:0] $currentvalue3 = $row['dbyear']; echo '<select name="dbyear">'; for ($i=1900; $i < 2006; $i++) { //adds a leading zero if needed $lz = strlen($i) == 1 ? '0'.$i : $i; $checkedStatus = ''; if ($i == $currentValue3)     {         $checkedStatus = 'SELECTED';     }     echo '<option value='.$checkedStatus.'>'.$lz.'</option>';     //echo '<option value="'.$lz.'" '.$checkedStatus.'>'.$lz.'</option>'; } echo '</select>';  [/code] Thanks, G
  18. The html posts 1900, when I change it to say 1970 it defaulst back.
  19. Hi all, I have a script to allow a user to update their details and I am stuck with pulling back the year part of the date of birth method I am using. In order to retrieve the day I use: [code=php:0] $dbday=$row['dbday'];     $dbmonth=$row['dbmonth'];     $dbyear=$row['dbyear']; $currentValue = $row['dbday']; //generate drop down for day echo '<select name="dbday">'; for ($i=1; $i < 32; $i++) {     //adds a leading zero if needed     //$lz = strlen($i) == 1 ? '0'.$i : $i;     $lz = str_pad($i, 2, '0', STR_PAD_LEFT);     // check if the value displayed is the one currenlty selected     $checkedStatus = '';     if ($i == $currentValue)     {         $checkedStatus = 'SELECTED';     }     echo '<option value="'.$lz.'" '.$checkedStatus.'>'.$lz.'</option>'; } echo '</select>'; [/code] This works great. However trying to do something similar for the year doesnt work: [code=php:0] //year $currentvalue3 = $row['dbyear']; echo '<select name="dbyear">'; for ($i=1900; $i < 2006; $i++) { //adds a leading zero if needed $lz = strlen($i) == 1 ? '0'.$i : $i; $checkedStatus = ''; if ($i == $currentValue3)     {         $checkedStatus = 'SELECTED';     }     echo '<option value="'.$lz.'" '.$checkedStatus.'>'.$lz.'</option>'; [/code] Any ideas as I have been looking at this all morning... Thanks, G
  20. I think I have worked this out for myself now. Thanks again
  21. Ah yes, I just added that to see if it works, I had taken it off 5 mons ago. Can I make the function conditional, in other words only provide the userid in the session once a user is logged in?
  22. Ok here is it s off the join form: [code=php:0] cleanMemberSession($_POST["username"], $_POST["password"], $_POST["userid"]);         // and then redirect them to the members page:         header("Location: members.php?".session_name()."=".session_id());           } } [/code]
  23. Hi all (again) After adding the userid to the flushmember function I now have a new problem that is causing some heair pulling.. The function does not work when a user 'joins', by using a join form the user gets directed to the memebrs page which is what you have been helping on. However when I now try and register a user I get the following errors: Warning: Missing argument 3 for cleanmembersession() in site.co.uk/user/htdocs/functions.php on line 231 Notice: Undefined variable: userid in site.co.uk/user/htdocs/functions.php on line 245 This part of the code looks like so: [code=php:0] function cleanMemberSession($username, $password, $userid) {     /*     Member session initialization function:     This function initializes 3 session variables:   $login, $password and $loggedIn.     $login and $password are used on member pages (where you     could allow the user to change their password for example).     $loggedIn is a simple boolean variable which indicates     whether or not the user is currently logged in.     */     $_SESSION["username"]=$username;     $_SESSION["password"]=$password;     $_SESSION["userid"]=$userid; $_SESSION["loggedIn"]=true; [/code] If I take out the userid the members page stops displaying the userid, if I add it I get these errors. I have no idea on a workaround, unless I can create another function that pulls in the userid?
  24. Yee ha! Wildteen you are great! Thank you for your help, userid is now displayed (it was the cleanmembersession that was wrong...).
  25. Ok I have made those changes, but in my members page where I want to display the userid, nothing is coming up still.... [code=php:0] // Check user logged in already: checkLoggedIn("yes"); doCSS(); print("Welcome to the members page <b>".$_SESSION["username"]."</b><br>"); print("Your password is: <b>".$_SESSION["password"]."</b><br>"); print("Your User ID Number is: <b>".$_SESSION["userid"]."</b><br>"); print("<a href=\"logout.php?".session_name()."=".session_id()."\">Logout</a></b><br>"); print ("<a href=\"suppliersearch.php?".session_name()."=".session_id()."\">Search for suppliers</a></b></br>"); [/code] You will find below the two functions that needed to be updated: [code=php:0] function checkPass($username, $password) {     /*     Password checking function:     This is a simple function that takes the $username and     $password that a user submits in a form and checks that a     row exists in the database where:     the value of the 'login' column is the same as the value in $login     and     the value of the 'password' column is the same as the value in $password     If exactly one row is returned, then that row of data is returned.     If no row is found, the function returns 'false'.     */     global $link;         $query="SELECT userid, username, password FROM users WHERE username='$username' and password='$password'";     //$query="SELECT username, password FROM users WHERE username='$username' and password='$password'";     $result=mysql_query($query, $link)         or die("checkPass fatal error: ".mysql_error());         // Check exactly one row is found:     if(mysql_num_rows($result)==1) {         $row=mysql_fetch_array($result);         return $row;     }     //Bad Login:     return false; } // end func checkPass($username, $password) [/code] and: [code=php:0] function cleanMemberSession($username, $password, $userid) {     /*     Member session initialization function:     This function initializes 3 session variables:   $login, $password and $loggedIn.     $login and $password are used on member pages (where you     could allow the user to change their password for example).     $loggedIn is a simple boolean variable which indicates     whether or not the user is currently logged in.     */     $_SESSION["username"]=$username;     $_SESSION["password"]=$password;     $_SESSION["loggedIn"]=true; $_SESSION["userid"]=$userid; } // end func cleanMemberSession($username, $pass) [/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.