mbhanley 0 Light Poster

Hi, I am having an issue, any suggestions will be great.
I am trying to fetch records from 3 tables on conditions to retrieve the correct data.
So far it brings up 2 of the same results as there are two image file names with the same product id's in the table row.
I want to limit that row to just show 1 but if I do that it removes all other records from being displayed.

$sql = "SELECT p.p_id, p.p_active, p.p_sku, p.p_slug, p.p_title, p.p_desc, p.p_price, p.p_qty, p.p_instock, i.p_img_id, i.p_img,i.p_img_thumb, i.p_id, c.c_id, c.c_title, c.c_slug 
FROM products AS p 
INNER JOIN categories AS c ON p.p_catid = c.c_id 
INNER JOIN product_img AS i ON  p.p_id=i.p_id 
WHERE p.p_catid='$c_id' AND p.p_active='1' ORDER BY p.p_id DESC";
mbhanley 0 Light Poster

It should work if your php code translates the urls;

from; articles.php?a_id=12322

To; articles/article_title

Are you using a cms like WordPress or a forum like phpBB or is it writen in PHP by yourself?

What happens if you try this;

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^articles/([A-Za-z0-9-]+)$ articles.php?a_id=$1 [QSA,L]
RewriteRule ^articles/([A_Za_z0_9_]+)$ articles.php?a_id=$1 [QSA,L]
RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]

or this;

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^articles/(.*)$ articles.php?a_id=$1 [QSA,L]
#RewriteRule ^articles/([A_Za_z0_9_]+)$ articles.php?a_id=$1 [QSA,L]
RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]
mbhanley 0 Light Poster

Ok try this;

    RewriteEngine On
    Options +Indexes
    Options +FollowSymlinks
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -d [NC]
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^articles/([A-Za-z0-9-]+)$ articles.php?a_id=$1 [L]
    RewriteRule ^articles/([A-Za-z0-9-]+)/$ articles.php?a_id=$1 [L]
    RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]

And then try typing the url manualy;

site.com/articles/article_title

Or Article id;

site.com/articles/2322

And let me know what the outcome is.

mbhanley 0 Light Poster

Also in some cases you may need to define the; RewriteBase /

RewriteEngine On
Options +Indexes
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^articles/([A-Za-z0-9-]+)$ articles.php?a_id=$1 [L]
RewriteRule ^articles/([A-Za-z0-9-]+)/$ articles.php?a_id=$1 [L]
RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]
mbhanley 0 Light Poster

Also try putting the string above; RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^articles/([A-Za-z0-9-]+)$ articles.php?a_id=$1 [L]
RewriteRule ^articles/([A-Za-z0-9-]+)/$ articles.php?a_id=$1 [L]
RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]
mbhanley 0 Light Poster

If you clicked the link and it took you to a dynamic url such as: site.com/articles.php?a_id=1231

This means you need to make PHP translate your dynamic links.

Test this by typing in the url address bar: site.com/articles/1231

Or by typing: site.com/articles/article_title_by_id

mbhanley 0 Light Poster

If your dynamic url is:
site.com/articles.php?id=1232

I believe this should be correct;

The whole string would be:

RewriteRule ^articles/([A-Za-z0-9-]+)$ articles.php?id=$1 [L]
RewriteRule ^articles/([A-Za-z0-9-]+)/$ articles.php?id=$1 [L]

This part of the url is handled and translated in PHP.

site.com/articles/here_is_todays_article

mbhanley 0 Light Poster

Thanks LastMitch, Notices are gone :)

mbhanley 0 Light Poster

I am trying to figure out why I am getting this error notice, Does anyone have an idea as to why this is
happening.

Notice: Undefined offset: 5

