slyme 27 Junior Poster in Training

I am assuming MySQL is the database - Are the databases on the same server? If not check this:

http://dev.mysql.com/doc/refman/5.0/en/replication.html

Actually, for all I know you may be able to replicate on the same server but I don't know for sure although I suspect that you can't.

Or you run all your scripts twice against all database functions, one for each database.

slyme 27 Junior Poster in Training

Give the users two fields - one to identify the user and one for the embedded object code from the youtube video - stick 'em both into a database and you can then read the database to output the listings.

You could also stick the youtube homepage in an iframe so the users can go to their video and copy and paste the embedded object code without switching pages.

slyme 27 Junior Poster in Training

If you want to do it the 'Dreamweaver Way' you could start here:

http://www.adobe.com/devnet/dreamweaver/application_development.html

slyme 27 Junior Poster in Training

I like that idea of sticking all the new line and tab stuff into variables, I wish I'd thought of that ages ago - I like to make my html output easily readable so my code is littered with "\n" and "\t" which makes my PHP code a bit messier than I would like. This will tidy it up a treat, I shall be using it for sure.

slyme 27 Junior Poster in Training

Should the IP number be part of the folder path? Or should the path be relative to the script? Like so:

$uploadDir ="upload/joomla/";

This assumes that the script is working in the directory that also contains the sub-directory "upload".

Or are you working on one server, uploading to another? That's above my pay grade but if so, I'm guessing various permission settings are going to be an issue here and I would use PHP ftp functions to move the file (only 'cos I don't know any better!)

slyme 27 Junior Poster in Training

Whenever you receive an email, your email client (Outlook/Thunderbird/Windows Mail whatever) will display that email as either HTML or plain text depending upon your settings.

You do not see anything except that which you need to see. There is, in fact, a lot of information that you are not seeing.

If you select 'View Source' then you will see the actual text file that your PHP script created. This information will help us track down the problem.

You will probably find 'View Source' below the 'View' menu in Outlook. Which version of Outlook are you using?

Hope this makes some sense ...

Simon.

slyme 27 Junior Poster in Training

You gotta have some php in the html, I believe that you want to minimise this?

How about - at the top of the page, above all html or in another page entirely but included in you html page:


<?php
$myoutput = '';
while ($row = mysql_fetch_array($result)) {
$myoutput .= '<tr><td>' . $row . '</td></tr>';
$myoutput .= '<tr><td>' . $row . '</td></tr>';
}
?>


Then, in your html:

<table>
<?php echo $myoutput; ?>
<\table>


That's about as separate as you're gonna get I think.

slyme 27 Junior Poster in Training

Almostbob you are a star, thank you. The penny has finally dropped. This has vexed me for some years now and I finally get it thanks to your replies. Now, if someone could explain what the second number in a musical time signature means then I would be walking on air! :)

I love the idea of serving up polka music to hackers!

thanks,

Simon.

slyme 27 Junior Poster in Training
slyme 27 Junior Poster in Training

Ah ... now that's the bit I don't get ... how do I protect a file or a directory using PHP (general pointers ... not asking for it to be done for me!)?

I have a log in routine, the relevent session is set and that's fine, I can do anything I like inside a page using PHP to list information acoording to logged status.

So, say I list a load of links to a some mp3 files and some of these mp3s are only listed for logged on users ... what's to stop someone simply putting the URL for the mp3 file itself in? They would still get the file even if they were not logged in.

My code has to work on Windows IIS and Apache. I believe that I could accomplish this on a Linux machine with .htaccess but I don't have that luxury.

As a point of interest, will .htaccess work on sites hosted on my mac?

thanks for your help,

Simon.

slyme 27 Junior Poster in Training

Of course! Too many hours without nicotine here!

slyme 27 Junior Poster in Training

So, the redirect at the top proved useful once I realised what was going on! I am assuming that the redirect destination page is the form?

There are no values in the checkbox input fields. If you include value="gorilla" (or whatever) in the form input field then that is the value that you will get if it is checked. If it is not checked you won't get any value.

hope this helps ...
Simon.

Edit ... hang on ... I've looked again ... values are there now! Was I mistaken or did you just figure it out? :-)

slyme 27 Junior Poster in Training

Not the source of your code .... the source of your email (the actual email that you receive) ... so, when you read your email it is probably presented to you as either plain text or html depending on your settings. You will have an option to 'View source' somewhere ... that source will be useful for evaluating what's going wrong.

slyme 27 Junior Poster in Training

You have got a mail server running haven't you? I use IIS/PHP on Windows and I run Mercury Mail Server (because the IIS mail server is a bit of a mystery to me) to handle the email. I'm guessing that Apache/PHP on windows will also need a mail server.

Also, take out the <? echo $_POST; ?> so that the form action is action=""

