FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[help]Mysql & php problem





cherry-pie
Hi I'm having some problems with mysql & php connection, it was working last week but now it's not working anymore and I don't know what is the problem Sad it was to show the layouts of each category separately but is showing all mixed together and some do not appear

Here is the page:

http://animetemplates.110mb.com/index.php?page=animetemplates&category=CardCaptorSakura

http://animetemplates.110mb.com/index.php?page=animetemplates&category=Air


this is the code

Quote:

<?php

include ('dbconfig.php');

$table = 'layouts'; // The name of your table in the database
$limit = '5'; // How many results should be shown at a time
$scroll = '20'; // How many elements to the navigation bar are shown at a time

// Get the total number of rows in a database
$query1 = mysql_query ("SELECT id FROM $table WHERE category='$category'");
$numrows = mysql_num_rows ($query1);
//

if (!isset ($_GET[show])) {
$display = 1;
} else {
$display = $_GET[show];
}

// Return results from START to LIMIT
$start = (($display * $limit) - $limit);
if(isset($category)){
$query = "select * from $table where category='$category' order by id desc limit $start, $limit";
}else{
$query = "select * from $table order by id desc limit $start, $limit";
}
$result= mysql_query($query, $connection) or die

("Could not execute query : $query." . mysql_error());

// Continue usual Code, display data

while ($row=mysql_fetch_array($result))
{
extract($row);

echo "<table border=\"0\" bordercolor=\"#000000\" cellpadding=\"0\" cellspacing=\"0\" width=\"163\" align=\"center\"><tr><td width=\"163\">
<p align=\"center\"><img src=\"$previewimage\"></td> </tR>
<tr>
<td width=\"163\"><b>Nome:</b>
$name<br>
<b>Data:</b>$date<br>
<b>Template by:</b> <a href=\"$artisturl\">$artist</a><br>
<b>Disponível:</b> $series<br>
<A href=\"$viewhtml\" target=\"_blank\">Pegar Código</a> | <a href=\"$download\">Download</a></td>
</tr>
</table><br>";
}

$paging = ceil ($numrows / $limit);

// Making the next prev links
if ($display > 1) {
$previous = $display - 1;

echo "<a href=\"$_SERVER[PHP_SELF]?page=animetemplates&category=$category&show=$previous\" target=\"_self\"><<Previous</a> | ";

}

if ($numrows != $limit) {
if ($paging > $scroll) {
$first = $_GET[show];
$last = ($scroll - 1) + $_GET[show];
} else {
$first = 1;
$last = $paging;
}
if ($last > $paging ) {
$first = $paging - ($scroll - 1);
$last = $paging;
}
for ($i = $first;$i <= $last;$i++){
if ($display == $i) {
echo "<b>$i</b> ";
} else {
echo "<a href=\"$_SERVER[PHP_SELF]?page=animetemplates&category=$category&show=$i\" target=\"_self\">$i</a> ";
}
}
}

if ($display < $paging) {
$next = $display + 1;
echo "| <a href=\"$_SERVER[PHP_SELF]?page=animetemplates&category=$category&show=$next\" target=\"_self\">Next>></a> ";

}
//


?>


If someone knows what is happening I would be sooo greatful Very Happy
ps: i'm not used to mysql language so don't be mad at me xD
ps2: my english is really bad i hope you can understand me
jmlworld
In dbconfig.php, make sure these details are correct:

1. database name
2. database username
3. database password
4. database server (usually its 'localhost', but there are some hosts who change this to something else)
5. Make sure that your current MySQL user name has the SELECT, UPDATE & INSERT privileges.

Usually, errors related to MySQL connection are due to the problems mentioned above. Check them out and lets know the result.

p.s. Your site is not loading for me.
cherry-pie
I think it's correct

Quote:

<?PHP
$hostname="localhost";
$user="****";
$pass="****";
$dbase="sailormo_fantasy";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
?>
AftershockVibe
Uh... you don't appear to be loading $category in from the URL.

Put this line in before you use it:
Code:
$category = $_GET[category];

or, for added safety:
Code:
$category = mysql_escape_string($_GET[category]);


You'll need to do the same for any other variables you're setting this way. I haven't checked to see if you have though.
Cool
cherry-pie
AftershockVibe wrote:
Uh... you don't appear to be loading $category in from the URL.

Put this line in before you use it:
Code:
$category = $_GET[category];

or, for added safety:
Code:
$category = mysql_escape_string($_GET[category]);


You'll need to do the same for any other variables you're setting this way. I haven't checked to see if you have though.
Cool


Wow it worked Very Happy thanks a lot *o*
Fire Boar
AftershockVibe wrote:
Uh... you don't appear to be loading $category in from the URL.

Put this line in before you use it:
Code:
$category = $_GET[category];

or, for added safety:
Code:
$category = mysql_escape_string($_GET[category]);


You'll need to do the same for any other variables you're setting this way. I haven't checked to see if you have though.
Cool


For validness sake, the contents of the [] should be quoted, as in:

Code:
$category = $_GET['category'];


It will still work if you don't... with the current version of PHP. But there is no guarantee that a depreciated form will work with later versions.
AftershockVibe
Quote:
For validness sake, the contents of the [] should be quoted, as in:

Code:
$category = $_GET['category'];


It will still work if you don't... with the current version of PHP. But there is no guarantee that a depreciated form will work with later versions.


Indeed, I actually changed away from that in order to fix in with the rest of the script (as to not confuse the newcomer).
Related topics
Mysql And PHP HELP PLZ
simple php problem, please help...
How To : Improve Your PHP Programming
A PHP problem !
HTML + PHP problem
mysql and apache problem.
PHP problem...
[MySQL (& php)] += in SQL?
PHP/Mysql - beginner!
A very good PHP MySQL Tutorial
MySQL and PHP problem in the future
Need Help integrating php variable into mySQL SELECT query
BEGINNING MYSQL and PHP
Could there be a PhP problem on the server?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.