Namers

PHP script help! Page continuosly "uploading"

Namecheap
Impact
66,132
Hey there, hopefully someone can help me with this problem!
Here is the situation.. bought a "affiliate script" from a site and have for the last few days been trying to add content (link, images and text) to this script from a "add listing" part of the website. I follow the instructions and "fill in" where I am supposed to fill in, I click on "Add This Product" and a "red circle with upload" appears and doesn't upload at all.. no matter what browser I use..


Screenshot
mfng.png


Not sure if this is the right coding (was told it is a "call to action" script.. Header.php
PHP:
<?php include("db.php");
 
if($squ = $mysqli->query("SELECT * FROM settings WHERE id='1'")){
 
    $settings = mysqli_fetch_array($squ);
 
    $squ->close();
}else{
     printf("Error: %s\n", $mysqli->error);
}
 
$urlTitle = parse_url($_SERVER['REQUEST_URI']);
 
$pageName = $urlTitle['path'];
if($pageName == '/about_us.html'){
 $pageTitle = 'About Us | ';
} else if($pageName ==  '/contactus.html'){
 $pageTitle = 'Contact Us | ';
} else if($pageName ==  '/privacy_policy.html'){
 $pageTitle = 'Privacy Policy | ';
} else if($pageName ==  '/tos.html'){
 $pageTitle = 'Terms of Use | ';
} else if($pageName ==  '/feeds.html'){
 $pageTitle = 'RSS Feeds | ';  
} else {
 $pageTitle = '';
}
 
//Tot Site Views
 $SiteHits = $settings['site_hits'];
 $SiteHits = $SiteHits + 1;
 $mysqli->query("UPDATE settings SET site_hits='$SiteHits' WHERE id='1'") or die(mysqli_error());
 
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $pageTitle;?><?php echo $settings['name']; ?></title>
<meta name="description" content="<?php echo $settings['descrp']; ?>" />
<meta name="keywords" content="<?php echo $settings['keywords']; ?>" />
 
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
 
<link href="templates/<?php echo $settings['template'];?>/css/style.css" rel="stylesheet" type="text/css">
 
<script src="js/jquery.min.js"></script>
 
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "ur-de6b7a4a-e967-4778-5476-54ab547cb1bb", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>
 
</head>
 
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<header>
<div class="top-bar">
<div class="tb-center">
<div class="tb-left">Welcome to <?php echo $settings['name'];?>!!</div>
<div class="tb-right"><a href="about_us.html" class="ht-links" target="_self">About Us</a> | <a href="privacy_policy.html" class="ht-links" target="_self">Privacy Policy</a> | <a href="tos.html" class="ht-links" target="_self">Terms of Use</a> | <a href="contactus.html" class="ht-links" target="_self">Contact Us</a></div>
</div><!--tb-center-->
</div><!--top-bar-->
<div class="h-content">
 
<div class="h-data">
<div class="logo"><a href="index.html"><img src="images/logo.png" width="264" height="49" alt="<?php echo $settings['name'];?>" longdesc="index.html"></a></div>
<div class="social-icons"> <a href="<?php echo $settings['fbpage'];?>" target="_blank"><img src="templates/<?php echo $settings['template'];?>/images/fb.png" width="32" height="32" alt="facebook"></a>
<a href="<?php echo $settings['twitter'];?>" target="_blank"><img src="templates/<?php echo $settings['template'];?>/images/twitter.png" width="32" height="32" alt="twitter"></a> 
<a href="<?php echo $settings['pinterest'];?>" target="_blank"><img src="templates/<?php echo $settings['template'];?>/images/pinterest.png" width="32" height="32" alt="pinterest"></a> 
<a href="<?php echo $settings['google_plus'];?>" target="_blank"><img src="templates/<?php echo $settings['template'];?>/images/googleplus.png" width="32" height="32" alt="google plus"></a> 
<a href="rss_feeds.html"><img src="templates/<?php echo $settings['template'];?>/images/rss.png" width="32" height="32" alt="rss feeds"></a> 
</div><!--social-icons-->
</div><!--h-data-->
</div><!--h-content-->
 
<div id="menu-bar">
<nav id='menu'>
<ul>
   <li><a href='index.html'><span>Home</span></a></li>
<?php
if($MenuSql = $mysqli->query("SELECT * FROM categories ORDER BY cname ASC")){
 
    while ($MenuRow = mysqli_fetch_array($MenuSql)){
  $MurlRow = $MenuRow['cname'];
  $Murl = preg_replace("![^a-z0-9]+!i", "-", $MurlRow);
  $Murl = strtolower($Murl);
 
?>    
   <li><a href='cat-<?php echo $MenuRow['id'];?>-<?php echo $Murl;?>-newest.html'><span><?php echo $MenuRow['cname'];?></span></a></li>
<?php     
 }
$MenuSql->close();
}else{
     printf("Error: %s\n", $mysqli->error);
}
?>
</ul>
</nav>
</div><!--menu-bar-->
</header>

Not sure what else is needed...and did contact support.."their 24 to 48 hours" response time is not the truth!
 
1. open "Developer Tools" from browser menu
2. In the lower window click Net tab
3. Fill out the form, click "Add this product"
4. Watch for any Post request showing up in Net tab. If there's any click on the row, click Response headers. In case there's no response from the server, the poblem is on the server side - you'll need to deal with php or call support
5. If no Post request occurs on Net tab after you click "Add .." open Console tab, look for any js errors. If there are any, post it here

*
 
Impact
66,132
Thanks _ and 4pm

[Sat Sep 14 17:09:36 2013] [error] [client 50.66.60.42] File does not exist: /home/briguy/public_html/404.shtml, referer: http://www.bargainbuys.info/admincp/css/style.css
Error log file
error_log
File Type: ASCII text
[09-Sep-2013 20:46:22 America/Chicago] PHP Warning: mysqli::connect() [<a href='mysqli.connect'>mysqli.connect</a>]: (28000/1045): Access denied for user 'briguy__briguy'@'localhost' (using password: YES) in /home/briguy/public_html/db.php on line 3
[09-Sep-2013 20:46:23 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 3
[09-Sep-2013 20:46:23 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:46:23 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:46:26 America/Chicago] PHP Warning: mysqli::connect() [<a href='mysqli.connect'>mysqli.connect</a>]: (28000/1045): Access denied for user 'briguy__briguy'@'localhost' (using password: YES) in /home/briguy/public_html/db.php on line 3
[09-Sep-2013 20:46:26 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 3
[09-Sep-2013 20:46:26 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:46:26 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:47:46 America/Chicago] PHP Warning: mysqli::connect() [<a href='mysqli.connect'>mysqli.connect</a>]: (28000/1045): Access denied for user 'briguy__briguy'@'localhost' (using password: YES) in /home/briguy/public_html/db.php on line 3
[09-Sep-2013 20:47:46 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 3
[09-Sep-2013 20:47:46 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:47:46 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:47:47 America/Chicago] PHP Warning: mysqli::connect() [<a href='mysqli.connect'>mysqli.connect</a>]: (28000/1045): Access denied for user 'briguy__briguy'@'localhost' (using password: YES) in /home/briguy/public_html/db.php on line 3
[09-Sep-2013 20:47:47 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 3
[09-Sep-2013 20:47:47 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:47:47 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:48:05 America/Chicago] PHP Warning: mysqli::connect() [<a href='mysqli.connect'>mysqli.connect</a>]: (28000/1045): Access denied for user 'briguy__briguy'@'localhost' (using password: YES) in /home/briguy/public_html/db.php on line 3
[09-Sep-2013 20:48:05 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 3
[09-Sep-2013 20:48:05 America/Chicago] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: invalid object or resource mysqli
in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:48:05 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:49:01 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:49:02 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
[09-Sep-2013 20:49:05 America/Chicago] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/briguy/public_html/header.php on line 32
 
Last edited:
[Sat Sep 14 17:09:36 2013] [error] [client 50.66.60.42] File does not exist: /home/briguy/public_html/404.shtml, referer: http://www.bargainbuys.info/admincp/css/style.css

that tells you dont have 404.shtml in your /public_html, but it is probably only used for 404 responses. so it looks like POST is getting nowhere.. probably wrong url param or you're missing callback php file that should process post form requests

Can you post POST URL and POST Headers - all should be on Net tab


*
 
Impact
66,132
Can you post POST URL and POST Headers - all should be on Net tab


*
working on that now... just updated previous posting of mine.. not sure what it means but hoping it is of help..


from Developer tools
fsb7.png

ajax-loader.gif has the "revolving circle"
 
Last edited:
working on that now... just updated previous posting of mine.. not sure what it means but hoping it is of help..

no need for researching POST headers - your updated log says your DB connection is not configured properly - "Access denied"
If you have PHPMyAdmin installed open it and check your DB privileges. Username/pass should be the same as in your PHP config. I suspect you didnt config your script to include correct DB credentials




added: i was wrong about POST headers - in addition to DB problem you also got 403 Access denied when trying to call submit_listing.php
you need to check file permissions for /admincp dir and everything in there. All php files there need to be executable by web server. You should check under what user your server runs and then do chown/chmod


*
 
Last edited:
Impact
66,132
no need for researching POST headers - your updated log says your DB connection is not configured properly - "Access denied"
If you have PHPMyAdmin installed open it and check your DB privileges. Username/pass should be the same as in your PHP config. I suspect you didnt config your script to include correct DB credentials




added: i was wrong about POST headers - in addition to DB problem you also got 403 Access denied when trying to call submit_listing.php
you need to check file permissions for /admincp dir and everything in there. All php files there need to be executable by web server. You should check under what user your server runs and then do chown/chmod


*
Went to "MySQL Account Maintenance" and "Checked"
agoa.png
 
Went to "MySQL Account Maintenance" and "Checked"

have you inserted your DB (mysql) username/pass into php config file when you were installing the script? or may be there is web interface with a form for configuring your php script?

simply put your script needs to know (from config) how to connect to your database i.e. your username and pass

from your screenshot it looks like that the script is using briguy__briguy username while DB has briguy_bri
 
NOT a database problem


there are 2 problems:

1. db connection

PHP Warning: mysqli::connect() [<a href='mysqli.connect'>mysqli.connect</a>]: (28000/1045): Access denied for user 'briguy__briguy'@'localhost' (using password: YES) in /home/briguy/public_html/db.php on line 3

it looks like CP prepending usernames and possibly DB name with <CP_username> plus "_"

Try to remove "briguy_" in db.php where DB connection is configured:
change "briguy_bruguy" to simply "briguy", repeat for DB name


2. file permissions in /admincp

before CHMOD 755 you need to make sure webserver is the owner of the files or in group, then do:

CHOWN <server user>:<server user> -R /admincp
CHMOD 755 -R /admincp


*
 
Impact
66,132
I tried all the suggestions and still not working but did figured out that when I add the "Affiliate URL" that when the problems starts

Screenshot
mfng.png


Not sure if the following are the right coding but not sure
PHP:
add_items.php 
File Type: PHP script text 
<?php include("header.php");?>
<div class="maintitle">Add New Listing</div>

<script>
$(document).ready(function()
{
    $('#FileUploader').on('submit', function(e)
    {
        e.preventDefault();
        $('#submit').attr('disabled', ''); // disable upload button
        //show uploading message
        $("#loadding").html('<div class="loader"><img src="http://www.namepros.com/images/ajax-loader.gif" alt="Please Wait"/> <br/><span>Uploading...</span></div>');
        $(this).ajaxSubmit({
        target: '#output',
        success:  afterSuccess //call function after success
        });
    });
});
 
function afterSuccess()
{
    //$('#FileUploader').resetForm();  // reset form
    $('#submit').removeAttr('disabled'); //enable submit button
    $('#loadding').html('');
}
</script>

<div id="loadding"></div>
<div id="output"></div>

<div class="box">
<div class="inbox">
<form action="submit_listing.php" id="FileUploader" enctype="multipart/form-data" method="post">

<label class="artlbl" for="cat">Category:</label>
<div class="formdiv">
<select name="category" id="category">
<option value="">Select a Category</option>
<?php
if($CatSql = $mysqli->query("SELECT * FROM categories ORDER BY cname ASC")){

    while ($CatRow = mysqli_fetch_array($CatSql)){
		
?>   
	<option value="<?php echo $CatRow['id'];?>"><?php echo $CatRow['cname'];?></option>
<?php     
	}
$CatSql->close();
}else{
     printf("Error: %s\n", $mysqli->error);
}
?>
</select>
</div>
<div class="clear"></div>

<label class="artlbl" for="title">Title:</label>
<div class="formdiv"><input  name="mName" id="mName" class="biginput" type="text" value=""/></div>


<label class="artlbl" for="aff">Affiliate URL:</label>
<div class="formdiv"><input  name="aff" id="aff" class="biginput" type="text" value=""/></div>

<label class="artlbl">Description</label>
<div class="formdiv">
<textarea name="disc" id="disc" cols=40 rows=5 ></textarea>
</div>

<label class="artlbl">Listing Image</label>
<div class="formdiv">
<input type='file' class="file" name="mFile" id="mFile"/>
</div>

<div class="clear"></div>

<label class="artlbl" for="price">Price (Without $ sign):</label>
<div class="formdiv"><input  name="price" id="price" class="biginput" type="text" value=""/></div>

<div class="formdiv">
<div class="sbutton"><input type="submit" id="submit" value="Add This Product"/></div>
</div>
</form>	
</div>
</div>
<?php include("footer.php");?>

second coding?

PHP:
 submit_listing.php 
File Type: PHP script text 
<?php
include('../db.php');

$UploadDirectory	= '../uploaded_images/';
 

if ([email protected]_exists($UploadDirectory)) {
	//destination folder does not exist
	die("Make sure Upload directory exist!");
}

if($_POST)
{		
		if(!isset($_POST['category']) || strlen($_POST['category'])<1)
	{
		//required variables are empty
		die('<div class="errormsgbox">Please select a category.</div>');
	}
	
	if(!isset($_POST['mName']) || strlen($_POST['mName'])<1)
	{
		//required variables are empty
		die('<div class="errormsgbox">Please add a title.</div>');
	}
	
	if(!isset($_POST['aff']) || strlen($_POST['aff'])<1)
	{
		//required variables are empty
		die('<div class="errormsgbox">Please add your affiliate URL.</div>');
	}
	
	if(!isset($_POST['disc']) || strlen($_POST['disc'])<1)
	{
		//required variables are empty
		die('<div class="errormsgbox">Please add a small description.</div>');
	}
	
		
	if(!isset($_FILES['mFile']))
	{
		//required variables are empty
		die('<div class="errormsgbox">Please add a image</div>');
	}
	
	if(!isset($_POST['price']) || strlen($_POST['price'])<1)
	{
		//required variables are empty
		die('<div class="errormsgbox">Please add price.</div>');
	}
	
	if($_FILES['mFile']['error'])
	{
		//File upload error encountered
		die(upload_errors($_FILES['mFile']['error']));
	}

	$FileName			= strtolower($_FILES['mFile']['name']); //uploaded file name
	$ImageExt			= substr($FileName, strrpos($FileName, '.')); //file extension
	$Active             = 1;//File active
	$FileType			= $_FILES['mFile']['type']; //file type
	$FileSize			= $_FILES['mFile']["size"]; //file size
	$RandNumber   		= rand(0, 9999999999); //Random number to make each filename unique.
	$Date		        = date("F j, Y");
	
	$FileTitle			= $mysqli->escape_string($_POST['mName']); // file title
	$Category           = $mysqli->escape_string($_POST['category']); // category 
	$AffURL             = $mysqli->escape_string($_POST['aff']); // afflite url
	$Description        = $mysqli->escape_string($_POST['disc']); // description
	$Price              = $mysqli->escape_string($_POST['price']); // price
	
	
		switch(strtolower($FileType))
	{
		//allowed file types
		case 'image/png': //png file
		case 'image/gif': //gif file 
		case 'image/jpeg': //jpeg file
		case 'image/bmp': //bmp file
			break;
		default:
			die('Unsupported Image File!'); //output error
	}

  
	//Image File Title will be used as new File name
	$NewFileName = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), strtolower($FileTitle));
	$NewFileName = $NewFileName.'_'.$RandNumber.$ImageExt;

 //Rename and save uploded image file to destination folder.
   if(move_uploaded_file($_FILES['mFile']["tmp_name"], $UploadDirectory . $NewFileName ))
   {
	
		
// Insert info into database table.. do w.e!
		$mysqli->query("INSERT INTO listings(title, aff_url, discription, price, image, catid, date, active) VALUES ('$FileTitle', '$AffURL','$Description','$Price','$NewFileName','$Category','$Date','$Active')");
		
		die('<div class="infomsgbox">New listing added successfully.</div>');
		
   
   }else{
   		die('<div class="errormsgbox">There seems to be a problem. please try again.</div>');
   } 
}

function upload_errors($err_code) {
	switch ($err_code) { 
        case UPLOAD_ERR_INI_SIZE: 
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 
        case UPLOAD_ERR_FORM_SIZE: 
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 
        case UPLOAD_ERR_PARTIAL: 
            return 'The uploaded file was only partially uploaded'; 
        case UPLOAD_ERR_NO_FILE: 
            return 'No file was uploaded'; 
        case UPLOAD_ERR_NO_TMP_DIR: 
            return 'Missing a temporary folder'; 
        case UPLOAD_ERR_CANT_WRITE: 
            return 'Failed to write file to disk'; 
        case UPLOAD_ERR_EXTENSION: 
            return 'File upload stopped by extension'; 
        default: 
            return 'Unknown upload error'; 
    } 
} 
?>
Thanks again for your time
 
Name Worth
Top Bottom