slyme 27 Junior Poster in Training

Should there be a $ in front of the first qr on line 68?

slyme 27 Junior Poster in Training

Take a look at the source of your email (make it one with a small attachment) and paste what you find here. Then we can get some idea of what your code is outputting .... my money is on a problem with the boundaries.

slyme 27 Junior Poster in Training

I suspect that the reason you are getting the ATT00407.txt is because the email client reads the attachment boundaries but finds nothing in between.

If there is a possibility of no file being uploaded then you should surround the attachment boundaries with an if statement to check that the file error is 0.

I have found that, on some servers, the file won't attach unless it is first moved from the temp directory(don't forget to delete it at the end).

You may find this page useful: http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

I kept getting in a tangle with this until I got my head around the content types and their associated boundaries.

Hope this helps ...
Simon.

slyme 27 Junior Poster in Training

Ardav is correct Motorider, you do not have a variable function so that's not the problem.

Here's what I would do at this point:

Using phpMyAdmin or some MySQL tool I would simply run the select query and check for results. If that doesn't help, I would then replace all of the code inside the if statement with:

$search_result = 'form submitted';

Then I would submit the form just to check that side of it is working (which it should be).

One of these tests should highlight the problem. Perhaps you could add an if statement inside the database query to return 'no records found' if the search result is genuinely empty.

Let us know how it goes ...

Simon.

Motorider commented: He helped me out tremendously +1
slyme 27 Junior Poster in Training

Ah, I see ... you want the file field to be populated with the original full local file path and name if the upload fails so that the user can simply click on the send button again?

Sorry, I don't even know if this is possible as I believe (but am not certain) that this information does not get sent to the server, just the file gets sent. I could so easily be wrong mind you.

Sorry I couldn't be more helpful,

Simon.

slyme 27 Junior Poster in Training

$_FILES where 'attachedfile' is the name of the form field. If the error is 0 then all went well. Look here for an explanation of the error code:
http://us3.php.net/manual/en/features.file-upload.errors.php

Also, this will give you some info regarding the files array:

echo '<pre>';
	print_r($_FILES);
	echo "</pre>";
slyme 27 Junior Poster in Training

Here you go Motorider - I have set the form action empty, this has the same effect as your code above.

I cannot check if the code runs properly once the form button is clicked because, obviously, I don't have the database.

<?php
	
//Create an empty variable
$search_result = '';