on line: if ($tree[$i]['level'] < $tree[$i+1]['level']) {
on line: } elseif ($tree[$i]['level'] == $tree[$i+1]['level']) {
on line: $diff = $tree[$i]['level'] - $tree[$i+1]['level'];

public function treeAsHtml() {
        $tree = $this->getTree();
        $html = "<ul>\n";
        for ($i=0; $i<count($tree); $i++) {
            $html .= "<li>" . $tree[$i][$this->name];
            if ($tree[$i]['level'] < $tree[$i+1]['level']) {
                $html .= "\n<ul>\n";
            } elseif ($tree[$i]['level'] == $tree[$i+1]['level']) {
                $html .= "</li>\n";
            } else {
                $diff = $tree[$i]['level'] - $tree[$i+1]['level'];
                $html .= str_repeat("</li>\n</ul>\n", $diff) . "</li>\n";
            }
        }
        $html .= "</ul>\n";
        return $html;
    }
mbhanley 0 Light Poster

Thanks LastMitch, I know what I am trying to acheive is very complicated but
if I didn't at least try to understand Jquery and Nested sets I would not
understand programing at all to this day.

I do find Jquery a little complicated but I always work out how to do what I want eventualy.

I am reading up on Nested sets and storing hierarchical data at the moment if I manage
to sus it all out I will make an example of how to do this and post it on my blog for
others.

mbhanley 0 Light Poster

I am trying to configure a menu for my CMS I want to be able to use Nested Sortables just like you have
in WordPress.

The problem Im having is getting my head around how I am going to start I already have a column
in my database table called page_order and that is sorted in order using Jquery ui sortable, but
If I want to use a multiple dropdown menu how would I sort this in the database table would I
need two table columns i.e. menu_cat & menu_item and once the data is posted with jquery how would
I store that in the correct order.

Im just stuck with the logic on how I am going to do this if anyone has any suggestions I'm all ears.

I want to use the following nested sortable plugin,

http://mjsarfatti.com/sandbox/nestedSortable/

https://code.google.com/p/nestedsortables/wiki/NestedSortableDocumentation

mbhanley 0 Light Poster

At last I have figured it out I was making things more complicated than they needed to be
the following query worked;

$mysqli->query("INSERT INTO cms_homecontent_versions (page_order, page, title, body, timestamp) SELECT page_order, page, title, body, timestamp FROM cms_homecontent");

So now if I run the following queries:

$mysqli->query("begin");
$mysqli->query("INSERT INTO cms_homecontent_versions (page_order, page, title, body, timestamp) 
SELECT page_order, page, title, body, timestamp FROM cms_homecontent");
$mysqli->query("UPDATE cms_homecontent SET page_order = '$pageorder', page = '$page', title = '$title', body = '$body', timestamp = NOW() WHERE id ='$id';");
if (mysqli_error($mysqli)) {
$mysqli->query("rollback");
}
else {
$mysqli->query("commit"); 
}

it moves the original table data to the new table
and then continues to update the original table sweet :)

Thanks LastMitch your a diamond.

mbhanley 0 Light Poster

I couldn't see it on the website.

Its more like;

INSERT INTO table1 (f1, f2, f3)
SELECT 'a', 'b', field FROM table2 WHERE id = 1;

But nothing I try seems to work :/

mbhanley 0 Light Poster

I have updated most of the file and everything except this query works.

$mysqli->query("INSERT INTO cms_homecontent_versions(id, page_order, page, title, body, timestamp) 
VALUES(null, '".$old_page_order."', '".$old_page."', '".$old_title."', '".$old_body."', NOW()) SELECT * FROM cms_homecontent WHERE id='".$id."';");

I used:

echo $mysqli->error;

To display the error and it returns.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM cms_homecontent WHERE id='1'' at line 2

I also have echo $old_page_order; etc to see if all variables are indeed being sent and they are so I think its the query its self more than anything.

I can use:

INSERT INTO cms_homecontent_versions SELECT * FROM cms_homecontent WHERE id='$id';

And it will work except what I am trying to prevent is the error of having a duplicate id entry and so hence why I need to use Insert INTO VALUES

mbhanley 0 Light Poster

I had a similar problem but it was due to something like not adding: ifisset

 $user = if(isset($_POST['username']))
 $pass = if(isset($_POST['password']))

have you tried turning on all errors to see what may be causing the problem.

error_reporting(E_ALL);

mbhanley 0 Light Poster

I made some changes as suggested just starting to understand and get the hang of mysqli
but I still must be missing something as the transaction still does not complete it
exicutes the update query but not the first insert query I must be missing something :/

function update_homecontent($p) {
$id = mysql_real_escape_string($p['id']);
$pageorder = mysql_real_escape_string($p['page_order']);
$page = mysql_real_escape_string($p['page']);
$title = mysql_real_escape_string($p['title']);
$body = mysql_real_escape_string($p['body']);
if(!$title || !$body):
if(!$title):
echo '<div class="bad">The title is required!</div>';
endif;

if(!$body):
echo '<div class="bad">The body is required!</div>';
endif;

echo '<p><a href="update-home-content.php?id=' . $id . '">Try Again</a></p>';

else:


$id = mysql_real_escape_string($id);
include './inc/connect.inc.php';
$query = "SELECT * FROM cms_homecontent WHERE id='$id'";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
$old_id= $row['id'];
$old_page_order= $row['page_order'];
$old_page= $row['page'];
$old_title= $row['title'];
$old_body= $row['body'];
//
$mysqli->query("begin");
$mysqli->query("INSERT INTO cms_homecontent_versions(id, page_order, page, title, body, timestamp) 
VALUES(null, '$old_page_order', '$old_page', '$old_title', '$old_body', NOW()) SELECT * FROM cms_homecontent WHERE id='$id';");
$mysqli->query("UPDATE cms_homecontent SET page_order = '$pageorder', page = '$page', title = '$title', body = '$body', timestamp = NOW() WHERE id ='$id';");
if (mysql_error()) {
$mysqli->query("rollback");
}
else {
$mysqli->query("commit"); 
}
}
$result->free();
}
$mysqli->close();

echo "<div class='good'>Content Updated Successfully</div>";

endif;
}
mbhanley 0 Light Poster

Thanks for that Im looking through the manual now,

I am working on a CMS that I have built from scratch it has some awesome features already.

I included features like a url rewrite and also opens the main files in editarea so that the main temlpate can be hardcoded.

I have also made a trash table so that if any page is deleted it can be recovered from the trash hence the reason I want to be able to get old saved versions so that changes made can be reverted when anyone updates a page.

Just having a problem getting the insert and update to work wright it updates but skips the insert part :/

mbhanley 0 Light Poster

Does anyone know a better way of getting this code to execute the mysql queries.

I am trying to Insert table records to a new table then update it.

so I need to call the table cms_homecontent first then insert those values to the new table cms_homecontent_versions and also ignore the id so that it is null and it can auto increment.

Then once that has completed continue updating cms_homecontent table with the data that was submitted.

Any help would be greatly appreciated.

function update_homecontent($p) {
$id = mysql_real_escape_string($p['id']);
$pageorder = mysql_real_escape_string($p['page_order']);
$page = mysql_real_escape_string($p['page']);
$title = mysql_real_escape_string($p['title']);
$body = mysql_real_escape_string($p['body']);
if(!$title || !$body):
if(!$title):
echo '<div class="bad">The title is required!</div>';
endif;

if(!$body):
echo '<div class="bad">The body is required!</div>';
endif;

echo '<p><a href="update-home-content.php?id=' . $id . '">Try Again</a></p>';

else:

$sql=("SELECT * FROM cms_homecontent WHERE id = '$id'");
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) != 0):
while($row = mysql_fetch_assoc($res)) {
$old_id= $row['id'];
$old_page_order= $row['page_order'];
$old_page= $row['page'];
$old_title= $row['title'];
$old_body= $row['body'];

$id = mysql_real_escape_string($id);

$sql .= (mysql_query("begin"));
$sql .= (mysql_query("INSERT INTO cms_homecontent_versions(id, page_order, page, title, body, timestamp) 
VALUES(null, '$old_page_order', '$old_page', '$old_title', '$old_body', NOW()) SELECT * FROM cms_homecontent WHERE id='$id';"));
$sql .= (mysql_query("UPDATE cms_homecontent SET page_order = '$pageorder', page = '$page', title = '$title', body = '$body', timestamp = NOW() WHERE id ='$id';"));
if (mysql_error()) {
$sql = (mysql_query("rollback"));
}
else {
$sql = (mysql_query("commit")); 
}

echo "<div class='good'>Content Updated Successfully</div>";
}
endif;
endif;
}
mbhanley 0 Light Poster

The code I have so far submits to add a domian name to the cart which is on another page.

The problem is I am using Smarty Template and when the page I want the php code to update will not update unless I refresh the page.

And I cannot use ajax to request the page because I tried that and the php code did not run I just got a load of code that the Smarty template could not translate.

This bit of code gets an array from a session and echos the domain names added to cart.

{php} 
for ($i=0; $i<=10; $i++) {
$doms  = $_SESSION['cart']['domains'][$i]['domain'];
echo $doms, "<br />";
}
{/php} 

This code submits a domain name to add to the cart.

{literal}
<script type="text/javascript"> 
$(function(){
    $("#domainorder").submit(function(e){    
       e.preventDefault();
        $.post("cart.php?a=add&domain=register", $("#domainorder").serialize(),
        function(data){}, "json");  
                                }); 
                                return false;
    });
$(document).ajaxStop(function(){
    window.location.reload();
});
</script>
{/literal}

Once the above code runns it does the job but refreshes the page, idealy I need to not refresh the page but just the php code above all on the same page so it updates the domain names that are in the cart.

mbhanley 0 Light Poster

Hi all I am stuck trying to figure out the best way to get data as at the moment I have tried a few different ways to achieve this with no luck.

What I am trying to do is update a block of php code that is in my sidebar when I submit a button.

I have tried loading a file with ajax but because I am using the smarty template it loads the file but the
php code does not run.

I have managed to get it to work to a certain point but it has to refresh the page which is not what I am after
as firefox post a pop up alert saying the page needs reloading and also it resets the page that had previous data already loaded.

Does anyone know a better way to acheive this.

mbhanley 0 Light Poster

Thanks Solo7 managed to get it working with this

$input = ($_FILES['file']['name']);
$patterns = array(); 
$patterns[0] = '/ /';
$patterns[1] = '/.flv/';
$patterns[2] = '/.mp4/';
$patterns[3] = '/.mov/';
$patterns[4] = '/.avi/';
$replacements = array(); 
$replacements[0] = '-';
$replacements[1] = '';
$replacements[2] = '';
$replacements[3] = '';
$replacements[4] = '';
$new_input = preg_replace($patterns, $replacements, $input);

$video_out = "" . $new_input . "-NEW.mp4";

Now I just got the small problem of getting ffmpeg to run but I should be able to get that sorted :)

