Jump to content

Kristoff1875

Members
  • Posts

    242
  • Joined

  • Last visited

Posts posted by Kristoff1875

  1. Thanks for the suggestion, I had considered a database... However i'd prefer not to use a database for 2 reasons. Firstly, it's a very small part of the site and secondly there could be potentially a fair few of these lists needed meaning having multiple databases could get confusing. Especially as there's only actually 3 data fields and it's not really gathering any information.

     

    As for which row gets changed. Here is the script that i'm modifying:

     

    http://coderoman.com/2011/01/php-wishlist-scriptapp/

     

    giftlist page:

    <form action="list/wishlist-form.php" method="post">    
    <?php
    
    $row = 1;
    if (($handle = fopen("list/wishlist.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    	$num = count($data);
    
    	switch ($num) {
    	case 0:
    		break;
    	case 2:
    		 echo "<input type=\"radio\" name=\"gift[]\" value=\"$row\" />
    			$data[0] - $data[2]<br />";
    		break;
    	case 3:
    		echo "<input type=\"radio\" name=\"gift[]\" value=\"$row\" />
    			$data[0] - $data[1] - $data[2]<br />";
    		break;
    	case 4:
    		echo "<input type=\"radio\" name=\"gift[]\" value=\"$row\" />
    			<a href=\"$data[3]\" target=\"_blank\">$data[0]</a> - $data[1] - $data[2]<br />";
    		break;
    }
    
            $row++;
        }
        fclose($handle);
    }
    ?>
    <br />
    <input type="submit" name="formSubmit" value="Click Here" />
    </form>

     

    CSV:

    "Morphy Richards Red Accents slow cooker","£34.99","Available"
    "Morphy Richards Red Accents slow cooker","£34.99","Available","http://www.houseoffraser.co.uk/Morphy+Richards+Red+Accents+slow+cooker+48728/146808112,default,pd.html"
    "Morphy Richards Red Accents slow cooker","£34.99","Available","http://www.houseoffraser.co.uk/Morphy+Richards+Red+Accents+slow+cooker+48728/146808112,default,pd.html"
    "Morphy Richards Red Accents slow cooker","£34.99","Available","http://www.houseoffraser.co.uk/Morphy+Richards+Red+Accents+slow+cooker+48728/146808112,default,pd.html"
    "Morphy Richards Red Accents slow cooker","£34.99","Available","http://www.houseoffraser.co.uk/Morphy+Richards+Red+Accents+slow+cooker+48728/146808112,default,pd.html"

     

     

    wishlist-form.php:

    <?php
    $aGift = $_POST['gift'];
    if(empty($aGift)) 
    echo "<h1>You didn't select any presents =(.</h1>";
    
    else {
    
    $fp = fopen('wishlist2.csv', 'w');
      	if (($handle = fopen("wishlist.csv", "r")) !== FALSE) {
      		$row = 1;
      	    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      	    	if ($row!=$aGift[0]) {
    				fputcsv($fp,$data);
      	    	$row++;
    		}
      	    	else {
      	    		$present = $data[0];
      	    		$row++;
      	    	}
            }
        fclose($handle);
        fclose($fp);
        unlink('wishlist.csv');
        rename('wishlist2.csv','wishlist.csv');
    }
    echo "<h1>Thanks for getting $present for me!</h1>";
    }
    ?>
    
    <p>You are the pride of [subject town].</p>

  2. Hi, I need to make a gift list, and found one online that uses a CSV file to display the gifts, then when people choose a gift, it deletes the chosen one from the CSV. This is the code:

     

    $fp = fopen('wishlist2.csv', 'w');
    
      	if (($handle = fopen("wishlist.csv", "r")) !== FALSE) {
      		$row = 1;
      	    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      	    	if ($row!=$aGift[0]) {
    				fputcsv($fp,$data);
      	    	$row++;
    		}
      	    	else {
      	    		$present = $data[0];
      	    		$row++;
      	    	}
            }
        fclose($handle);
        fclose($fp);
        unlink('wishlist.csv');
        rename('wishlist2.csv','wishlist.csv');
    }
    echo "<h1>Thanks for getting $present for me!</h1>";
    }

     

    I have added a data field which says "Available" And what I actually want is for this text to change to "Reserved" rather than the row to be deleted.

     

    I changed it to this after some research:

     

    $fname = "wishlist.csv";
    
    $row = 1;
    $fhandle = fopen($fname,"r");
    $content = fread($fhandle,filesize($fname));
    
    $content = str_replace("Available", "Reserved", $content);
    
    $fhandle = fopen($fname,"w");
    fwrite($fhandle,$content);
    fclose($fhandle);

     

    Which does what I want, only it changes every "Available" in to "Reserved"

     

    How do I change it only on the selected line?

     

    There will no doubt be more questions after this one, but thanks in advanced for this! Total newbie to CSV having not used them before.

  3. I think I see that because even if it's false, it's still submitting the form as long as the others are all filled in, however, I did try making the false part go to the error page, which still didnt work.

     

    The only thing I can think is that there should be a check as well as the checks to make sure the fields are filled in, that checks whether preg_match is true or false?

     

    No idea how I should do that so any advice is greatly appreciated!

     

    Thanks for the help!!

  4. Hi, thanks for the assistance!

     

    This is my full code from the php sender:

     

    <?php
    $myemail = "info@******.com";
    $name = $_POST['name'] ;
    $email = $_POST['email'] ;
    $phone = $_POST['phone'] ;
    $dobday = $_POST['dobday'] ;
    $dobmonth = $_POST['dobmonth'] ;
    $dobyear = $_POST['dobyear'] ;
    $town = $_POST['town'] ;
    
    if(preg_match("~[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}~i", $email))
    {
      return TRUE;
    }
    else
    {
      echo FALSE;
    }
    
    if (empty($name) || empty($email) || empty($phone) || empty($dobday) || empty($dobmonth) || empty($dobyear) || empty($town)){
    header("Location: error.php");
    }
    else
    {
    $message = "Someone has filled out The Honey Club Mailing List Form:\n
    \n
    Name: $name\n
    Email: $email\n
    Phone: $phone\n
    D.O.B: $dob\n
    Town: $town\n";
    
    mail ($myemail, "Mailing List Form", $message, "From: $email");
    
    header("Location: formsubmitted.php");
    }
    ?> 

     

    It goes to formsubmitted.php and the email is sent, but even if the email is just "test" it still sends fine  :shrug:

     

    Thanks again!

  5. I know, that is the only attempt on there at the moment as everything else i've tried just brings up an error?

     

    EDIT:

     

    Just tried this again:

     

    <?php
    $myemail = "";
    $name = $_POST['name'] ;
    $email = $_POST['email'] ;
    $phone = $_POST['phone'] ;
    $dobday = $_POST['dobday'] ;
    $dobmonth = $_POST['dobmonth'] ;
    $dobyear = $_POST['dobyear'] ;
    $town = $_POST['town'] ;
    
    function valid_email($email) {
      // check an email address is possibly valid
      if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) {
        return true;
      } else {
        return false;
      }
    }
    
    if (empty($name) || empty($email) || empty($phone) || empty($dobday) || empty($dobmonth) || empty($dobyear) || empty($town)){
    header("Location: error.php");
    }
    else
    {
    $message = "Someone has filled out Mailing List Form:\n
    \n
    Name: $name\n
    Email: $email\n
    Phone: $phone\n
    D.O.B: $dob\n
    Town: $town\n";
    
    mail ($myemail, "Mailing List Form", $message, "From: $email");
    
    header("Location: formsubmitted.php");
    }
    ?> 

     

    And it works, but it allowed "test" as the email  :confused:

  6. Cheers for the help again. I have added the following with a form field (just to get the change password field working so far:

     

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // Get values from form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];
    
    // Insert data into mysql
    $sql="UPDATE $tbl_name SET password='$mypassword' WHERE username='".$_SESSION['myusername']."'";
    $result=mysql_query($sql);
    
    // if successfully insert data into database, displays message "Successful".
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='insert.php'>Back to main page</a>";
    }
    
    else {
    echo "ERROR";
    }
    
    // close connection
    mysql_close();
    ?>

     

    Everything goes through fine on the website, but when I try the login again, the new password doesn't work, and the old one still does?  :confused:

  7. Don't shoot me please!!!

     

    I've tried about 50 different ways of doing this but still can't get the sender to check whether the email is of the right format ie (name@email.com), I don't even care if the email is real as long as it's in email format.

     

    Here is my code:

     

    <?php
    $myemail = "****";
    $name = $_POST['name'] ;
    $email = $_POST['email'] ;
    $phone = $_POST['phone'] ;
    $dobday = $_POST['dobday'] ;
    $dobmonth = $_POST['dobmonth'] ;
    $dobyear = $_POST['dobyear'] ;
    $town = $_POST['town'] ;
    
    if (empty($name) || empty($email) || empty($phone) || empty($dobday) || empty($dobmonth) || empty($dobyear) || empty($town)){
    header("Location: error.php");
    }
    else
    {
    $message = "Someone has filled out Mailing List Form:\n
    \n
    Name: $name\n
    Email: $email\n
    Phone: $phone\n
    D.O.B: $dobday $dobmonth $dobyear\n
    Town: $town\n";
    
    mail ($myemail, "Mailing List Form", $message, "From: $email");
    
    header("Location: formsubmitted.php");
    }
    ?> 

     

    Any help appreciated!

  8. Thanks for the reply Lemmin, however I still don't fully grasp it. On the login success page it starts off as follows:

     

    <?
    session_start();
    if(!session_is_registered(myusername)){
    header("location:main_login.php");
    }
    ?>

     

    Is that where it grasps which member is logged in and who's password it will be changing?

     

    Cheers

  9. Hi, first time poster, have developed a little members system and now need some help to finish it off.

     

    Basically, the site admin has a form he can fill in to add a new username and password to a MySQL database. This works great.

     

    The username and password can then be used to login to the members only page of the website which will have offers etc for the Club (the website is for a Club) VIP members.

     

    Everything works great, except for I can't seem to figure out how the members can change their password. Ideally this would be a link that pops up a window with fields saying: Old Password, New Password, Confirm New Password.

     

    Not entirely sure how this should work, any advice is great.

     

    Here is the code currently used:

     

    <?php
    $host="localhost"; // Host name
    $username="******"; // Mysql username
    $password="******"; // Mysql password
    $db_name="******"; // Database name
    $tbl_name="******"; // Table name
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // username and password sent from form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];
    
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:login_success.php?=$myusername");
    }
    else {
    header("location:error.php");
    }
    ?>

     

    Any help appreciated.

     

    Cheers

×
×
  • 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.