//If statement, to check if the submit button has been clicked.
if (isset($_POST['submit'])) {
	//Connect To Database
	$hostname='';
	$username='';
	$password='';
	$dbname='';

	mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
	mysql_select_db($dbname);
	
	$mytype = $_POST['mytype']; //this is an integer
	$term = $_POST['desc']; //this is a string
	
	$sql = mysql_query("select * FROM products WHERE description like '%$term%' AND product_type_id = '{$mytype}'");
	
	while ($row = mysql_fetch_array($sql)) {
		// Use the variable to build the result
		$search_result .= 'ID: '.$row['ID'] . "\n";
		$search_result .=  '<br/> Part No: '.$row['part no'] . "\n";
		$search_result .=  '<br/> Description: '.$row['description'] . "\n";
		$search_result .=  '<br/> Price: '.$row['price'] . "\n";
		$search_result .=  '<br/><br/>' . "\n";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bus Parts Search</title> 
<link href="test.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 12pt}
.style2 {font-size: 12px}
-->
</style>
</head>

<body>
<div>
<div class="banner"><img src="graphics/stainlessbg2copy.jpg" width="950" height="125"></div>
    
<div class="cont"></div>

<div class="head1">
  <h4><u>Search Parts Here</u></h4>
  <h4 class="style1">First Select type. </h4>
  <h4 class="style1">Enter part description keyword<br>
  and submit.</h4>
  <h4 class="style1">To see a complete list of parts<br>
    on hand for a type.<br>
    Submit with description blank.</h4>
  </div>

<div class="search"> …
slyme 27 Junior Poster in Training

The variables $table and $suburb will be empty when the page is first loaded. They will only populated once the form has been submitted - whatever other problems there may be, I think this should be avoided by using an if statement to check that the form has been submitted before executing any other code.

slyme 27 Junior Poster in Training

Yep, it's a PHP thingie then!

Right, so I store the files outside of the root. Users log on to the site and get the appropriate session details set. Then they browse to a page full of links to various files, PDFs and MP3s. Some files are public and everyone gets that list. Some files are private and only logged users see that list.

How should I form the URL to link to the private files and what's to stop a user returning to a file after they have logged off?

Thanks,

Simon.

slyme 27 Junior Poster in Training

Sorry to all if this is in the wrong forum, I'll move it if someone tells me where it should go.

I saw another poster discussing some files stored above the root ... well here's what was posted:

"I have a script which generates invoices as PDF files and stores above just above www level (so they cannot be access directly via a URL)."

How does this work (I would like to use this)? If the files cannot be accessed via a URL, how are they accessed?

Thanks,

Simon.

slyme 27 Junior Poster in Training

Look at the email source - does it have the appropriate boundaries? If so, is there any text at all where the attachment should be?

Also, I have had an issue on some servers where the attachment won't attach unless it is first moved out of the temp folder to another location. Not sure why, maybe the file gets deleted before the attchment process is complete, maybe it has something to do with permissions, whatever, moving the file first can help.

slyme 27 Junior Poster in Training

Ok - surround the code with an if statement to check whether the form has been posted or not.

I'm guessing that the code is being executed without any input when you first load the page.

slyme 27 Junior Poster in Training

You can use this script to test your db/php stuff - fill in the blanks at the top and run it, if it fails you should glean some more meaningful info:

<?php

$db_host = ''; 
$db_name = '';
$db_user = '';
$db_password = '';


$db_table = '';
$db_query = '';
$db_field = '';
$db_display = '';


$con = mysql_connect($db_host, $db_user, $db_password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db_name, $con);
$result = mysql_query("SELECT * FROM $db_table WHERE $db_field = '$db_query'");

while($row = mysql_fetch_array($result))
  {
  echo $row[$db_display];
  }


mysql_close($con);
?>
slyme 27 Junior Poster in Training

Try this:

("SELECT * FROM '" . $table . "' WHERE Suburb = '" . $suburb . "'")

slyme 27 Junior Poster in Training

Stick the PHP code right at the top of the page (just to keep things neat and tidy really) above the HTML stuff.

Create an empty variable, say $output_result before your existing code.

Now, surround your code (not the empty variable) with an if statement. The if statement should test whether or not the Submit button has been clicked.

Instead of using echo in your code use the empty variable and fill it with the result.

Finally, echo the empty (or not!) variable in the div where you want to display the results.

Remember to set the form action to refer back to the same page.

hope this helps ...
Simon

slyme 27 Junior Poster in Training

Is $suburb text or numeric? If it is text it needs the single quotes around it.
If it is numeric then you don't need the quotes.
Either way, as Thirusha says, you do need the curly brackets (plus the double quote on the end).

slyme 27 Junior Poster in Training

I think Nvu may be of interest - just google Nvu, you'll find it.

slyme 27 Junior Poster in Training

Create a file called mailtest.php and stick the code below into it - should do the trick. If you are testing it locally then you will need a mail server running on your machine.

It is pretty basic, you'll have to add some stuff for handling any other input fields. It will give you the basic attachment routine.

Remember to change the email at the top, the $uploaddir variable and alter $allowedExtensions to suit.

<?php
$to = "your@email.co.uk"; // Change to your email
$from = "some@email.co.uk"; // Perhaps you will collect this as part of the form
$subject = 'Test Email'; // Again, perhaps you will collect this as part of the form
$message = 'Test message';  // And once again perhaps you will collect this as part of the form
$uploaddir = 'uploads\\'; // You will need to create a directory and put its name here. The directory will need permissions set so that the script can move files into it and then delete them. Don't remove the \\
$error_state = false;
$random_hash = md5(date('r', time())); 
$page_output = '<form action="" method="post" enctype="multipart/form-data">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
<input type="file" name="attachedfile" /><br />
<input type="submit" name="submit" value="Send" /></form>
';
$allowedExtensions = array("rtf", "doc", "docx", "pdf", "odt"); // change this to suit your needs
function isAllowedExtension($fileName) {
	global $allowedExtensions;
	return in_array(end(explode(".", $fileName)), $allowedExtensions);
}

if (isset($_REQUEST["submit"]) && $_REQUEST["submit"] == 'Send') {
	if ($_FILES['attachedfile']['error'] == 0) {
		$file = $_FILES['attachedfile'];
		if(isAllowedExtension($file['name'])) …
slyme 27 Junior Poster in Training

Do you mean you want to generate a hyper link on the page using the the items in the array? Sort of like this:

echo '<a href="http://mysitehere-localhost.com/testing.php?yourpage' . http_build_query($data) . '">my link</a>';

The 'yourpage' bit of the link is throwing me (what's it for?) a bit so maybe I haven't quite got what you want to do.

Sorry if I have misunderstood, hope this helps ...
Simon.

slyme 27 Junior Poster in Training

MySQL is straight forward to install and use. I use TinyMCE/PHP(sometimes ASP)/MySQL(sometimes Access) to create/edit/delete web pages and find it fantastic combination.

If you can't use MySQL or any other database then you can use text files to hold the data.

You will need to set permissions on the files/directory. If the files need to go into the root then create/edit them in another directory and use PHP ftp functions to move them.

Hope this helps ...

Simon.