Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209

    Forum field posts even on null

    Hey, so every time the forum posts, the "staff_members" Variable posts, even when theres nothing in it.
    Code:
     
     if(isset($_GET['success']) && empty($_GET['success'])) {
    	echo '<font color='green'>The server settings were successfully updated !</font>';
    } else {
    if(empty($_POST) == false && empty($errors) == true) {
    	if(empty($_POST['votifier_key'])) $votKey = "false"; else $votKey =  htmlspecialchars($_POST['votifier_key'], ENT_QUOTES);
    	$votPort = (int)$_POST['votifier_port'];
    	$votIp	 =  htmlspecialchars($_POST['votifier_ip'], ENT_QUOTES);
    	$ip 	 = $_POST['ip'];
    	$port	 = $_POST['port'];
    	$name    =  htmlspecialchars($_POST['name'], ENT_QUOTES);
    	$website 	 = $_POST['website'];
    	$show_port 	 = $_POST['show_port'];
    	$youtube_id  = htmlspecialchars($_POST['youtube_id'], ENT_QUOTES);
    	$description = htmlspecialchars($_POST['description'], ENT_QUOTES);
    	$category = (isset($_POST['category'])) ? json_encode($_POST['category']) : "null";
    	$country = (country_check(0, $_POST['country'])) ? $_POST['country'] : 'US';
    
    
    	if($image != false) { 
    		$image_new_name = md5(time().rand()) . '.' . $image_file_extension;
    		move_uploaded_file($image_file_temp, 'banners/' . $image_new_name);	
    	 	@unlink('banners/'.$data['banner']);
    		mysql_query("UPDATE `servers` SET `banner` = '$image_new_name' WHERE `id` = '$sid'");
    	}
    
    
    	mysql_query("UPDATE `servers` SET `ip` = '$ip', `port` = '$port', `country` = '$country', `show_port` = '$show_port', `website` = '$website', `youtube_id` = '$youtube_id', `description` = '$description', `category_id` = '$category', `name` = '$name', `votifier_key` = '$votKey', `votifier_ip` = '$votIp', `votifier_port` = '$votPort' WHERE `id` = '$sid'");
    $listofstaff = explode(",",$_POST['staff_members']);
    	if(empty($_POST) == false) foreach($listofstaff as $staff){
    		$s = explode(";", $staff);
    
    
    		mysql_query("INSERT INTO `servers_staff` (`ID`, `serverID`, `player`, `rank`) VALUES (NULL, '$sid', '$s[0]', '$s[1]')");
    }

    As I was not the one who added it to the site, I have no idea how to fix it -_-
    Basically I need the field "staff_members" if null, not to post anything, just like most of the other fields.


    Thanks!

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    I have no way to test it, so make a safe copy of what you already have in case you need to put it back.

    Here is what I came up with:
    Code:
    if(isset($_GET['success']) && empty($_GET['success'])) {
     echo '<font color='green'>The server settings were successfully updated !</font>';
    } else {
    $listofstaff = explode(",",$_POST['staff_members']);
    if(empty($_POST) == false && empty($errors) == true && count($listofstaff)>0) {
     if(empty($_POST['votifier_key'])) $votKey = "false"; else $votKey =  htmlspecialchars($_POST['votifier_key'], ENT_QUOTES);
     $votPort = (int)$_POST['votifier_port'];
     $votIp  =  htmlspecialchars($_POST['votifier_ip'], ENT_QUOTES);
     $ip   = $_POST['ip'];
     $port  = $_POST['port'];
     $name    =  htmlspecialchars($_POST['name'], ENT_QUOTES);
     $website   = $_POST['website'];
     $show_port   = $_POST['show_port'];
     $youtube_id  = htmlspecialchars($_POST['youtube_id'], ENT_QUOTES);
     $description = htmlspecialchars($_POST['description'], ENT_QUOTES);
     $category = (isset($_POST['category'])) ? json_encode($_POST['category']) : "null";
     $country = (country_check(0, $_POST['country'])) ? $_POST['country'] : 'US';
    
     if($image != false) { 
      $image_new_name = md5(time().rand()) . '.' . $image_file_extension;
      move_uploaded_file($image_file_temp, 'banners/' . $image_new_name); 
       @unlink('banners/'.$data['banner']);
      mysql_query("UPDATE `servers` SET `banner` = '$image_new_name' WHERE `id` = '$sid'");
     }
    
     mysql_query("UPDATE `servers` SET `ip` = '$ip', `port` = '$port', `country` = '$country', `show_port` = '$show_port', `website` = '$website', `youtube_id` = '$youtube_id', `description` = '$description', `category_id` = '$category', `name` = '$name', `votifier_key` = '$votKey', `votifier_ip` = '$votIp', `votifier_port` = '$votPort' WHERE `id` = '$sid'");
     if(empty($_POST) == false) foreach($listofstaff as $staff){
      $s = explode(";", $staff);
      mysql_query("INSERT INTO `servers_staff` (`ID`, `serverID`, `player`, `rank`) VALUES (NULL, '$sid', '$s[0]', '$s[1]')");
    }
    }
    else{
    // staff_members is empty
    }
    }
    Last edited by mlseim; Nov 30th, 2015 at 01:31 PM.


  4. #3
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Hey, thanks for the response. Turns out I forgot a piece, which is causing it to error :P

    <?php
    if(isset($_GET['success']) && empty($_GET['success'])) {
    echo "<font color='green'>The server settings were successfully updated !</font>";
    } else {
    $listofstaff = explode(",",$_POST['staff_members']);
    if(empty($_POST) == false && empty($errors) == true && count($listofstaff)>0) {
    if(empty($_POST['votifier_key'])) $votKey = "false"; else $votKey = htmlspecialchars($_POST['votifier_key'], ENT_QUOTES);
    $votPort = (int)$_POST['votifier_port'];
    $votIp = htmlspecialchars($_POST['votifier_ip'], ENT_QUOTES);
    $ip = $_POST['ip'];
    $port = $_POST['port'];
    $name = htmlspecialchars($_POST['name'], ENT_QUOTES);
    $website = $_POST['website'];
    $show_port = $_POST['show_port'];
    $youtube_id = htmlspecialchars($_POST['youtube_id'], ENT_QUOTES);
    $description = htmlspecialchars($_POST['description'], ENT_QUOTES);
    $category = (isset($_POST['category'])) ? json_encode($_POST['category']) : "null";
    $country = (country_check(0, $_POST['country'])) ? $_POST['country'] : 'US';


    if($image != false) {
    $image_new_name = md5(time().rand()) . '.' . $image_file_extension;
    move_uploaded_file($image_file_temp, 'banners/' . $image_new_name);
    @unlink('banners/'.$data['banner']);
    mysql_query("UPDATE `servers` SET `banner` = '$image_new_name' WHERE `id` = '$sid'");
    }


    mysql_query("UPDATE `servers` SET `ip` = '$ip', `port` = '$port', `country` = '$country', `show_port` = '$show_port', `website` = '$website', `youtube_id` = '$youtube_id', `description` = '$description', `category_id` = '$category', `name` = '$name', `votifier_key` = '$votKey', `votifier_ip` = '$votIp', `votifier_port` = '$votPort' WHERE `id` = '$sid'");
    if(empty($_POST) == false) foreach($listofstaff as $staff){
    $s = explode(";", $staff);
    mysql_query("INSERT INTO `servers_staff` (`ID`, `serverID`, `player`, `rank`) VALUES (NULL, '$sid', '$s[0]', '$s[1]')");
    }
    }
    else{
    // staff_members is empty
    }
    }






    header('Location: my_servers.php?successUpdate');
    } else if (empty($errors) == false) {
    echo output_errors($errors);
    }
    ?>
    Error phpcodechecker gives is:
    Parse error: syntax error, unexpected 'else' (T_ELSE) in your code on line 116
    PHP Syntax Check: Parse error: syntax error, unexpected 'else' (T_ELSE) in your code on line 116
    • } else if (empty($errors) == false) {

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    If you have an error on line 116, there must be more script than you're showing ....

    This is simplified so you can follow it easier ...

    PHP Code:

    <?php
    if(isset($_GET['success']) && empty($_GET['success'])) {
    if (empty(
    $errors) == false) {
    echo 
    output_errors($errors);
    }
    else{
    header('Location: my_servers.php?successUpdate');
    exit;
    }
    }
    $listofstaff explode(",",$_POST['staff_members']);
    if(empty(
    $_POST) == false && empty($errors) == true && count($listofstaff)>0) {
    if(empty(
    $_POST['votifier_key'])) $votKey "false"; else $votKey htmlspecialchars($_POST['votifier_key'], ENT_QUOTES);
    $votPort = (int)$_POST['votifier_port'];
    $votIp htmlspecialchars($_POST['votifier_ip'], ENT_QUOTES);
    $ip $_POST['ip'];
    $port $_POST['port'];
    $name htmlspecialchars($_POST['name'], ENT_QUOTES);
    $website $_POST['website'];
    $show_port $_POST['show_port'];
    $youtube_id htmlspecialchars($_POST['youtube_id'], ENT_QUOTES);
    $description htmlspecialchars($_POST['description'], ENT_QUOTES);
    $category = (isset($_POST['category'])) ? json_encode($_POST['category']) : "null";
    $country = (country_check(0$_POST['country'])) ? $_POST['country'] : 'US';

    if(
    $image != false) {
    $image_new_name md5(time().rand()) . '.' $image_file_extension;
    move_uploaded_file($image_file_temp'banners/' $image_new_name);
    @
    unlink('banners/'.$data['banner']);
    mysql_query("UPDATE `servers` SET `banner` = '$image_new_name' WHERE `id` = '$sid'");
    }

    mysql_query("UPDATE `servers` SET `ip` = '$ip', `port` = '$port', `country` = '$country', `show_port` = '$show_port', `website` = '$website', `youtube_id` = '$youtube_id', `description` = '$description', `category_id` = '$category', `name` = '$name', `votifier_key` = '$votKey', `votifier_ip` = '$votIp', `votifier_port` = '$votPort' WHERE `id` = '$sid'");
    foreach(
    $listofstaff as $staff){
    $s explode(";"$staff);
    mysql_query("INSERT INTO `servers_staff` (`ID`, `serverID`, `player`, `rank`) VALUES (NULL, '$sid', '$s[0]', '$s[1]')");
    // foreach loop 
    }
    else{
    // staff_members is empty
    }


    ?>


  6. #5
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Here's all the information you need.
    Latest error code from what you gave, is:
    Parse error: syntax error, unexpected '}' in /var/www/changeserver1.php on line 223

    Entire page:

    The "}" is the one before footer. If I add a "{" ( or if I remove it from before the footer ) to the end of the syntax you gave me, I get error "Notice: Undefined index: staff_members in /var/www/changeserver1.php on line 88", but the page still renders, whereas with the first error it doesnt.

    <?php
    include 'core/init.php';
    protect_page();
    include 'includes/overall/header.php';


    @$sid = (INT)$_GET['id'];
    $data = mysql_fetch_assoc(mysql_query("SELECT `ip`, `country`, `port`, `show_port` `description`, `youtube_id`, `website`, `name`, `votifier_key`, `votifier_ip`, `votifier_port`, `banner`, `category_id` FROM `servers` WHERE `id` = '$sid' AND `user_id` = '$session_user_id'"));
    if($data == false){
    echo "<h2>This server does not belongs to you !</h2>";
    include 'includes/overall/footer.php';
    die();
    }
    $staff_result = mysql_query("SELECT * FROM `servers_staff` WHERE `serverID` = '$sid'") or die(mysql_error());


    if(empty($_POST) == false) {
    $_POST['name']= htmlspecialchars($_POST['name'], ENT_QUOTES);
    $allowed_extensions = array("jpg", "jpeg", "png", "gif");
    $image = (empty($_FILES['image']['name']) == false) ? true : false;


    if(empty($errors) == true) {


    if(!$image) {

    } else {


    $image_file_name = $_FILES['image']['name'];
    $image_file_extension = explode('.', $image_file_name);
    $image_file_extension = strtolower(end($image_file_extension));
    $image_file_temp = $_FILES['image']['tmp_name'];
    $image_file_size = $_FILES['image']['size'];
    list($image_width, $image_height) = getimagesize($image_file_temp);


    if(in_array($image_file_extension, $allowed_extensions) !== true) {
    $_SESSION['error'][] = "You can only upload JPG, JPEG, PNG and GIF images";
    }
    if($image_width != "468" || $image_height != "60") {
    $errors[] = "Banner is too large or too small, only 468 * 60 accepted. Your image is: " .$image_width." * ".$image_height;
    }
    }


    if(strlen($_POST['name']) > 64){
    $errors[] = "Server name is too long !";
    }
    if(strlen($_POST['name']) < 4){
    $errors[] = "Server name is too short !";
    }
    if(!empty($_POST['website'])){
    if(!filter_var($_POST['website'], FILTER_VALIDATE_URL)){
    $errors[] = "Invalid website url !";
    }
    }
    if(strlen($_POST['youtube_id']) > 25){
    $errors[] = "Youtube ID is too long !";
    }
    if(strlen($_POST['description']) > 2500){
    $errors[] = "Description is too long! Please keep it under 2500 letters !";
    }

    if(isset($_POST['category'])) {
    if(is_array($_POST['category'])){
    foreach($_POST['category'] as $key => $category){
    if(!is_numeric($category)) unset($_POST['category'][$key]);
    }
    if(count($_POST['category']) > $settings['max_categories']){
    $errors[] = "You selected too many categories !";
    }
    if(count($_POST['category']) < 1){
    $errors[] = "You need to select at least 1 category !";
    }
    }
    }

    }
    }


    ?>
    <h2>Server Settings</h2>
    <?php
    if(isset($_GET['success']) && empty($_GET['success'])) {
    if (empty($errors) == false) {
    echo output_errors($errors);
    }
    else{
    header('Location: my_servers.php?successUpdate');
    exit;
    }
    }
    $listofstaff = explode(",",$_POST['staff_members']);
    if(empty($_POST) == false && empty($errors) == true && count($listofstaff)>0) {
    if(empty($_POST['votifier_key'])) $votKey = "false"; else $votKey = htmlspecialchars($_POST['votifier_key'], ENT_QUOTES);
    $votPort = (int)$_POST['votifier_port'];
    $votIp = htmlspecialchars($_POST['votifier_ip'], ENT_QUOTES);
    $ip = $_POST['ip'];
    $port = $_POST['port'];
    $name = htmlspecialchars($_POST['name'], ENT_QUOTES);
    $website = $_POST['website'];
    $show_port = $_POST['show_port'];
    $youtube_id = htmlspecialchars($_POST['youtube_id'], ENT_QUOTES);
    $description = htmlspecialchars($_POST['description'], ENT_QUOTES);
    $category = (isset($_POST['category'])) ? json_encode($_POST['category']) : "null";
    $country = (country_check(0, $_POST['country'])) ? $_POST['country'] : 'US';


    if($image != false) {
    $image_new_name = md5(time().rand()) . '.' . $image_file_extension;
    move_uploaded_file($image_file_temp, 'banners/' . $image_new_name);
    @unlink('banners/'.$data['banner']);
    mysql_query("UPDATE `servers` SET `banner` = '$image_new_name' WHERE `id` = '$sid'");
    }


    mysql_query("UPDATE `servers` SET `ip` = '$ip', `port` = '$port', `country` = '$country', `show_port` = '$show_port', `website` = '$website', `youtube_id` = '$youtube_id', `description` = '$description', `category_id` = '$category', `name` = '$name', `votifier_key` = '$votKey', `votifier_ip` = '$votIp', `votifier_port` = '$votPort' WHERE `id` = '$sid'");
    foreach($listofstaff as $staff){
    $s = explode(";", $staff);
    mysql_query("INSERT INTO `servers_staff` (`ID`, `serverID`, `player`, `rank`) VALUES (NULL, '$sid', '$s[0]', '$s[1]')");
    } // foreach loop
    }
    else{
    // staff_members is empty
    }


    ?>
    <form action="" method="post" role="form" enctype="multipart/form-data">
    <div class="form-group">
    <input type="text" name="ip" value="<?php echo $data['ip']; ?>" class="form-control" />
    </div>

    <div class="form-group">
    <input type="text" name="port" value="<?php echo $data['port']; ?>" class="form-control" />
    </div>


    <div class="form-group">
    <label>Show port? Default is false.</label>
    <input type="hidden" name="show_port" value="no" />
    <input type="checkbox" name="show_port" value="yes" />
    </div>


    <div class="form-group">
    <label>Name*</label>
    <input type="text" name="name" value="<?php echo $data['name']; ?>" class="form-control" />
    </div>

    <div class="form-group">
    <label>Website</label>
    <input type="text" name="website" value="<?php echo $data['website']; ?>" class="form-control" />
    </div>

    <div class="form-group">
    <label>Youtube Video ID</label>
    <input type="text" name="youtube_id" value="<?php echo $data['youtube_id']; ?>" placeholder="Ex: xHRkHFxD-xY" class="form-control" />
    </div>

    <div class="form-group">
    <label>Upload Banner*</label><br />
    <p class="help-block">JPG, JPEG or GIF - 468 x 60</p>
    <input type="file" name="image" class="form-control" />
    </div>


    <div class="form-group">
    <label>Country</label>
    <select name="country" class="form-control">
    <?php country_check(1, $data['country']); ?>
    </select>
    </div>

    <div class="form-group">
    <label>Votifier Key</label>
    <input type="text" name="votifier_key" class="form-control" value="<?php echo $data['votifier_key']; ?>" />
    </div>

    <div class="form-group">
    <label>Votifier Ip</label>
    <span class="help-block">Leave empty if you don't want to use a custom votifier IP</span>
    <input type="text" name="votifier_ip" value="<?php echo $data['votifier_ip']; ?>" class="form-control" />
    </div>

    <div class="form-group">
    <label>Votifier Port</label>
    <input type="text" name="votifier_port" value="<?php echo $data['votifier_port']; ?>" class="form-control" />
    </div>

    <div class="form-group">
    <label>Category*</label>
    <p class="muted">You can select up to <?php echo $settings['max_categories']; ?> categories</p>
    <?php
    $result = mysql_query("SELECT * FROM `categories`");
    $data = ($data['category_id'] !== "null") ? json_decode($data['category_id']) : array();
    while($row = mysql_fetch_array($result)){
    if(in_array($row['category_id'], $data)){
    echo "<input type='checkbox' name='category[]' value='" . $row['category_id'] . "' checked>" . $row['name'] . "<br />";
    } else {
    echo "<input type='checkbox' name='category[]' value='" . $row['category_id'] . "'>" . $row['name'] . "<br />";
    }
    }
    ?>
    </div>
    <?php $description = mysql_fetch_assoc(mysql_query("SELECT `description` FROM `servers` WHERE `id` = '$sid' AND `user_id` = '$session_user_id'"));
    ?><div class="form-group">
    <label>Description</label>
    <p class="muted">Write an <b>awesome</b> description to attract visitors!</p>
    <textarea name="description" class="form-control"><?php echo $description['description']; ?></textarea>
    </div>

    <div class="form-group">
    <label>Staff Members</label>
    <ul>
    <?php
    //Show current staff
    while($row = mysql_fetch_array($staff_result, MYSQL_ASSOC)){
    echo'<li>' . $row['player'] . '</li>';
    }
    ?>
    </ul>
    <label>Add staff members</label>
    <label>Usage: Seperate staff with , </label><br>
    <label>To give them a rank do (playername);(rank)</label>
    <input type="text" name="staff_members" value placeholder="Note: Contact technical support to remove a staff member" class="form-control" />
    </div>
    <br />
    <input class="btn btn-default" type="submit" value="Submit" />
    </form>

    <?php
    }
    include 'includes/overall/footer.php';
    ?>

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    The index "notice" is a notice, not an error. It's good that you don't suppress notices, but many people do.

    To fix that, find this line:

    $listofstaff = explode(",",$_POST['staff_members']);

    Change to:

    if($_POST['staff_members']){
    $listofstaff = explode(",",$_POST['staff_members']);
    }


    The other problems have to do with mis-matched or unclosed brackets { }

    Take this section ....


    if(empty($errors) == true) {

    if(!$image) {

    } else {


    Seems like things missing for the if !image statement ... it does nothing, and then there is an else statement.

    You should use Notepad++ to edit your script. That text editor highlights opening and closing tags, parenthesis, brackets, etc.

    https://notepad-plus-plus.org/


  8. #7
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Awesome! Works great! Thanks so much!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:39 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com