php submitting the username

Joined
12 Feb 2006
Posts
17,908
Location
Surrey
i have a form submitting itself to mysql and then php reading it, which for me, is just brilliant.

something im stuck with now is how would i get the form/php to submit which user submitted the content and then display that content, rather then atm i have it so they have to put a name.

the form is set up so it only will show if the user is signed in, but it thens how would i get the form to say, find username and submit it as something like author?
 
perfect, just what i needed to know.

while im here. when sites are put on a server i know that the file name needs to be index.html for the homepage, what do you do if you want the home page for that domain to be index.php?

thanks

[edit]
also anther thing that would be great to know, how would i g about making a way for the user to upload a picture to go with what they submit? im not looking step by step obviously, just advice where to start, e.g. am i in need first of making a way to upload things, then i want to sort out the rest?
thanks
 
Last edited:
ok i have managed to implement a php script for uploading images, which did work, for some odd reason isn't now but i know i can sort that in a bit. the problem im having now is that i want the image that is uploading to be associated with the rest of the information in the form, so that when icall whats on the form for id 1 etc, it brings the image that was uploaded at the same time, if there is one, if not it displays a default image.

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

<?php

include"connect.php"; 

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

	<tr>
		<td>
			Title
		</td>

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

	<tr>
		<td>
			Description:
		</td>

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

	<tr>
		<td>
			URL: http://
		</td>

		<td>
			<input type='text' name='url'></input>
		</td>
	</tr>
	
	<tr>
		<td>
			Upload Image:
		</td>	
	
		<td>
			<input type='file' name='imgfile'></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'];

$error = array();

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

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, valid) VALUES('$title', '$description', '$url', '$username', '$date', '0')";

mysql_query($sql);
echo"Website successfully queued for verification. Your site will be added when verified by an Admin. Check back soon to see it. An email will be sent if there is any problems.";
}
	}
	
  if(isset($_POST['submit'])) {

$uploadpath = "upload/";

$uploadpath = $uploadpath . basename( $_FILES['imgfile']['name']); 

if(move_uploaded_file($_FILES['imgfile']['tmp_name'], $uploadpath)) {


	echo"This file: ".  basename( $_FILES['imgfile']['name']). "has been uploaded Other Details:";
	echo"Mime Type: ". $_FILES['imgfile']['type'] ."";
	echo"Size (Bytes): ". $_FILES['imgfile']['size'] ."";
	echo"File Name: ". $_FILES['imgfile']['name'] ."";

} 
else {
	echo "There was an error uploading the file, please try again!";
}
  }


?>

i know that i need to add the name for the INSERT INTO part but i have no clue how i'd get the name if that makes sense.

hoping someone can help me out here
 
Back
Top Bottom