Jump to content

help


jonny5771

Recommended Posts

I am trying to make a portal but there is something wrong with my php code. Here is a list of all my pages so you may see what is wrong  :). i have been trying to work this one out for days. so i will be very grateful for any help.

 

here is my submit.htm page

 

<html>
<head>
<title>Submit Flash</title>
</head>
<body>
<p><strong><font size="5">Submit Flash</font></strong></p>
<p><strong><font size="3">Agreement:</font></strong><br>
<textarea name="textarea" cols="40" rows="2">Type the user agreement here, however this is optional).</textarea>
</p>
<form action="upload.php" method="post" enctype="multipart/form-data" name="uploadform">
<p><strong><font size="3">Your Name:</font></strong>
<input name="name" type="text" id="name" size="26" maxlength="26">
</p>
<p><strong><font size="3">Your Email:
<input name="email" type="text" id="email" size="26" maxlength="26">
</font></strong></p>
<p><strong><font size="3">Website:
<input name="website" type="text" id="website" size="26" maxlength="26">(Optional)
</font></strong></p>
<p><strong><font size="3">Title:
<input name="title" type="text" id="title" size="26" maxlength="26">
</font></strong></p>
<p><strong><font size="3">Category:
<!--You may change these values if you want-->
<select name="category" id="category">
<option value="">--------Select---------</option>
<option value="Humor">Humor</option>
<option value="Violence">Violence</option>
<option value="Action">Action</option>
<option value="Music">Music</option>
<option value="Game/Interactive">Game/Interactive</option>
<option value="Other">Other</option>
</select>
</font></strong></p>
<p><strong><font size="3">Width:
<input name="width" type="text" id="width" value="550" size="4" maxlength="4">
(Default is 550)</font></strong></p>
<p><strong><font size="3">Height:
<input name="height" type="text" id="height" value="400" size="4" maxlength="4">
(Default is 400) </font></strong></p>
<p><strong><font size="3">Description:<br>
<textarea name="description" cols="40" rows="5" id="description"></textarea>
(Optional)
</font></strong></p>
<p><strong><font size="3">File (.swf):
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">
<input name="userfile" type="file" id="userfile">
</font></strong></p>
<p><strong><font size="3">
<input type="submit" name="Submit" value="Submit">
</font></strong></p>
</form>
<p><strong></strong></p>
</body>
</html>

 

and here is the code that goes in the MySQL database

 

CREATE TABLE flash
(
flashid INT(5) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(26) NOT NULL,
author VARCHAR(26) NOT NULL,
email VARCHAR(26),
website VARCHAR(26),
category VARCHAR(20) NOT NULL,
width INT(4) UNSIGNED NOT NULL,
height INT(4) UNSIGNED NOT NULL,
description TEXT NOT NULL,
userfile VARCHAR(26) NOT NULL,
views INT(5) UNSIGNED DEFAULT '0' NOT NULL,
date VARCHAR(30) NOT NULL,
score FLOAT(2, 1) DEFAULT '5.0' NOT NULL,
votes INT(5) UNSIGNED DEFAULT '1' NOT NULL
);

 

 

and here is the code for the database connect

 

 

<?php
@ $db = mysql_pconnect('dbhost', 'username', 'password');
if (!$db)
{
echo("Could not connect to database");
exit;
}
mysql_select_db('databasename'); //the name of your database
?>

 

note: where it says dbhost, username, password, and databasename, i had enterd my info.

 

 

 

here is my upload.php page

 

<html>
<head>
<title>Submit Flash</title>
</head>
<body>
<?php


// $userfile is where file went on webserver
$userfile = $_FILES['userfile']['tmp_name'];

// $userfile_name is original file name
$userfile_name = $_FILES['userfile']['name'];

// $userfile_size is size in bytes
$userfile_size = $_FILES['userfile']['size'];

// $userfile_type is mime type e.g. image/gif
$userfile_type = $_FILES['userfile']['type'];

