Jump to content

c_pattle

Members
  • Posts

    295
  • Joined

  • Last visited

Posts posted by c_pattle

  1. I have a table called "users_cart" where it products in a users cart are stored.  They are stored in the columns "product1", "product1_price", "product2", "product2_price" etc. 

     

    I am trying to use the following loop to print them out onto the screen but can't seem to get it to work.  $count always seems to be stuck at 2. 

     

    
    $cart_qry = 'select * from users_cart where username="' . $_SESSION['username'] . '"';
    $cart_rs = mysql_query ( $cart_qry, $conn ) or die ('error query1' . mysql_error());
    
    $count = 1;
    	while ( $row = mysql_fetch_array ( $cart_rs ) ) {
    		$_SESSION['display_cart'] = "<tr><td>" . $row['product' . $count . ''] . "</td><td>" . $row['product' . $count . '_price'] . "</td></tr>";
    		$_SESSION['cart_total'] += $row['product' . $count. '_price'];
    		$_SESSION['cart_item_total'] + 1;
    		$count = $count + 1;
    		echo ( $count );
    		echo ( $_SESSION['display_cart'] );
    	}
    

  2. I have the following code which sends an attachment to my inbox.  However I want to be able to send two attachments.  Does anyone know how this is done?  I tried to just repeat all the code changing "att" (name of input) to "att2" but it still only sent the first one.  Thanks for any help. 

     

    <?php 
    
    $to = "chris.pattle@gmail.com"; 
    
    $att = $_FILES['att'];
    $att_path = $_FILES['att']['tmp_name'];
    $att_name = $_FILES['att']['name'];
    $att_size = $_FILES['att']['size'];
    $att_type = $_FILES['att']['type'];
    
    $att2 = $_FILES['att2'];
    $att2_path = $_FILES['att2']['tmp_name'];
    $att2_name = $_FILES['att2']['name'];
    $att2_size = $_FILES['att2']['size'];
    $att2_type = $_FILES['att2']['type'];
    
    $fp = fopen( $att_path, "rb");
    $file = fread( $fp, $att_size );
    fclose ($fp);
    
    $fp2 = fopen( $att2_path, "rb");
    $file2 = fread( $fp2, $att2_size );
    fclose ($fp2);
    
    $num = md5(time());
    $str = "==multipart_Boundary_x{$num}x";
    
    $file = chunk_split(base64_encode($file));
    
    $subject = "You have a new order from " . $_REQUEST['order_company_name']; 
    
    $email = $_REQUEST['order_email'] ; 
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: multipart/mixed;";
    $headers .= "boundary=\"{$str}\"\r\n";
    $headers .= "From: $email"; 
    
    $msg .= "This is a multi-part message in MIME format\r\n\n";
    $msg .= "--{$str}\r\n";
    $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
    $msg .= "Content-Transfer-Encoding: 8bit\r\n";
    $msg .= "--{$str}\r\n";
    
    $msg .= "Content-Type: {$att_type}; ";
    $msg .= "name=\"{$att_name}\"\r\n";
    $msg .= "Content-Disposition: attachment; ";
    $msg .= "filename =\"{$att_name}\"\r\n";
    $msg .= "Content-Transfer-Encoding: base64\r\n";
    $msg .= "$file\r\n\n";
    $msg .= "--{$str}";
    
    $msg .= "Content-Type: {$att2_type}; ";
    $msg .= "name=\"{$att2_name}\"\r\n";
    $msg .= "Content-Disposition: attachment; ";
    $msg .= "filename =\"{$att2_name}\"\r\n";
    $msg .= "Content-Transfer-Encoding: base64\r\n";
    $msg .= "$file2\r\n\n";
    $msg .= "--{$str}";
    
    $sent = mail($to, $subject, $msg, $headers) ; 
    if($sent) 
    {print "Thank you.  Your order was sent successfully"; }
    else 
    {print "Sorry.  We encountered an error sending your mail"; }
    ?>
    

  3. Hey

     

    I have an form with the option of adding an attachment.  However I'm having some trouble when trying to send it.  I am getting the following error. 

     

    Warning: fread(): supplied argument is not a valid stream resource in /websites/123reg/LinuxPackage21/co/lo/ur/colourbrush.co.uk/public_html/order_success2.php on line 39

     

    I have copied my code below

     

    <?php
    $to = "someone@gmail.com"; 
    
    $att = $_FILES['att'];
    $att_path = $_FILES['att']['tmp_name'];
    $att_name = $_FILES['att']['name'];
    $att_size = $_FILES['att']['size'];
    $att_type = $_FILES['att']['type'];
    
    $fp = fopen( $att_path, "rb");
    $file = fread( $fp, $att_size );
    $fclose ($fp);
    
    $num = md5(time());
    $str = "==multipart_Boundary_x{$num}x";
    
    $file = chunk_split(base64_encode($file));
    
    $subject = "You have a new order from " . $_REQUEST['order_company_name']; 
    
    $message = "Company Name:  " . $_REQUEST['order_company_name'] ;
    
    $email = $_REQUEST['order_email'] ; 
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: multipart/mixed;";
    $headers .= "boundary=\"{$str}\"\r\n";
    //$headers .= " charset=iso-8859-1\r\n";
    $headers .= "From: $email"; 
    $sent = mail($to, $subject, $message, $headers) ; 
    if($sent) 
    {print "Thank you.  Your order was sent successfully"; }
    else 
    {print "Sorry.  We encountered an error sending your mail"; }
    ?>
    

  4. Thanks for your help.  I tried to adapt your script to include three divs for three different options but can't seem to get it to work. 

     

       function list1change()
       {
          div1 = document.getElementById('div1');
          order_property_details = document.getElementById('order_property_details');
          if (order_property_details.selectedIndex==0)
             div1.style.display = 'block';
          else if (order_property_details.selectedIndex==1)
             div2.style.display = 'block';
          else if (order_property_details.selectedIndex==2)
             div3.style.display = 'block';
          else
             div1.style.display = 'none';
             div2.style.display = 'none';
             div3.style.display = 'none';
    
       }

  5. Hey

     

    I have a form on my website with a select box.  What I want to achieve is depending on what the user selects from this select box another select box will appear.  For example if the users selects either option 1, 3, or 6 from the first select menu a second one will appear.  Is this possible to do using PHP as I'm not sure how to do it. 

     

    Thanks

  6. I've just made a search form on my website where the user can search for a product and I have used the following code

     

    $search_query = 'select * from product_list where product_name="' . $search_word . '"';

     

    however this only works if the user types the exact name of the product.  Is there a mysql select I can do where it will find all product name which feature part of the search word.  For example if the users searches for "frying pan" it will find all products with the word "frying" somewhere in their name and not just the product with the exact name "frying pan"

  7. Hey

     

    I have two tables called product_list and users_cart.  I am trying to use a select function to retrieve data from both table and then display it as the users shopping cart.  I have used the following sql. 

     

    select product_list.product_name, product_list.image, users_cart.* from product_list, users_cart where users_cart.product1 = product_list.product_name and username="chris";

     

    However the problem with this is that it only returns the value in product_list.image for the first item in the users shopping cart (users_cart.product1).  Does anyone know how I am get it to return the image for each of the items in the shopping cart (product1, product2 and product3)? 

     

    Feel free to ask more question if I haven't explained it well enough. 

     

    Thanks for any help

  8. also I've updated the code to try to send an email to the user once they register but that doesn't seem to be working. 

     

    <?php
    //Adding a new user into the database
    
    //trying to clear variables
    header('Location: register.php'); 
    
    $register_firstname = $_POST['register_firstname'];
    $register_lastname = $_POST['register_lastname'];
    $register_username = $_POST['register_username'];
    $register_email = $_POST['register_email'];
    $register_password_1 = $_POST['register_password_1'];
    $register_password_2 = $_POST['register_password_2'];
    
    if( $register_firstname and $register_lastname and $register_username and $register_email and $register_password_1 and $register_password_2) { 
    if( $register_password_1 == $register_password_2) {
    $sql="insert into users (first_name, last_name, username, email, password) values (\"$register_firstname\", \"$register_lastname\", \"$register_username\", \"$register_email\", \"$register_password_1\")";
    
    $rs = mysql_query( $sql, $link );
    if($rs) {
    echo("congratulations you have successfully registered");
    $to = $register_email;
    $re = "registration to Ribbons2Roses";
    $msg = "Congratulations". $register_firstname . "you have successfully register to Ribbons2Roses.  Your username is" . $register_username . "We hope you enjoy shopping for that perfect gift on our website and if you have any questions please don't hestitate to contact one of the team";
    mail( $to, $re, $msg );
    } else {
    echo ('error' . mysql_error());
    }
    
    }
    
    else {
    	echo ("The two passwords do not match.  Please retype them");
    }
    }
    
    else {
    echo ("You have not completed all the fields.  Please fill in the blank fields");
    }
    ?>

     

    Here is the related text in the php.ini file

     

    [mail function]

    ; For Win32 only.

    SMTP = localhost

    smtp_port = 25

     

    ; For Win32 only.

    ;sendmail_from = me@example.com

     

    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").

    sendmail_path = sendmail -t -i

     

    ; Force the addition of the specified parameters to be passed as extra parameters

    ; to the sendmail binary. These parameters will always replace the value of

    ; the 5th parameter to mail(), even in safe mode.

    ;mail.force_extra_parameters =

  9. I have a page that registers a new user to a database.  However when you refresh the page the variables that are used to add information to the database still contain information so it keeps trying to add the user to the database.  How can I clear the variables after the user clicks the submit button?

     

    <?php
    //Adding a new user into the database
    
    //trying to clear variables
    header('Location: register.php'); 
    
    $register_firstname = $_POST['register_firstname'];
    $register_lastname = $_POST['register_lastname'];
    $register_username = $_POST['register_username'];
    $register_email = $_POST['register_email'];
    $register_password_1 = $_POST['register_password_1'];
    $register_password_2 = $_POST['register_password_2'];
    
    if( $register_firstname and $register_lastname and $register_username and $register_email and $register_password_1 and $register_password_2) { 
    if( $register_password_1 == $register_password_2) {
    $sql="insert into users (first_name, last_name, username, email, password) values (\"$register_firstname\", \"$register_lastname\", \"$register_username\", \"$register_email\", \"$register_password_1\")";
    
    $rs = mysql_query( $sql, $link );
    if($rs) {
    echo("congratulations you have successfully registered");
    } else {
    echo ('error' . mysql_error());
    }
    
    }
    
    else {
    	echo ("The two passwords do not match.  Please retype them");
    }
    }
    
    else {
    echo ("You have not completed all the fields.  Please fill in the blank fields");
    }
    ?>

  10. Thanks

     

    When I tried to use the header function shown the in script above I got this warning message. 

     

    Warning: Cannot modify header information - headers already sent by (output started at /var/www/ribbons/register.php:24) in /var/www/ribbons/register.php on line 135

  11. I still can't seem to use clear the variable in this script.  Have I gone wrong anywhere or does anyone else know what I can do to try to clear them?

     

    <?php
    
    //Adding a new user into the database
    //Clearing variables
    $register_firstname = $register_lastname = $register_username = $register_email = $register_password_1 = $register_password_2 = '';
    
    $register_firstname = $_POST['register_firstname'];
    $register_lastname = $_POST['register_lastname'];
    $register_username = $_POST['register_username'];
    $register_email = $_POST['register_email'];
    $register_password_1 = $_POST['register_password_1'];
    $register_password_2 = $_POST['register_password_2'];
    
    if( $register_firstname and $register_lastname and $register_username and $register_email and $register_password_1 and $register_password_2) {
    
       
    
    if( $register_password_1 == $register_password_2) {
    
       
    
    $sql="insert into users (first_name, last_name, username, email, password) values (\"$register_firstname\", \"$register_lastname\", \"$register_username\", \"$register_email\", \"$register_password_1\")";
    
       
    
    $rs = mysql_query( $sql, $link );
    
       
    
    if($rs) {
    
       
    
    echo("congratulations you have successfully registered");
    
       
    
    } else {
    
       
    
    echo ('error' . mysql_error());
    
       
    
    }
    
    header('Location: page_script_is_on.php');   
    
    }
    
    else {
    
    echo ("The two passwords do not match.  Please retype them");
    
    }
    }
    
    else {
    
    echo ("You have not completed all the fields.  Please fill in the blank fields");
    }
    ?> 

  12. I'm trying to use the array method but having some problems.  Below is where I have set the keys. 

     

    	<li><a href="childrens_products.php?key[1]=cooking">Cooking gift sets</a></li>
    
    <li><a href="childrens_products.php?key[2]=garden">Garden gift sets</a></li>

     

    And this is where I am trying to use those keys

     

    if(isset($_GET['key'])){
       $keyword = mysql_real_escape_string($_GET['key']);
    $cat_query = "select * from product_list where category='" . $keyword . "' and department='children'";
    $rs = mysql_query ( $cat_query, $conn ) or die ('error query1' . mysql_error());

     

    However when I try to run the code I get this error "Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /var/www/ribbons/childrens_products.php on line 91"

  13. Thanks Ken.  So all I'd need to do is just add in "header('Location: page_script_is_on.php');" after all of the processing has been done like I have below?

     

    <?php
    
    //Adding a new user into the database
    //Clearing variables
    $register_firstname = $register_lastname = $register_username = $register_email = $register_password_1 = $register_password_2 = '';
    
    $register_firstname = $_POST['register_firstname'];
    $register_lastname = $_POST['register_lastname'];
    $register_username = $_POST['register_username'];
    $register_email = $_POST['register_email'];
    $register_password_1 = $_POST['register_password_1'];
    $register_password_2 = $_POST['register_password_2'];
    
    if( $register_firstname and $register_lastname and $register_username and $register_email and $register_password_1 and $register_password_2) {
    
    
    
    if( $register_password_1 == $register_password_2) {
    
    
    
    $sql="insert into users (first_name, last_name, username, email, password) values (\"$register_firstname\", \"$register_lastname\", \"$register_username\", \"$register_email\", \"$register_password_1\")";
    
    
    
    $rs = mysql_query( $sql, $link );
    
    
    
    if($rs) {
    
    
    
    echo("congratulations you have successfully registered");
    
    
    
    } else {
    
    
    
    echo ('error' . mysql_error());
    
    
    
    }
    
    header('Location: page_script_is_on.php');	
    
    }
    
    else {
    
    echo ("The two passwords do not match.  Please retype them");
    
    }
    }
    
    else {
    
    echo ("You have not completed all the fields.  Please fill in the blank fields");
    }
    ?> 

  14. Hey

     

    I am writing a page that adds a new user into a mysql database.  The code all works fine except after the new user has been added if you refresh to page the variables still store the information it attempts to add the user again.  I have attempted to clear the variable but it doesn't seem to work.  Does anyone know where I am going wrong?

     

    <?php
    //Adding a new user into the database
    
    $register_firstname = $_POST['register_firstname'];
    $register_lastname = $_POST['register_lastname'];
    $register_username = $_POST['register_username'];
    $register_email = $_POST['register_email'];
    $register_password_1 = $_POST['register_password_1'];
    $register_password_2 = $_POST['register_password_2'];
    
    if( $register_firstname and $register_lastname and $register_username and $register_email and $register_password_1 and $register_password_2) {
    
    if( $register_password_1 == $register_password_2) {
    $sql="insert into users (first_name, last_name, username, email, password) values (\"$register_firstname\", \"$register_lastname\", \"$register_username\", \"$register_email\", \"$register_password_1\")";
    
    $rs = mysql_query( $sql, $link );
    if($rs) {
    echo("congratulations you have successfully registered");
    } else {
    echo ('error' . mysql_error());
    }
    
    //Clearing variables
    $register_firstname = '';
    $register_lastname = '';
    $register_username = '';
    $register_email = '';
    $register_password_1 = '';
    $register_password_2 = '';
    $_POST['register_firstname'] = '';
    $_POST['register_lastname'] = '';
    $_POST['register_username'] = '';
    $_POST['register_email'] = '';
    $_POST['register_password_1'] = '';
    $_POST['register_password_2'] = '';
    
    }
    
    else {
    	echo ("The two passwords do not match.  Please retype them");
    }
    }
    
    else {
    echo ("You have not completed all the fields.  Please fill in the blank fields");
    }
    ?>

     

    Thanks for any help

  15. Hey everyone

     

    I am using this code "childrens_products.php?key=cooking" and then depending on the key I am then querying from a mysql database.  For example.

     

    if(isset($_GET['key'])){

      $keyword = mysql_real_escape_string($_GET['key']);

    $cat_query = "select * from product_list where category='" . $keyword . "' and department='home'";

     

    However does it have to read "key=cooking" or can it read "key2=garden" or "key3="bathroom" etc?

     

    Also you set more than one key such as "childrens_products.php?key=cooking, key2=garden"?

     

    Thanks for any help

     

    Chris

  16. Hey

     

    I'm not sure if this it the correct place to post this but if not then feel free to move it. 

     

    I've created a mysql table to store user names and password and am trying to create a log in page which checks the username and passwords are valid. 

     

    I used this sql to create the table "create table users (first_name varchar(25) not null, last_name varchar(25) not null, username varchar(20) unique, password varchar(16);"

     

    However when I try to insert data into the table using "insert into users (first_name, last_name, username, password) values ("jack", "jones", "jack", password("jack"));" it says there is a warning.  It's something to do with the password because when you view the table the password is stored as a 15 character string with a "*" at the start. 

     

    Does anyone know what I'm doing wrong?

  17. Hey everyone. I'm trying to simply just create a php document that allows me to create a database using MySQL. I've copied my code below (password for mysql is correct but I wanted to hide it).

     

    <?php

     

    $conn = mysql_connect("localhost","root","******") or die ("Sorry");

     

    $rs1 = mysql_create_db ( $_REQEUST['db'] );

     

    $rs2 = mysql_list_db ($conn );

    for( $row = 0; $row < mysql_num_rows ($rs2); $row++) {

    $list.= mysql_tablename( $rs2, $row) . " - ";

    }

    ?>

     

    <html>

    <head>

    <title>Title</title>

    </head>

     

    <body>

    <form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="post">Current Databases: <?php echo ( $list); ?>

    <hr>Name:<input type="text" name"db">

    <input type="submit" value"Create Database">

    </form>

    </body>

    </html>

     

    When I try to run the page I get this error "Fatal error: Call to undefined function mysql_create_db() in /var/www/test2.php on line 5"

     

    Does anyone know why this is happening?

     

    Thanks for any help

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