Parse error: syntax error, unexpected T_VARIABLE in Mod_Upload.php on line 9

Discussion in 'PHP' started by reddev32, Nov 25, 2010.

  1. #1
    I have been working on this file for over 5 hours and i finaly got it all completed but now i am getting this messsage any ideas?

    The underlined code is the problem and i don' know how to fix it.

    <?php
    //Start session
    session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
    die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
    die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
    $str = @trim($str);
    if(get_magic_quotes_gpc()) {
    $str = stripslashes($str);
    }
    return mysql_real_escape_string($str);
    }

    Please help :D
     
    reddev32, Nov 25, 2010 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    The error lies in the first lines of config.php, not the code you posted.

    It would be helpful if you can post your config file (removing sensitive information) and more information on your PHP version (useful in the event your config.php contains classes).
     
    ThePHPMaster, Nov 25, 2010 IP
  3. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php
    define('DB_HOST', 'localhost');
    define('DB_USER', '');
    define('DB_PASSWORD', '');
    define('DB_DATABASE', ');
    ?>
     
    reddev32, Nov 25, 2010 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    This part is missing an apostrophe:

    define('DB_DATABASE', ');

    should be

    define('DB_DATABASE', '');

    Did that solve your problem?
     
    ThePHPMaster, Nov 25, 2010 IP
  5. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Unfortunatly no :( it was is the same of what u have put as you have put the ' must of gotten deleted in the detion of the inportant data.

    Any others ideas.

    Once i gfet this to work i can apply it to my other uses for it 2 but i can't get ti to work :(
     
    reddev32, Nov 25, 2010 IP
  6. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Mod_Upload.php

    ====================================

    <?php
    //Start session
    session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link)
    {
    die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db)
    {
    die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str)
    {
    $str = @trim($str);
    if(get_magic_quotes_gpc()) {
    $str = stripslashes($str);
    }
    return mysql_real_escape_string($str);
    }
    ?>

    ====================================

    config.php
    ============================

    <?php
    define('DB_HOST', 'db_host');
    define('DB_USER', 'db_user');
    define('DB_PASSWORD', 'db_pass');
    define('DB_DATABASE', 'db_name');
    ?>

    ===================================

    replace db credentials in config.php with your credentials and it will work.

    Enjoy
     
    drctaccess, Nov 26, 2010 IP
  7. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for the reply the above works fine :D
     
    reddev32, Nov 26, 2010 IP
  8. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hey guys its me again i go teh 1st part working but now i getting Parse error: syntax error, unexpected $end in Mod_Upload.php on line 96.

    Any ideas? code is below it follows on from what i 1st posted :(

    if(isset($_POST['upload']) && $_FILES['Mod_ID']['size'] > 0)
    {


    //Sanitize the POST Values
    $Mod_Name = clean($_POST['Mod_Name']);
    $member_id = clean ($_POST['member_id']);
    $Description = clean ($_POST['Description']);
    $Date_Added = clean ($_POST['Date_Added']);
    $Date_Modified = clean ($_POST['Date_Modified']);
    $Image_ID = clean ($_POST['Image_ID']);
    $fileName = $_FILES['Mod_ID']['name'];
    $tmpName = $_FILES['Mod_ID']['tmp_name'];
    $fileSize = $_FILES['Mod_ID']['size'];
    $fileType = $_FILES['Mod_ID']['type'];
    $binary_date = addslashes(fread(fopen($Image_ID, "r"), filesize($Image_ID)));

    //Validations
    if($Mod_Name ==''){
    $errmsg_arr[] = 'Mod Name Missing';
    $errflag = true;
    }
    if($Description ==''){
    $errmsg_arr[] = 'Description Missing';
    $errflag = true;
    }
    if($Image_ID ==''){
    $errmsg_arr[] = 'Please select the mod image to upload';
    $errflag = true;
    }
    if($Mod_ID ==''){
    $errmsg_arr[] = 'Please select an mod to upload';
    $errflag = true;
    }

    //If there a input validations, redirect back to the reqistration form
    if($errmflag){
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
    session_write_close();
    header("location: Supreme_Commander_Upload.php");
    exit();
    }

    //Insert Query
    $qry = "INSERT INTO mod(Mod_Name, member_id, Description, Date_Added, Date_Modified) Values('$Mod_Name','$member_id','$Description','$Date_Added','$Date_Modified')";
    "INSERT INTO mod_file(name, filesize, type, binary_date ) VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
    "INSERT INTO mod_images VALUES ('','$binary_data','$Image_ID_name','$Image_ID_size','$Image_ID_type')";
    $result = @mysql_query($gry);

    //Check whether the query was successful or failed
    if($result) {
    header("location: Mod_Success.php");
    exit();
    }else {
    die("Query failed");
    }
    ?>
     
    reddev32, Nov 27, 2010 IP
  9. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #9
    change this
    }
    ?> 
    Code (markup):
    to this:

    
    }}
    ?> 
    
    Code (markup):
    Should fix it ?
     
    MyVodaFone, Nov 27, 2010 IP
  10. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    ok now this is weird i am just getting a blank sceen theres no data gone in mysql and theres no error file to be seen. :(
     
    reddev32, Nov 27, 2010 IP
  11. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #11
    if(isset($_POST['upload']) && $_FILES['Mod_ID']['size'] > 0)


    all your actions trigger if there is a filed name called "upload" sent via POST and also a file size > 0

    if above conditions are not met .. you will receive blank screen

    to see that for yourself do this:

    replace this:


    ?>

    with this:

    else echo 'nothing done because either no post request of file size greater than 0'; ?>
     
    drctaccess, Nov 27, 2010 IP
  12. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I have fixed/ sort out that problem but now i a getting qeury has fail :(
     
    reddev32, Nov 27, 2010 IP
  13. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    now i am getting Parse error: syntax error, unexpected T_STRING in /home/reddev32/public_html/Vault/supremecommander/Mod_Upload.php on line 90
     
    reddev32, Nov 27, 2010 IP
  14. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #14
    You better outsource your script to someone who can fix it for you.
     
    drctaccess, Nov 27, 2010 IP
  15. reddev32

    reddev32 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    dam :(

    can anyon ehere help me if i send tehm the script?

    if u can contack me @ please
     
    reddev32, Nov 27, 2010 IP