// $userfile_error is any error encountered
$userfile_error = $_FILES['userfile']['error'];

if ($userfile_error > 0)
{
echo 'Error: ';
switch ($userfile_error)
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}

if ($userfile_type != 'application/x-shockwave-flash')
{
echo 'Error: file must be SWF';
exit;
}

require ("dbconnect.php");
$query = "select * from flash";
$result = mysql_query($query);

//this makes the userfile_name the same as its flashid
$userfile_name = (mysql_num_rows($result))+1;

$upfile = 'upload/'.$userfile_name.'.swf';

if (is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Error: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Error: Possible file upload attack. Filename: '.$userfile_name;
exit;
}

$fileuploaded = 'upload/'.$file_name.'.swf';
//unlike the file upload script this does not need to be the full path to the directory

$date = date('F jS, Y'); //gets the date added by simple PHP date function
$date = addslashes($date); //we must add slashes to everything before entering it into the database

//add slashes to other variables
if ($website){$website = addslashes($website);}

if ($description)
{
$description = addslashes($description);
}
else
{
$description = 'N/A';
}
$name = addslashes($name);
$title = addslashes($title);
$width = addslashes($width);
$height = addslashes($height);
$category = addslashes($category);

//enter information into database creating a new row
$query = "INSERT INTO flash (author, title, website, email, width, height, description, userfile, category, date) VALUES ('$author', '$title', '$website', '$email', '$width', '$height', '$description', '$userfile', '$category', '$date')";

$result = mysql_query($query);
echo("File uploaded sucessfully!");
?>
</body>
</html>

 

 

here is my view.php page

<html>
<head>
<title>View Flash</title>
</head>
<body>
<?php
require("dbconnect.php");

/add slashes to flashid (passed via view.php?id=$id)
$id = addslashes($id);

//selects database row with passed flashid
$query = "select * from flash where flashid = $id";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

//declare variables
$views = stripslashes($row['views']);
$score = stripslashes($row['score']);
$score = $score.' / 10';
$title = stripslashes($row['title']);
$author = stripslashes($row['author']);
$email = stripslashes($row['email']);
$website = stripslashes($row['website']);
$height = stripslashes($row['height']);
$width = stripslashes($row['width']);
$description = stripslashes($row['description']);
$userfile = stripslashes($row['userfile']);
$date = stripslashes($row['date']);
$category = stripslashes($row['category']);
$flashid = stripslashes($row['flashid']);

echo("<font size="4"><strong>Movie Stats</strong></font><br>");
echo ("<strong>Title: </strong>$title<br>");
echo ("<strong>Author: </strong>$author<br>");
echo ("<a href='mailto:$email'>Email</a> | <a href='$website' target='_blank'>Website</a><br>");

echo ("<strong>Category: </strong>$category<br>");
echo ("<strong>Date Added: </strong>$date<br>");
echo ("<strong>Views: </strong>$views<br>");
echo ("<strong>Score: </strong>$score<br>");

