Using $_GET['action'] in a form.
#1

Okay, so I'm not all that good with PHP and was wondering how I'd get an action from a form.

For example, you can upload a MP4, PNG or a JPEG file.

so when they file uploads, I want to add "?action=success" to the url so the website knows to display the $success message.

But I'm not all that good with it, could someone help me out?

Form code:
PHP код:
<div class="container">
                <
center>
                <
h3>Upload your file:</h3>
                <
form action="home.php?action=" method="POST" enctype="multipart/form-data">
                    <
input type="file" name="file" />
                    <
input type="submit" name="submit" value="Upload">
                </
form>
                </
center>
            </
div
PHP Code:
PHP код:
if(isset($_POST['submit']))
{
    
$name $_FILES['file']['name'];
    
$temp $_FILES['file']['tmp_name'];
    
$type $_FILES['file']['type'];
    
$size $_FILES['file']['size'];
    
$url "localhost/video%20host/uploaded/$name";
    
$error "<div class='alert alert-danger'>There was an error uploading your file. Supported files are: MP4 - Jpeg - PNG</div>";
    
$success "<div class='alert alert-success'>File uploaded successfully. <br />Link:<br/>$url</div>";
    
    if((
$_FILES["file"]["type"] == "video/mp4") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png"))
    {
        
move_uploaded_file($temp,"uploaded/".$name);
        
mysql_query("INSERT INTO `videos` VALUE('', '$name', $url')");
        
    }

Reply
#2

if($_GET['action'] == 'success')

Reply
#3

Quote:
Originally Posted by king_hual
Посмотреть сообщение
if($_GET['action'] == 'success')

Yes.. but how do I set it when using a form-.-
Reply
#4

So you want to redirect the user to the same page but with ?action=success ?
Reply
#5

Yup.

EDIT: Ok, I know how to use $_GET['action'] when using it in <a> tags for example.
But not when using a form.
Reply
#6

Use input type hidden.
Код HTML:
<input type="hidden" name="action" value="foo">
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
Forms use $_POST, not $_GET. And you REALLY need to learn how to sanitise inputs - that code is currently begging for SQL injections.
Yes I know. But I've fixed it now, don't worry.
Reply
#8

Quote:
Originally Posted by Zeppo
Посмотреть сообщение
Yes I know. But I've fixed it now, don't worry.
That's what everyone says, and it only makes me worry more.
Reply
#9

At the end of your php code put:

PHP код:
header('Location: /?action=success'); 
The header location redirects the browser to that URL.
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
Forms use $_POST, not $_GET. And you REALLY need to learn how to sanitise inputs - that code is currently begging for SQL injections.
Код:
<form method="get"></form>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)