mbhanley 0 Light Poster

Need help with code i am trying to acheive upload of videos but when they are uploaded the file names
need to be changed to have hyphens in replace of white space and still keep the exstensions.
its proving difficult because once uploaded ffmpeg needs to read the output as the new file name so it can be
placed into the database and echo'ed out later :)

Ive searched about and tried for hours now i just need a little guidance as my brain is turning to mush at the min.

<?php

if ($_POST) {
$folder = "../videos/";
$redirect = "http://www.url.com/admin/imitv.php?success"; 
$title = $_POST['title']; 
$description = $_POST['description']; 
$video_cat_id = $_POST['video_cat_id']; 
move_uploaded_file($_FILES["imagefile"]["tmp_name"], "$folder" . $_FILES["imagefile"]["name"]);
$imagefile = $_FILES['imagefile']['name'];
//VIDEO
move_uploaded_file($_FILES["file"]["tmp_name"], "$folder" . $_FILES["file"]["name"]);
$input = ("$folder" . $_FILES['file']['name']);
$new_input = pathinfo("$folder" . $_FILES['file']['name']);
$new_input=preg_replace('/[^A-Za-z0-9-]+/', '-', $new_input);
$new_video = trim($new_input); 
$output = ("$folder" .$new_video."NEW.mp4");
//rename('../videos/'.$_FILES['file']['name'], '../videos/'.$new_video.'NEW.mp4'); 

echo "Converting $input to $output<br />";
//$command = "ffmpeg -i $video_name -ab 106kb -b 2109kb -s hd720 -ar 44100 -r 29.96 $output";
$command = "ffmpeg -i $input $output";

echo "$command<br />";
echo shell_exec( $command );
echo "Converted<br />";


$con = mysql_connect("localhost","user","pass");
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db("database", $con);
$sql="INSERT INTO table VALUES ('null', '$title', '$description', '$output', '$imagefile', '$video_cat_id')";
if (!mysql_query($sql,$con)){die('Error: ' . mysql_error());}
mysql_close($con);
header('Location: '.$redirect); die;
}

