Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3626910
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:49:18+00:00 2026-05-18T23:49:18+00:00

I’m working with a solution provided by Cool Hand Luke UK which upload’s a

  • 0

I’m working with a solution provided by Cool Hand Luke UK which upload’s a file and add various details to MySQL (here’s the post). So far, works great, but I want to change things a little.

My form is set-up to allow users to add either a file or a URL, but not both at once (code below, still some work to do to show/hide the URL and file fields but I’m sure you get the idea). I’d like to use the same script but run into issues when the file field is not populated.

I hoped someone could help tweak the php to allow me to have both functions using the same php?

Any help would be fantastic. Thanks in advance.

—

PHP (insert_news.php):

    <?php error_reporting(E_ALL^E_NOTICE);

    define('INCLUDE_CHECK',true); include "connect.php";

    $target = "../uploads/"; $target = $target . basename( $_FILES['photo']['name']);

    //This gets all the other information from the form 
    $name=$_POST['name']; 
    $author=$_POST['author'];
    $newsID=$_POST['newsID']; 
    $description=$_POST['description']; 
    $type=$_POST['type']; 
    $url=$_POST['url']; 
    $pic=(mysql_real_escape_string($_FILES['photo']['name']));

    //Writes the information to the database 
    mysql_query("INSERT INTO adidas_news (name, description, documentName, author, newsID, url, type) VALUES ('$name', '$description', '$pic', '$author', '$newsID', '$url', '$type')");

    //Writes the photo to the server 
    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {

    //Tells you if its all ok 
    header("Location: ../news.php"); } else {

    //Gives and error if its not 
    echo "Sorry, there was a problem uploading your file."; }

    ?>

Form:

<form method="post" id="addURLForm" action="insert_news.php">
                <img src="images/bg_addform_top.gif" width="446" height="11" />
                    <table class="addForm" cellspacing="0">
                      <tr>
                        <th>Name:<span class="greenText">*</span></th>
                        <td><input name="name" type="text" class="textBox required" maxlength="80" /></td>
                      </tr>
                      <tr>
                        <th>Type:<span class="greenText">*</span></th>
                        <td>
                            <select name="type" class="textBox">
                                <option selected="selected">-- Select --</option>
                                <option value="file">File/Document</option>
                                <option value="url">URL/Link</option>
                            </select>
                        </td>
                      </tr>
                      <tr>
                        <th>Full URL:<span class="greenText">*</span></th>
                        <td><input name="url" type="text" class="textBox url" maxlength="120" /></td>
                      </tr>
                      <tr>
                        <th>File:<span class="greenText">*</span></th>
                        <td><input type="file" class="" name="photo"></td>
                      </tr>
                      <tr>
                        <th>Description:<span class="greenText">*</span></th>
                        <td><textarea name="description" class="textBox required"></textarea></td>
                      </tr>
                      <tr>
                        <th>
                            <input name="newsID" type="hidden" value="<?php
                            for ($i=0; $i<5; $i++) {
                            $d=rand(1,30)%2;
                            echo $d ? chr(rand(65,90)) : chr(rand(48,57));
                            }
                            ?>" />
                            <input name="author" type="hidden" value="<?php             
                            $result = mysql_query("SELECT * FROM adidas_members WHERE usr='".$_SESSION['usr']."'");
                            while($row = mysql_fetch_array($result))
                            {
                            echo "" . $row['fullName'] . "";
                            }
                            ?>" />
                        </th>
                        <td><input type="image" class="submitButton" src="images/button_submit.gif" /></td>
                      </tr>
                    </table>

            </form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:49:19+00:00Added an answer on May 18, 2026 at 11:49 pm

    In your PHP Script you can add the check to see if any file is uploaded or not.

    For example see below snippet.

    if(isset($_FILES['photo']['tmp_name'])) //  check if any file is uploaded
    {
    
       //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
    
       //Tells you if its all ok header("Location: ../news.php"); } else {
    
       //Gives and error if its not echo "Sorry, there was a problem uploading your file."; }
    }
    

    Hope this will Help

    Thanks!

    Hussain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.