//make rate form so user can rate submission (we will create the rate.php file later)
echo("<form name='form1' method='post' action='rate.php?id=");");
echo($flashid);
echo("'><div align='center'>
<select name='rate' id='rate'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>
<input type='submit' name='Submit' value='Rate'>");

echo("<p><font size="4"><strong>$title</strong></font></p>");
echo("<div align='left'><strong><font style='text-decoration=underline'>Author's Discription:</font></strong><br>");
echo ($description);

//echo link that opens movie in new non-resizeable window
echo("<br>
<a href=\"javascript:void(0)\" onClick=\"window.open('");
echo ($userfile);
echo ("','miniwin','toolbar=0,location=0,directories=0, status=1,menubar=0,scrollbars=0,resizable=0,");
echo ("width=");
echo ($width);
echo (", height=");
echo ($height);
echo ("')\">");

//checks if submission is a movie or a game
if ($category == 'Game/Interactive')
{
echo("Play Game");
}
else
{
echo("Play Movie");
}
echo("</a>");

//Read/Write reviews link (opens reviews window)
$query = "select * from flash_reviews where flashid = $id";
$result = mysql_query($query);
$numreviews = mysql_num_rows($result);
echo("<a href=\"javascript:void(0)\" onClick=\"window.open('review.php?id=$id','miniwin ','toolbar=0,location=0,directories=0,status=1,men ubar=0,scrollbars=0,resizable=0,width=470, height=510')\">Write/Read Reviews(");

//prints number of reviews already written
echo ($numreviews);
echo (")</a>");

$views++;
$viewquery = "update flash set views = '".$views."' where flashid = $id";
$viewresult = mysql_query($viewquery);

?>
</body>
</html>

 

 

And finally here is the portal.php

 

<html>
<head>
<title>Flash Portal</title>
</head>
<body>
<?php
require("dbconnect.php");

echo("<font size='4'><strong>15 Most Recent</strong></font>");
//displays most recent flash using a while loop
$query = "SELECT * FROM flash ORDER BY flashid DESC LIMIT 15";
$result = mysql_query($query);
$i = 0;
while ($row = mysql_fetch_array($result))
{
//increases printed number for flash by one
$i++;
//declare varibles
$score = stripslashes($row['score']);
$title = $row['title'];
$flashid = stripslashes($row['flashid']);

//print flash submission
echo($i);
echo(" - ");
echo("<a href='view.php?id=");
echo($flashid);
echo(">$title</a>");

//tells if submission is excellent (score higher than 7.0), okay (score between 3.0 and 7.0), or bad (score lower than 3.0)
if ($score <= 3.0)
{
echo("(Bad!)");
}
else if ($score > 3.0 && $score <= 7.0)
{
echo("(Okay)");
}
else if ($score > 7.0)
{
echo("(Excellent!)");
}
echo("<br>");
}

echo("<font size='4'><strong>15 Most Viewed</strong></font>");
//displays 15 most viewed flash
$query = "SELECT * FROM flash ORDER BY views DESC LIMIT 15";
$result = mysql_query($query);
$i = 0;
while ($row = mysql_fetch_array($result))
{
//increases printed number for flash by one
$i++;
//declare varibles
$score = stripslashes($row['score']);
$title = $row['title'];
$flashid = stripslashes($row['flashid']);

//print flash submission
echo($i);
echo(" - ");
echo("<a href='view.php?id=");
echo($flashid);
echo(">$title</a>");
echo("<br>");
}

echo("<font size='4'><strong>Top 15</strong></font>");
//displays 15 top flash (ordered by highest score)
$query = "SELECT * FROM flash ORDER BY score DESC LIMIT 15";
$result = mysql_query($query);
$i = 0;
while ($row = mysql_fetch_array($result))
{
//increases printed number for flash by one
$i++;
//declare varibles
$score = stripslashes($row['score']);
$title = $row['title'];
$flashid = stripslashes($row['flashid']);

//print flash submission
echo($i);
echo(" - ");
echo("<a href='view.php?id=");
echo($flashid);
echo(">$title</a>");
echo("<br>");
}

//finish up page by adding end tags
?>
</body>
</html>

 

EDITED BY WILDTEEN88: Please use the code tags (


) when posting code within posts. Thank you.

Link to comment
Share on other sites

the code seems to be alright, can you see any errors when you click the submit.

 

When I upload the file it says the file was uploaded successfully but the title, name, with, height, ect is not displayed in the mysql database. and when I go to the portal all that shows is the id not title ect... so there is a problem with sending the info to the my sql database or something.

Link to comment
Share on other sites

You should retrieve form variables from the $_POST array, not assume they exist globally.

 

For example:

 

$description = $_POST['description']; // retrieve from POSTed variables array

 

Yeah that worked thanks  :D. But just one more problem, when I go to the flash portal and click on the submitted flash, a blank screen with nothing on appears. Maybe the vew.php page is coded wrong. could ya please take a look?

 

Thanks  :)

 

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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