Jump to content

dannyd

Members
  • Posts

    52
  • Joined

  • Last visited

    Never

Posts posted by dannyd

  1. I'm trying to configure the .htaccess file to include:

     

    ErrorDocument 404 /404page.html

     

    But if I add anything in my .htaccess my site goes down with a misconfiguration error.

     

    My httpd.conf file has this:

     

      <Directory "/usr/local/apache/htdocs">

        AllowOverride AuthConfig                  //should this be set to ALL ?

      </Directory>

     

    What could I be missing ?

     

  2. If I was to use the code below how would I allow the email output to allow HTML and the attach file ? What header do I add ?

     

    <html>

    <head>

    <title> Sending Email </title>

    </head>

    <body>

    <?php

    // Read POST request params into global vars

    $to      = $_POST['to'];

    $from    = $_POST['from'];

    $subject = $_POST['subject'];

    $message = $_POST['message'];

     

    // Obtain file upload vars

    $fileatt      = $_FILES['fileatt']['tmp_name'];

    $fileatt_type = $_FILES['fileatt']['type'];

    $fileatt_name = $_FILES['fileatt']['name'];

     

    $headers = "From: $from";

     

    if (is_uploaded_file($fileatt)) {

      // Read the file to be attached ('rb' = read binary)

      $file = fopen($fileatt,'rb');

      $data = fread($file,filesize($fileatt));

      fclose($file);

     

      // Generate a boundary string

      $semi_rand = md5(time());

      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

     

      $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

     

      // Add the headers for a file attachment

      $headers .= "\nMIME-Version: 1.0\n" .

                  "Content-Type: multipart/mixed;\n" .

                  " boundary=\"{$mime_boundary}\"";

     

     

      // Add a multipart boundary above the plain message

      $message = "This is a multi-part message in MIME format.\n\n" .

                "--{$mime_boundary}\n" .

                "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .

                "Content-Transfer-Encoding: 7bit\n\n" .

                $message . "\n\n";

     

      // Base64 encode the file data

      $data = chunk_split(base64_encode($data));

     

      // Add file attachment to the message

      $message .= "--{$mime_boundary}\n" .

                  "Content-Type: {$fileatt_type};\n" .

                  " name=\"{$fileatt_name}\"\n" .

                  //"Content-Disposition: attachment;\n" .

                  //" filename=\"{$fileatt_name}\"\n" .

                  "Content-Transfer-Encoding: base64\n\n" .

                  $data . "\n\n" .

                  "--{$mime_boundary}--\n";

    }

     

    // Send the message

    $ok = @mail($to, $subject, $message, $headers);

    if ($ok) {

      echo "<p>Mail sent! Yay PHP!</p>";

    } else {

      echo "<p>Mail could not be sent. Sorry!</p>";

    }

    ?>

    </body>

    </html>

  3. Can you give me an example of how I would rearrange the code or where I am outputting text before I call a redirect. So for instance when I delete I want it automatically redirected to the default form instead of displaying the message that somethings been deleted and the user having to use the back button.

  4. I pasted my code below which has my whole attributes script which thanks to this site works. Not the pretties piece of code but works. How can I redirect after the delete so it goes to to the page /attributes.php?cadid=cadid page. I always get a headers error if i use a php redirect. Not sure how to work around that. Any ideas ?

     

    <?php
    
    
    //table for product attributes
    $tbl_name = "product_attributes";
    
    // get the required action
    if(isset($_GET['action']) && !empty($_GET['action']))
    {
        // call code based on action
        switch(strtolower($_GET['action']))
        {
    
    
    //************************** BEGIN ADD ATTRIBUTES TO PRODUCT *******************************************
    case 'add':
    
        $clid = $_REQUEST['clid'];
    $clientname = $_REQUEST['clientname'];
    
     echo '<b>Add attributes to: ' . $clientname . '<b><BR>';
    
    
        // start displaying data
        $sql    = 'SELECT * FROM ' . $tbl_name . ' WHERE clid="' . $clid . '" ORDER BY sort ASC';
        $result = mysql_query($sql);
    
    
        // get the number of field from the table
        $num_fields = mysql_num_fields($result);
    
        // display results with table fieldnames and "add" link
        echo '<table border="1" cellspacing="2" cellpadding="5"><tr>';
       
    
        
    $field_array=array('Attribute ID','Client ID','Attribute Name','Price', 'URL', 'Sort');
    
    
    // first the field names from table
        for($i = 0; $i < $num_fields; $i++)
        {
           // echo '    <th>' . ucwords(mysql_field_name($result, $i)) . "</th>\n";
       
       echo '<th bgcolor="#ddf4fd">' . $field_array[$i] . '</th>';
       
    }
        // append the Action column
        echo '<th bgcolor="#ddf4fd">Action</th>';
        
        
    
        echo "  </tr>\n";
    
        // now display all content to screen
        while($row = mysql_fetch_assoc($result))
        {
            // use implode to create new cell for each item in the row
            echo "  <tr>\n    <td>" , implode("</td>\n    <td>", $row) . "</td>\n    ";
    
            // display our action links (edit and delete)
            	
    	echo '<td><a href="?action=edit&attribute_id='.$row['attribute_id'].'&clid=' . $row['clid'] . '&clientname=' . $clientname.'">EDIT</a> | <a href="?action=delete&attribute_id='.$row['attribute_id'].'&clid=' . $row['$clid'] . '&clientname=' . $clientname .'">DELETE</a></td>'."\n  </tr>\n";
        }
        // close table
        echo "</table>\n";
       //end displaying data
    
       
      if(isset($_POST['submit']) && $_POST['submit'] == 'Add')
                {
                    
    
    		foreach($_POST as $field => $value)
                    {
                       
    				 if ($value == '' && $field != 'clid' && $field != 'attribute_id'){
    
    						echo '<font color="red">ERROR: Please Make sure fields are not empty</font>';
    				        exit;
       			          }	
    
    				if($field != 'submit' && $field != 'attribute_id' && $field != 'clid')
                        {
                            $fields_list[] = "`$field`='" . mysql_real_escape_string($value) . "'";
                        }
                   
    			}
                   
                  
                    echo 'record added!';
    
    			$sql = "INSERT INTO product_attributes (clid,attribute_name,price,url,sort) VALUES('$clid', '$attribute_name', '$price', '$url','$sort')";
                    $result = mysql_query($sql);
                    //ob_flush();
    			//header('Location: attributes.php?action=add&clid=$cadid');
                    //ob_flush();
    			  
    			  
    	}
    
    
    
    //       echo '<table width="400"><tr><td><form method="post" action="?action=add&clid=' . $clid . '"><input type="hidden" name="clid" value="' .  $clid . '"><br>Attribute:<input type="Text" name="attribute_name"><br>Price:<input type="Text" name="price"><br>URL:<input type="Text" name="url"><br>Order:<input type="Text" name="sort"><br><input type="submit" name="submit" value="Add" /></form></td></tr></table>';
    
    
            echo '<table width="450"><tr><td><form method="post" action="?action=add&clid=' . $clid . '"><input type="hidden" name="clid" value="' .  $clid . '"></td><td><input type="hidden" name="clid" value="' .  $clid . '"></td></tr><tr>    <td width="75">Attribute Name:</td><td><input type="Text" name="attribute_name"></td></tr><tr><td>Price:</td><td><input type="Text" name="price"></td></tr><tr><td>URL (Link to attribute page):</td><td><input type="Text" name="url"></td></tr><tr>  <td>Order:</td>   <td><input type="Text" name="sort"></td> </tr> <tr><td width="170"> </td>  <td width="218"><form method="post" action="?action=add&clid=' . $clid . '"> <input type="submit" name="submit" value="Add" /></form></td></tr></table>';
    
    	break;
    //************************** END ADD ATTRIBUTES TO PRODUCT *******************************************
    
    
    //************************** BEGIN EDIT ATTRIBUTES TO PRODUCT *******************************************
    
        case 'edit':
    
    $clid = $_REQUEST['clid'];
    $clientname = $_REQUEST['clientname'];
    
       echo '<b>Edit Attributes for: ' . $clientname . '</b><BR>';
    
    // get all data from the table
        $sql    = 'SELECT * FROM product_attributes WHERE clid="' . $clid . '" ORDER BY sort ASC';
        $result = mysql_query($sql);
        // get the number of field from the table
        $num_fields = mysql_num_fields($result);
        
          // display results with table fieldnames and "add" link
          echo '<a href="?action=add&clid=' . $clid . '&clientname=' . $clientname . '">Add a Record</a>';
          echo '<table border="1" cellspacing="2" cellpadding="5"><tr>'."\n";
    
    
        $field_array=array('Attribute ID','Client ID','Attribute Name','Price', 'URL', 'Sort');
    
           // first the field names from table
           for($i = 0; $i < $num_fields; $i++)
           {
          
       //echo '    <th>' . ucwords(mysql_field_name($result, $i)) . "</th>\n";
       echo '<th bgcolor="#ddf4fd">' . $field_array[$i] . '</th>';
           }
           // append the Action column
           echo '<th bgcolor="#ddf4fd">Action</th>';
           echo '</tr>';
           
              
       // now display all content to screen
           while($row = mysql_fetch_assoc($result))
           {
            // use implode to create new cell for each item in the row
            echo "  <tr>\n    <td>" , implode("</td>\n    <td>", $row) . "</td>\n    ";
    
            // display our action links (edit and delete)
            	
    	echo '<td><a href="?action=edit&attribute_id='.$row['attribute_id'].'&clid='.$row['clid'].'&clientname=' . $clientname . '">EDIT</a> | <a href="?action=delete&attribute_id='.$row['attribute_id'].'&clid='.$row['clid'].'&attribute_name=' . $row['attribute_name'] . '&clientname=' . $clientname . '">DELETE</a></td>'."\n  </tr>\n";
           }
           // close table
           echo "</table>\n";
      //end displaying data;	
    
    
    	$edit_fields=array('Attribute Name','Price', 'URL', 'Sort');
    
    	// check that form has been submitted:
                if(isset($_POST['submit']) && $_POST['submit'] == 'Update')
                {
                    
    
    			$attribute_id = $_POST['attribute_id'];
    			$clid = $_POST['clid'];
          
                    foreach($_POST as $field => $value)
                    {
                        
    			   if($field != 'submit' && $field != 'attribute_id' && $field != 'clid')
                        {
                       		
    				   				
    				   $fields_list[] = "`$field`='" . mysql_real_escape_string($value) . "'";
                        
    				       if ($value == ''){
    
    						echo $field . '<font color="red">ERROR: Please Make sure fields are not empty</font>';
    				        exit;
    				       }	
    
    
    				}
                   
    			}
    
                    $sql = 'UPDATE ' . $tbl_name . ' SET ' . implode(', ', $fields_list) . ' WHERE attribute_id=' . $attribute_id;
                    $result = mysql_query($sql);
                   
    		               
    			 }
                // form has not been submitted, display form
                elseif(isset($_GET['attribute_id']) && is_numeric($_GET['attribute_id']))
                {
                    // get the id from the url
                    // url example: ?action=edit&id=1
                    $id    = $_GET['attribute_id'];
                    // get data from table based on id
                    $sql   = 'SELECT * FROM '.$tbl_name.' WHERE attribute_id='.$attribute_id;
                    // perform query
                    $result = mysql_query($sql);
    
                    // check that the quewry return one result
                    if(mysql_num_rows($result) == 1)
                    {
                        $row = mysql_fetch_assoc($result);
    
                        $form = '<form action="?action=edit" method="post">';
    
                        foreach($row as $field_name => $field_value)
                        {
                            
    					if ($field_name == 'clid' || $field_name == 'attribute_id') 
    
                                $type = 'hidden';						
    					else 						
    					    $type = 'text';
                            
    
    					 $form .= '<input size="50" type="' . $type . '" name="'. $field_name .'" value="' . $field_value . '" /><br />';
    
    				   
                        }
    
                        $form .= '<input type="submit"  name="submit" value="Update" /></form>';
    
                       echo $form;
                    }
                }
            break;
    
    //************************** END EDIT ATTRIBUTES TO PRODUCT *******************************************
    
    //************************** BEGIN DELETE ATTRIBUTES TO PRODUCT *******************************************
    
            case 'delete':
                 
                echo  '<font color="red"><b>' . $attribute_name . ' deleted from ' . $clientname . '</font></b>';
    		exit;		
    		//$sql = "DELETE FROM product_attributes WHERE attribute_id=$attribute_id";	
                //$result = mysql_query($sql);
    
            break;
    
    //************************** END DELETE ATTRIBUTES TO PRODUCT *******************************************
    
    
    //**************************  BEGIN DEFAULT ATTRIBUTES TO PRODUCT *******************************************
    
        default:
                
        $clientname = $_REQUEST['clientname'];
    // get all data from the table
        $sql    = 'SELECT * FROM product_attributes WHERE clid=' . $clid;
        $result = mysql_query($sql);
    
        // get the number of fields from the table
        $num_fields = mysql_num_fields($result);
    
    
       // display results with table fieldnames and "add" link
       echo '<a href="?action=add&clid=' . $clid . '">Add Record</a>';
       
       echo '<table border="1" cellspacing="2" cellpadding="5"><tr>'."\n";
    
    
       // first the field names from table
        for($i = 0; $i < $num_fields; $i++)
        {
    
    	//echo '    <th>' . ucwords(mysql_field_name($result, $i)) . "</th>\n";
        }
        // append the Action column
        echo "    <th>Action</th>\n";
        
        
    
        echo "  </tr>\n";
    
        // now display all content to screen
        while($row = mysql_fetch_assoc($result))
        {
            // use implode to create new cell for each item in the row
            echo "  <tr>\n    <td>" , implode("</td>\n    <td>", $row) . "</td>   ";
    
            // display our action links (edit and delete)
            	
    	echo '<td><a href="?action=edit&attribute_id='.$row['attribute_id'].'&clid='.$row['clid'].'&clientname=' . $clientname . '">EDIT</a> | <a href="?action=delete&attribute_id='.$row['attribute_id'].'&attribute_name=' . $row['attribute_name'] . '&clientname=' . $clientname . '">DELETE</a></td>'."\n  </tr>\n";
        }
        // close table
        echo "</table>\n";
    
    }
    }
    
    //**************************  END DEFAULT ATTRIBUTES TO PRODUCT *******************************************
    
    
    else
    {
    
    
    $clientname = $_REQUEST['clientname'];
    echo '<b>Attributes for : ' . $clientname . '</b>';
    echo '<BR>';
    
     // get all data from the table
        $sql    = 'SELECT * FROM product_attributes WHERE clid="' . $clid . '" ORDER BY sort ASC';
        $result = mysql_query($sql);
    
        // get the number of field from the table
        $num_fields = mysql_num_fields($result);
    
       // display results with table fieldnames and "add" link
       echo '<a href="?action=add&clid=' . $clid . '&clientname=' . $clientname . '">Add Record</a>';
       
       echo '<table border="1" cellspacing="2" cellpadding="5"><tr>'."\n";
    
        $field_array=array('Attribute ID','Client ID','Attribute Name','Price', 'URL', 'Sort');
    
       // first the field names from table
        for($i = 0; $i < $num_fields; $i++)
        {
            //echo '    <th>' . ucwords(mysql_field_name($result, $i)) . "</th>\n";
    	echo '<th bgcolor="#ddf4fd">' . $field_array[$i] . '</th>';
        }
        // append the Action column
        echo '<th bgcolor="#ddf4fd">Action</th>';
        
        
    
        echo "  </tr>\n";
    
        // now display all content to screen
        while($row = mysql_fetch_assoc($result))
        {
            // use implode to create new cell for each item in the row
            echo "  <tr>\n    <td>" , implode("</td>\n    <td>", $row) . "</td>\n    ";
    
            // display our action links (edit and delete)
            	
    	echo '<td><a href="?action=edit&attribute_id='.$row['attribute_id'].'&clid='.$row['clid'].'&clientname=' . $clientname . '">EDIT</a> | <a href="?action=delete&attribute_id='.$row['attribute_id'].'&attribute_name=' . $row['attribute_name'] . '&clientname=' . $clientname . '">DELETE</a></td>'."\n  </tr>\n";
        }
        // close table
        echo "</table>\n";
    
       
    }
    
    ?>

     

  5. Not sure where this fits but our IT department says I need to secure a page with SSL. Its a contact form thats in plain text. How would I go about securing it ? Can anyone supply information on how to install and use SSL ?

  6. This isnt working for me when I embed it into PHP:

     

    <select onChange=”window.open(this.options[this.selectedIndex].value)” name=”s1″>

    <option selected>pick one</option>

    <option value=’http://www.google.com’>google</option>

    <option value=’http://www.yahoo.com’>yahoo</option>

    </select>

     

    Is there a PHP version of creating a dropdown list with a redirect ?

  7. I have a script that add/updates/deletes values in a database. After the sql takes place I'd like to redirect them to a page. When I do this I get the error below:

     

    Warning: Cannot modify header information - headers already sent by (output started at /admin/attributes.php:4) in...

     

    Is there a way to redirect without getting this error ?

     

     

     

  8. Im using the template for a script however I pass in an id through the url so the add/update/delete works for a specific product attributes. How can I make the id global thats passed into the script. For the cases it doesnt recognize the passed in variable.

  9. Is there a way I can ignore fields when I output them in the edit code you just pasted when the form is generated ?

     

    Like:

    foreach($row as $field_name => $field_value)

        {

      if(!$fieldname != id){

     

      //echo fields to be edited

     

      }

             

    }

     

    I dont want to be able to edit ids.

  10. i know you mentioned its bad coding practice to keep things in the same file ... but for the sake of getting something working .. can i create a case called update and have it handle the mysql statement coming from another case ?

     

    //update database

    case 'update':

     

            $attribute_id = $_GET['attribute_id'];

    $attribute_name = $_GET['attribute_name'];

     

    echo $attribute_name;

     

    $sql = 'UPDATE product_attributes SET attribute_id="' . $attribute_id . '", attribute_name="' . $attribute_name . '" WHERE attribute_id="' . $attribute_id . '"';

            $result = mysql_query($sql);

     

        break;

     

     

    //update form

    case 'edit':

                // code here to update data in table

                $attribute_id = $_GET['attribute_id'];

        $attribute_name = $_GET['attribute_name'];

    echo "<form action=\"?action=update&attribute_id=".$attribute_id."&attribute_name=".$_POST['attribute_name']." method=\"post\">";

    echo '<input type="hidden" name="attribute_id" value="' . $attribute_id . '">';

    echo '<input type="text" name="attribute_name" value="' . $attribute_name . '">';

    echo '<input name="update" type="submit" value="Update">';

    echo '</form>';

     

    break;

     

     

    is this even possible ?

  11. So in the case edit I would put my form like below, i know this is wrong how would I pass the edit form tag to properly pass the edited field to edit.php where i guess i would perform the mysql update ?

     

    case 'edit':

     

                // code here to update data in table

           

                    $attribute_id = $_GET['attribute_id'];

    $attribute_name = $_GET['attribute_name'];

     

    echo "<form action=\"edit.php?&attribute_id=".$attribute_id."&attribute_name=attribute_name\" method=\"post\">";

     

    echo '<input type="hidden" name="attribute_id" value="' . $attribute_id . '">';

      echo '<input type="text" name="attribute_name" value="' . $attribute_name . '">';

    echo '<input name="update" type="submit" value="Update">';

        echo '</form>';

    break;

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