?>
mbhanley 0 Light Poster

I m not sure, javascript can process submitted form or not. so will will need perl in html2 for storing html1 values in hidden fields.

It should show the menu when hovering over the categories tab not sure why it did not work for you maybe I was messing about with the code at the time but it does show.

Its repeating the categories table row cat_title once joined with the subcategories table.
so I get category title, then a subcategory title then it repeats its self in that way.

Rather than having a category title then a subcategory title and another subcategory title then another subcategory title.

The tables are set up like this.

(categories)
cat_id cat_title

(subcategories)
subcat_id subcat_title cat_id

mbhanley 0 Light Poster

you are using same field cat_id in both the table. you don't need to select cat_id from subcategories table.

SELECT c.cat_id, c.cat_title, s.subcat_id, s.subcat_title FROM categories AS c LEFT JOIN subcategories AS s ON c.cat_id = s.cat_id ORDER BY c.cat_id

Thanks for the help Chintan, I have got two table columns cat_id, in both tables categories and subcategories so that the subcategories can be identified to the categories table row based on its id the mysql table set up is like the this.

(categories)
cat_id cat_title

(subcategories)
subcat_id subcat_title cat_id


The problem is it seems to repeat the categories table once joined with the subcategories table and then when I echo out the cat_title row it repeats it more than once.

I only need it to echo the category once then echo all the subcategories underneath that category rather than repeating the cat_title with each subcat_title.

mbhanley 0 Light Poster

Try this . I think you had not used join correctly.

"SELECT c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id
FROM categories AS c LEFT JOIN subcategories AS s ON c.cat_id = s.cat_id ORDER BY subcat_id ";

Nope still does not work getting a repeat on the category table row. And if I use a MySQL statement HAVING repeats i.e.

$sql = "SELECT COUNT(*) as repetitions, c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id FROM subcategories AS s INNER JOIN categories AS c ON c.cat_id=s.cat_id GROUP BY s.cat_id HAVING repetitions > 1";

It cuts off the rest of the table rows for subcategories, subcat_title

mbhanley 0 Light Poster

I will be using a Mega menu and have Categories then SubCategories displayed underneath but I keep getting repeats on the category table row if you take a look at www.awholesaledirectory.com and hover over the category part on the menu you can see what I'm talking about a little better

mbhanley 0 Light Poster

I have tried for hours now trying to figure out how to do this and I'm sure its impossible, I have tried the following queries and still searching for the solution.
I need to display the subcategories, subcat_title table row based on the condition the table row cat_id is equal to the cat_id row of the categories table. Its working but not how I need it to as its repeating the table row cat_title from the categories table. I'm trying to get this query to work so I can create a Mega Menu for my site.
Any help would be very appreciated.

$sql = "SELECT * FROM categories c, subcategories s WHERE c.cat_id = s.cat_id ORDER BY ABS( `cat_title` )";
$sql = "SELECT COUNT(*) as repetitions, c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id FROM subcategories AS s INNER JOIN categories AS c ON c.cat_id=s.cat_id GROUP BY s.cat_id HAVING repetitions > 1";
$sql = "SELECT c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id FROM subcategories AS s LEFT OUTER JOIN categories AS c ON c.cat_id = s.cat_id ORDER BY c.cat_title";
mbhanley 0 Light Poster

Having A Problem in getting results to display correctly I seem to be getting two sets of results displayed for categories "cat_title" when I only need it displayed once.
What is the best way around this does anyone know whether I should define using an mysql query or PHP.

function get_categories($id='') {
		
		if($id != ""):
		$id = mysql_real_escape_string($id);
		$sql = "SELECT c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id 
		FROM subcategories AS s LEFT JOIN categories AS c ON c.cat_id = s.cat_id ORDER BY subcat_id ";
		else:
		$sql = "SELECT c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id 
		FROM subcategories AS s LEFT JOIN categories AS c ON c.cat_id = s.cat_id ORDER BY subcat_id ";
		endif;
		$res = mysql_query($sql) or die(mysql_error()); 
		if(mysql_num_rows($res) != 0):
		while($row = mysql_fetch_assoc($res)) {
		
		$base_url = 'http://www.awholesaledirectory.com/';
		$cat_title = $row['cat_title'];
		
		$cat_title =preg_replace('/[^A-Za-z0-9-]+/', '-', $row['cat_title'] );
		$category_title = strtolower( trim( $cat_title ) );
		
		$subcat_title = $row['subcat_title'];
		$subcat_title =preg_replace('/[^A-Za-z0-9-]+/', '-', $row['subcat_title'] );
		$subcategory_title = strtolower( trim( $subcat_title ) );
		
		echo '<ul><li><h2><a href="'.$base_url.'' .$category_title. '" title="' .$row['cat_title']. '">' .$row['cat_title']. '</a><h2></li>';
		echo '<li><a href="'.$base_url.'' .$subcategory_title. '" title="' .$row['subcat_title']. '">' .$row['subcat_title']. '</a></li>'; 
		
		
		}
		else:
			echo '';
		endif;	
}
mbhanley 0 Light Poster

