php displaying stuff from another file

Joined
12 Feb 2006
Posts
17,644
Location
Surrey
im looking for a way that php will load everything that is on one file and then display it on the page? e.g. i have a php page called submit.php that has a form that will process and add the info from the form to mysql, i then want a simple code that i put on index.php that will just load everything that you would see looking at submit.php.

i have looked on php website and this seems to be kinda of what i'm after but i really don't understand it too well or know how to implement it as im still a newboy to php. Any be able to explain, and if thats not what im looking for, any way i can do this?
 
Trigger said:
Yeah, include(); is the best way of doing it. Or require(); for that matter :) They are almost identical except in the way they handle errors- require(); will produce a fatal error if the file is missing and stop the script whereas include(); will produce a warning but continue the script. :)

i tired include but as i thought, it didnt load what was on submit.php and show it on index.php, it just refers to it.
 
ok here is what i put on index.php

Code:
<? include("submit/submit.php"); ?>

and here is submit.php
Code:
<? include("../login/include/session.php"); ?>

<?php

$file_name = $HTTP_POST_FILES['ufile']['name'];

$random_digit=rand(0000,9999);

$limit_size=50000;

$new_file_name=$random_digit.$file_name;

$file_size=$HTTP_POST_FILES['ufile']['size'];

$path= "upload/".$new_file_name;

if($ufile !=none)



if($file_size >= $limit_size){
echo "Your file size is over limit<BR>";
echo "Your file size = ".$file_size;
echo " K";
echo "<BR>File size limit = 50000 k";
}
else {

{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "File Upload Success<br />";

echo "<b>File Name :</b>".$new_file_name."<br />";
echo "<b>File Size :</b>".$HTTP_POST_FILES['ufile']['size']."<br />";
echo "<b>File Type :</b>".$HTTP_POST_FILES['ufile']['type']."<br />";
}
else
{
echo "";
}
}


include"connect.php"; 

if(!isset($_POST['add_news']))
	{
echo"
<br />
<br />
<form action='$self?action=addnews' name='addnews' id='form1' method='post' enctype=\"multipart/form-data\">
<table>

	<tr>
		<td>
			Title: <input type='text' name='title'>
		</td>
	</tr>

	<tr>
		<td>
			Description:<textarea cols='15' name='description' rows='5'></textarea>
		</td>
	</tr>

	<tr>
		<td>
			URL: http:// <input type='text' name='url'></input>
		</td>
	</tr>
	
	<tr>
		<td>
			Upload Image: <input type='file' name='ufile' id='ufile' size='50' /></input>
		</td>
	</tr>
	
	<tr>
		<td>
			<input type='submit' name='add_news' value='submit news topic'>
		</td>
	</tr>
	
</table>
</form>";	
}
elseif(isset($_POST['add_news'])) 
{
$title = mysql_real_escape_string($_POST['title']);
$url = mysql_real_escape_string($_POST['url']);
$description = $_POST['description'];
$date = date("d.m.y");
$username = $_SESSION['username'];
$imagename = $new_file_name;

$error = array();



if(empty($title)) {
$error[] = "You must enter a title<br />";
}
if(empty($description)) {
$error[] = "Enter a description please<br />"; 
}
if(empty($url)) {
$error[] = "The URL is needed<br />"; 
}

if(count($error)>0) {
echo"<font size='3' color='#CC0000'><strong>ERROR:</strong></font>";
foreach($error as $error2);
echo"$error2";
}
else {

$sql = "INSERT INTO submit(title, description, url, author, date, imagename, valid) VALUES('$title', '$description', '$url', '$username', '$date', '$imagename', '0')";

mysql_query($sql);
echo"Website successfully queued for verification. Your site will be added soon when verified by an Admin.<br />An email will be sent if there is any problems.";
}

}
}

?>

didn't work for me
 
ok some odd reason now its working, well almost. the form and other infomration from submit.php is included, but the troulbe is that as some of the php in submit.php refers to directories that are now different to where index.php is.

How would i sort this? could i have it just select the form? so that that way it will still be submitted to submit.php.

why is it bad pratice to put <? and <?php? do they mean differnt things? the reason i have used them is because i was using tutorials to write the php and some would say ok start off with one and others would start with the other

also wanting to try out yahoo ads on my site, however i can't seem to find a way to get them. can someone post me a link to set them up for my site. i honestly have searched, and i can't find them, just yahoo financing and some other things
 
ok thanks guys for the help i think thats pretty much everything. One last thing actually is that is there a way to make something begin at the root directory and then work it's way to the directory specified? for instance the form i have been talking about is on submit.php but that is in root/submit/ folder. i have the login script in root/login/admin/ etc. Is there a way that i can just put like .../root/etc that will just begin at the first directory, instead of ../ which just goes back one?
 
cheers bud

[edit]
seeing as my thread is at the top i am not gonig to bother making a new thread for this.

wheni started the site i was uploading example php stuff, such as counters. All of which have then been modified, deleted, etc. Im having a problem though as one of the scruipts put a folder up with a file in it which i can't now delete. I have tried many things such as renemaing it, not allowed, changing its permission, not allowed. So im asking is there another way in which i can try delete it, or if all fails, dleelte everything on the server and then just upload it all again as i jhave it all still here.

thanks
 
Last edited:
Back
Top Bottom