I get it now.. how confusing, I was stuck thinking I needed to php to check it lol.
How simple I never thought you could use an id as another id with a query nice one for your help on this.

mbhanley 0 Light Poster

I need to restrict access to other table id's by making a check against an (id) of a table named users and then check that the (user_id) of another table is the same i.e

table1

id username password

table2

id somedata user_id


if table1 id is the same as table2 user_id then show table2 contents but only show the contents of table2 where the user_id exists and still use the id row of table2 to display contents in a url like ?id=12 only if its the users data if not frow an error

How would I go about this I have tried and tried but no joy

I have some code setup that I been trying I can post if like.

mbhanley 0 Light Poster

I noticed I did not show the full code missed a bit, soz here is the full function

//Update model


function update_model_form($id){
	


$id = mysql_real_escape_string($row['id']);
$user_id = mysql_real_escape_string($row['user_id']);
$username = mysql_real_escape_string($_SESSION['username']);
$who = mysql_query("SELECT u.id, u.username FROM users u INNER JOIN profile p WHERE username='$username' AND user_id='$id'");
$who_num_rows = mysql_num_rows($who);
if (!$username&&$id==$user_id)

		$id = mysql_real_escape_string($id);
		
		$sql = "SELECT p.cname, p.email, p.work_landline, p.mobile, p.door_no, p.street, p.town, p.county, p.country, 
		p.postcode, p.website, p.aimage, p.intro, p.id 
		FROM profile p INNER JOIN users u ON u.id=p.user_id 
		WHERE u.username = " . mysql_real_escape_string($_SESSION['username']) ." ORDER BY cname ASC";
		
		$sql = "SELECT * FROM cescorts WHERE id = '$id'";
		$res = mysql_query($sql) or die(mysql_error());
		$row = mysql_fetch_assoc($res);
	
		?>
        <?php include 'tinymce.php'; ?>
        
        <form method="post" action="escorts.php">
          <input type="hidden" name="update_model" value="true" />
          <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
          <div id="edit-model-form">
            <div class="edit-model">
              <label for="g_name">Models Name:</label>
              <input type="text" name="g_name" value="<?php echo $row['g_name']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="nationality">Nationality:</label>
              <input type="text" name="nationality" value="<?php echo $row['nationality']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="age">Age:</label>
              <input type="text" name="age" value="<?php echo $row['age']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="height">Height:</label>
              <input type="text" name="height" value="<?php echo $row['height']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="bust">Bust:</label>
              <input type="text" name="bust" value="<?php echo $row['bust']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="dress_size">Dress Size:</label>
              <input type="text" name="dress_size" value="<?php echo $row['dress_size']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="hair">Hair Colour:</label>
              <input type="text" name="hair" value="<?php echo $row['hair']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="eyes">Eye Colour:</label>
              <input type="text" name="eyes" value="<?php echo $row['eyes']; ?>">
            </div>
            <br />
            <div class="edit-model"> …
mbhanley 0 Light Poster

yeh I got the database setup correct and the session start at the top of each page

I get the following error,

Parse error: syntax error, unexpected T_ELSE, expecting T_FUNCTION in C:\xampp\htdocs\public_html\adultxxxzone.co.uk\members\agency\class\members_class.php on line 759

mbhanley 0 Light Poster

Sure no prob, thanks for your help..

$id = mysql_real_escape_string($row['id']);
$user_id = mysql_real_escape_string($row['user_id']);
$username = mysql_real_escape_string($_SESSION['username']);

$who = mysql_query("SELECT u.id, u.username FROM users u INNER JOIN profile p WHERE username='$username' AND user_id='$id'");

$who_num_rows = mysql_num_rows($who);

if (!$username&&$id==$user_id)

function update_model_form($id){
		$id = mysql_real_escape_string($id);
		
		sql = "SELECT p.cname, p.email, p.work_landline, p.mobile, p.door_no, p.street, p.town, p.county, p.country, 
		p.postcode, p.website, p.aimage, p.intro, p.id 
		FROM profile p INNER JOIN users u ON u.id=p.user_id 
		WHERE u.username = "' . mysql_real_escape_string($_SESSION['username']) . ' " ORDER BY cname ASC";
		
		$sql = "SELECT * FROM cescorts WHERE id = '$id'";
		$res = mysql_query($sql) or die(mysql_error());
		$row = mysql_fetch_assoc($res);
	
		?>
        <?php include 'tinymce.php'; ?>
        
        <form method="post" action="escorts.php">
          <input type="hidden" name="update_model" value="true" />
          <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
          <div id="edit-model-form">
            <div class="edit-model">
              <label for="g_name">Models Name:</label>
              <input type="text" name="g_name" value="<?php echo $row['g_name']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="nationality">Nationality:</label>
              <input type="text" name="nationality" value="<?php echo $row['nationality']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="age">Age:</label>
              <input type="text" name="age" value="<?php echo $row['age']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="height">Height:</label>
              <input type="text" name="height" value="<?php echo $row['height']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="bust">Bust:</label>
              <input type="text" name="bust" value="<?php echo $row['bust']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="dress_size">Dress Size:</label>
              <input type="text" name="dress_size" value="<?php echo $row['dress_size']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="hair">Hair Colour:</label>
              <input type="text" name="hair" value="<?php echo $row['hair']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="eyes">Eye Colour:</label>
              <input type="text" name="eyes" value="<?php echo $row['eyes']; ?>">
            </div>
            <br />
            <div class="edit-model">
              <label for="languages">Languages:</label>
              <input type="text" name="languages" value="<?php echo $row['languages']; ?>">
            </div>
            <br …
mbhanley 0 Light Poster

Can anyone tell me if I am going in the wright direction with this, or if there is a better way, I am trying to create a session check so that if logged in clients change the url id number
example.com?id=192
it won't show other clients contents. Its the first time having to write a cms with multiple mysql table checks so the query is probably wrong as well.

$id= mysql_real_escape_string($row['id']);
$user_id= mysql_real_escape_string($row['user_id']);
$username = mysql_real_escape_string($_SESSION['username']);

$who = mysql_query("SELECT u.id, u.username FROM users u INNER JOIN profile p WHERE username='$username' AND user_id='$id'");

$who_num_rows = mysql_num_rows($who);

if (!$username&&$id==$user_id)
	
Runn valid page content.
	
else
{
Runn error.
}
mbhanley 0 Light Poster

Finally fixed the problem at last 8 hours later lol what headache

mbhanley 0 Light Poster

This might help, would have anything to do with the multipart/mixed also are their any setting that need to be changed in php.ini file.

http://www.webcheatsheet.com/php/send_email_text_html_attachment.php

mbhanley 0 Light Poster

Soz I missed one out

function get_pagination($id = '') {
		
		if($id != ""):
			$id = mysql_real_escape_string($id);
			$sql = "SELECT COUNT(*) FROM profile WHERE id = '$id'";	
			else:
			$sql = "SELECT p.cname, p.intro, p.aimage, p.id, p.user_id  
				   FROM profile p INNER JOIN users u ON u.id=p.user_id != '' ORDER BY p.id ASC $pages->limit";
		endif;
		
		$res = mysql_query($sql) or die(mysql_error());
		
		if(mysql_num_rows($res) != 0):
			while($row = mysql_fetch_assoc($res)) {
	
	echo "<br />";
	$user_id = $row['user_id'];
	$cname = $row['cname'];
	
	
	$intro = $row['intro'];
	$aimage = '<a href="page.php?='. $row['id'] .'"><img src="members/images/'. $row['aimage'] .' " style="width:100px; height:165px; border:1px solid #000;" /></a>';
	
	echo $user_id;
	echo "<br />";
	echo $cname;
	echo "<br />";
	echo $intro;
	echo "<br />";
	echo $aimage;
	echo "<br />";
	echo "<br /><br /><hr /><br />";	
			}
		else:
			echo '<p>Uh Oh!, this doesn\'t exist!</p>';
		endif;
	}
mbhanley 0 Light Poster

If I set a value inside it works but if dont then it won't so I guess not value is being passed on which is wierd as it works with everything else I have done so far.

function get_agency_profile($id='2') {
		
		if($id != ""):
		$id = mysql_real_escape_string($id);
		$sql = "SELECT * FROM profile WHERE id = '$id'"; 
		else:
		$sql = '
		SELECT p.cname, p.email, p.id, p.user_id 
		FROM profile p INNER JOIN users u ON p.user_id=u.id 
		WHERE p.user_id=user_id ORDER BY id ASC';  
		endif;
		$res = mysql_query($sql) or die(mysql_error()); 
		if(mysql_num_rows($res) != 0):
			while($row = mysql_fetch_assoc($res)) {
				
				$id = 1;
				echo ' <br /> ';
				echo ' ' . $row['user_id'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['cname'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['email'] . ' ';
			}
		else:
			echo '<p>Uh Oh!, this doesn\'t exist!</p>';
		endif;	
	}

The code that should pass the value is:

<?php 
require_once 'class/paginator.class.php'; 
include 'class/class.php';
include 'db_inc/obj.php';



$result = mysql_query("SELECT COUNT(*) FROM profile WHERE id"); 
while($num_rows = mysql_fetch_array($result))
  {	
	$pages = new Paginator;  
    $pages->items_total = $num_rows[0];  
    $pages->mid_range = 9;  
    $pages->paginate();  

echo '<span style="margin-left:25px"> ' . $pages->display_jump_menu() . $pages->display_items_per_page() . '</span>';  

	if(isset($_GET['id'])):
		$obj->get_pagination($_GET['id']);
	else:
		$obj->get_pagination();
	endif;
	
	
    echo $pages->display_pages();  
  }
?>

The get function call

if(isset($_GET['id'])):
		$obj->get_agency_profile($_GET['id']);
	else:
		$obj->get_agency_profile();
	endif;

Does any thing look odd with the code

mbhanley 0 Light Poster

No still no go, At the moment it just runns and loops every item in the data base wich is echo-ing 6 times rather than just once I feel this maybe an SQL prob but I can't see any problem with it and I have tried everything I can think of, its really anoying. grrr

mbhanley 0 Light Poster

Thats no prob I have other scripts as well such as image upload and rename to a random value based on unix timestamp and insert into database would you like a copy. Also I will be using that script with jquery image crop soon as well. Check out.

http://www.webmotionuk.co.uk/php-jquery-image-upload-and-crop-v11/

mbhanley 0 Light Poster

Here is the code I use to upload and resize images. Hope it helps.

<?php  
   
require 'include/product_upload_config.php';  
require 'include/product_upload_functions.php';  
   
 if(isset($_FILES['fupload'])) {  
       
     if(preg_match('/[.](jpg)|(gif)|(png)$/', $_FILES['fupload']['name'])) {  
           
         $filename = $_FILES['fupload']['name'];  
        $source = $_FILES['fupload']['tmp_name'];
        $target = $path_to_image_directory . $filename;  
          
        move_uploaded_file($source, $target);  
           
         createThumbnail($filename);
    }  
 }  
?>
          <h3>Upload Product Image!</h3>
          <form enctype="multipart/form-data" action="<?php print $_SERVER['PHP_SELF']?>" method="post">
            <input type="file" name="fupload" />
            <input type="submit" value="Go!" />
          </form>

product_upload_functions.php

<?php

function createThumbnail($filename) {  
       
     require 'product_upload_config.php';  
       
     if(preg_match('/[.](jpg)$/', $filename)) {  
         $im = imagecreatefromjpeg($path_to_image_directory . $filename);  
     } else if (preg_match('/[.](gif)$/', $filename)) {  
         $im = imagecreatefromgif($path_to_image_directory . $filename);  
     } else if (preg_match('/[.](png)$/', $filename)) {  
         $im = imagecreatefrompng($path_to_image_directory . $filename);  
     }  
       
     $ox = imagesx($im);  
     $oy = imagesy($im);  
       
     $nx = $final_width_of_image;  
     $ny = floor($oy * ($final_width_of_image / $ox));  
       
  $nm = imagecreatetruecolor($nx, $ny);  
       
     imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);  
       
     if(!file_exists($path_to_thumbs_directory)) {  
       if(!mkdir($path_to_thumbs_directory)) {  
            die("There was a problem. Please try again!");  
       }   
        }  
   
     imagejpeg($nm, $path_to_thumbs_directory . $filename);  
     $tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';  
     $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a      thumbnail has been created.<br />';  
      echo $tn;  
  }  
 ?>

product_upload_config.php

<?php

$final_width_of_image = 100;  
$path_to_image_directory = 'images/fullsized/product/';
$path_to_thumbs_directory = 'images/thumbs/product/';

?>
mbhanley 0 Light Poster

Have set the correct path to the include i.e.

<?php
include '../includes/store.php';
?>

OR

<?php
include '../../includes/store.php';
?>

As the directory path to the includes could be a folder or two up.

mbhanley 0 Light Poster

Can anyone see where im going wrong with this code I keep hitting a brick wall with it.
Its doing my head in. I think its more the sql code, It keeps showing all data instead of just showing the data based on the user_id which should be limited to one set of data. Any help would be much appreciated :)

function get_agency_profile($id = '') {
		
		if($id != ""):
			$id = mysql_real_escape_string($id);
			$sql = "
		SELECT p.cname, p.email, p.work_landline, p.mobile, p.door_no, p.street, p.town, p.county, p.country, 
		p.postcode, p.website, p.aimage, p.intro, p.id 
		FROM profile p INNER JOIN users u ON u.id=p.user_id 
		WHERE user_id = '$id'";	
		
			else:
			$sql = "
		SELECT p.cname, p.email, p.work_landline, p.mobile, p.door_no, p.street, p.town, p.county, p.country, 
		p.postcode, p.website, p.aimage, p.intro, p.id 
		FROM profile p INNER JOIN users u ON u.id=p.user_id ORDER BY user_id DESC"; 
		endif;
		
		$res = mysql_query($sql) or die(mysql_error());
		
		if(mysql_num_rows($res) != 0):
			while($row = mysql_fetch_assoc($res)) {
				
				echo ' <br /> ';
				echo ' ' . $row['id'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['cname'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['email'] . ' ';
			}
		else:
			echo '<p>Uh Oh!, this doesn\'t exist!</p>';
		endif;
		
		
	}
mbhanley 0 Light Poster

Thank you thats helped a lot I wasn't to sure if I could not use a function class inside another function. I did manage to get it working but not with a function so I will just use that instead and now I face another problem but trial and error seems the only way at the min, I now think it will be a good idea to plan this thing out on paper as im starting to loose where i am this lol, Thanks for your help very useful.

mbhanley 0 Light Poster

Not sure if its the sql query or what, but I have a pagination class and a function I am trying to put together if some one would be able to point be in the wright direction it will be very appreciated. :)

The following is the function which I am trying to get results from, based on a count of id's from a table called (profile) then joined by a row (user_id) to a table called (users) I then need to display certain rows from both tables and use the $id variable to use as an anchor so it can be used in a href link.

// Function for pagination
function get_cprofile($id = '') {
		
		if($id != ""):
			$id = mysql_real_escape_string($id);

			$sql = "SELECT COUNT(*) FROM profile WHERE id = '$id'";	
			
		else:
		
		$sql = "
		SELECT p.cname, p.intro, p.aimage, p.id 
		FROM profile p INNER JOIN users u ON u.id=p.user_id 
		WHERE u.id = 'p.user_id' != '' ORDER BY p.id ASC $pages->limit 
		";
		
		endif;
		
		$res = mysql_query($sql) or die(mysql_error());
		
		if(mysql_num_rows($res) != 0):
			while($num_rows = mysql_fetch_assoc($res)) {
			
	echo "<br />";
	$cname = $row['cname'];
	$intro = $row['intro'];
	$aimage = '<img src="members/images/'. $row['aimage'] .' " style="width:100px; height:165px; border:1px solid #000;" />';
	
	echo $cname;
	echo "<br />";
	echo $intro;
	echo "<br />";
	echo $aimage;
	echo "<br /><br /><hr /><br />";
	
    echo $pages->display_pages();  
		
			}
		else:
			echo '<br /><p>No Profile Details Available! Please Add Some <-link-> </p>';
		endif;
		
		echo '<br />';
	}

This next bit of code calls the function above and objects class from my …

mbhanley 0 Light Poster

Why not try installing and using roundcube, http://roundcube.net/

mbhanley 0 Light Poster

OK, now I see the problem. The issue is that you are executing SELECT * but both tables have an id column. What you need to do is specify precisely which columns you want by prefixing the columns with the table (notice that I used "u" as the alias for the "users" table and "c" for the contacts table):

Assuming you are interested in users.id, try:

$sql='
SELECT c.fname, c.lname, u.id
FROM contacts c INNER JOIN users u ON u.id=c.user_id
 WHERE 
        u.username = "' . mysql_real_escape_string($_SESSION['username']) . '"';

Thank you so much it works perfectly I just had to change u.id to c.id on the select and that was all I am so gonna have to look up more on sql.


Thank you.

mbhanley 0 Light Poster

I don't understand what you mean. Post a sample of BOTH tables

Sorry if im making things more complicated than they need to be im rubbish at explaining.

I am trying to get the user_id of the contacts table to match the id of the users table
based on the session username. and then display the id of the contacts table using an
echo.

Table structure for table `contacts`
--

CREATE TABLE IF NOT EXISTS `contacts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fname` varchar(25) NOT NULL,
  `lname` varchar(25) NOT NULL,
  `email` varchar(40) NOT NULL,
  `landline` varchar(20) NOT NULL,
  `work_landline` varchar(20) NOT NULL,
  `mobile` varchar(20) NOT NULL,
  `door_no` varchar(10000) NOT NULL,
  `street` varchar(100) NOT NULL,
  `town` varchar(100) NOT NULL,
  `county` varchar(100) NOT NULL,
  `country` varchar(100) NOT NULL,
  `postcode` varchar(15) NOT NULL,
  `website` varchar(50) NOT NULL,
  `user_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(25) NOT NULL,
  `username` varchar(25) NOT NULL,
  `password` varchar(100) NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
mbhanley 0 Light Poster

what is NOT working on the code you posted? Are you NOT getting any results? Are you getting the ENTIRE table? Are you getting the WRONG id?

Have you tried to echo your sql statement to verify what sql command is actually being executed?

Hi sorry for any confusion I find it hard to explain some things. I am getting the same results on each echo of the row variable and its being displayed from the user_id of the table rather than getting the result from the id of the table.

mbhanley 0 Light Poster

Here you go use this and then include the text files into a textarea it works pretty sweet. Hope this helps.

<?php

/* 
Search engine spiders
Yahoo! Slurp
Msnbot
Googlebot
Ask Jeeves
*/

$useragent = $_SERVER["HTTP_USER_AGENT"];
$ref = $_SERVER['HTTP_REFERER'];
$host = $_SERVER['HTTP_HOST'];
$ip = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y H:i:s');


if (strpos($useragent,"Firefox"))
{
	//found! create file
	$file = fopen("./crawldetector/Visitor.txt","a");
	fwrite($file,""."\nVisitor Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}


if (strpos($useragent,"Yahoo! Slurp"))
{
	//found! create file
	$file = fopen("./crawldetector/Yahoo.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}

if (strpos($useragent,"Googlebot"))
{
	//found! create file
	$file = fopen("./crawldetector/Googlebot.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}

if (strpos($useragent,"Msnbot"))
{
	//found! create file
	$file = fopen("./crawldetector/Msnbot.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}

if (strpos($useragent,"Ask Jeeves"))
{
	//found! create file
	$file = fopen("./crawldetector/AskJeeves.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}


?>

Textarea's with the text files to include.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Crawler Stats</title>
</head>

<body>

<h4>Visitors</h4>
<textarea rows="10" cols="70">
<?php include('visitor.txt'); ?>
</textarea>

<br />
<h4>Google</h4>
<textarea rows="10" cols="70">
<?php include('googlebot.txt'); ?>
</textarea>

<br />
<h4>Yahoo</h4>
<textarea rows="10" cols="70">
<?php include('Yahoo.txt'); ?>
</textarea>

<br />
<h4>Bing</h4>
<textarea rows="10" cols="70">
<?php include('Msnbot.txt'); ?>
</textarea>

<br />
<h4>Ask Jeeves</h4>
<textarea rows="10" cols="70">
<?php include('AskJeeves.txt'); ?>
</textarea>

</body>
</html>