Jump to content

Still struggling with codes


djfox

Recommended Posts

I`m still having devil of a time getting my php to display the data from the mysql database.

 

<?php
//Date: February 25 2007
//For: www.secrettrance.net
//Description: Trancer Profile

session_start();
include("dbcon.php");
include("func.php");
require_once "auth.php";
require_once "includes/defines.php";




$lev=$_SESSION['level2'];

if($submit){
   $s = $sub." by ".$name;
   //$b= emote($bod);
   mysql_query("INSERT INTO artistcomment (userID,subject,content,date,sender) VALUES ( '$g', '$s', '$bod', NOW(),$send )")or die ( mysql_error());
   mysql_query("INSERT INTO messagedata (recBoxID, sendBoxID, content, subject, isNew, date) VALUES ($gall, '1', 'Profile Comment Recieved <br><a href=trancer.php?g=$gall>Please click here to go to your profile</a>.<br>This is automated message please do not reply.', 'New Profile comment received!', 1, NOW() )");
}
//get the users information
$query = "SELECT login, level, rName, age, gender, aim, yahoo, msn, icq, livejournal, bio,email, country, website,mood, status, icon, webcam, arttype FROM userdata WHERE id='$gall'";
$user = mysql_query($query) or die("Query failed: [$query] - " . mysql_error()); 



$res = mysql_query("SELECT COUNT(*) FROM artistcomment WHERE userID='$gall'");
$numCom = mysql_fetch_row($res);
mysql_free_result($res);

$res = mysql_query("SELECT COUNT(*) FROM image WHERE gallNum='$gall'");
$numImage = mysql_fetch_row($res);
mysql_free_result($res);

$res = mysql_query("SELECT id, name, gallNum, URL, description, addDate FROM image WHERE gallNum='$gall' ORDER BY id DESC");
$log = $user[0];




$Title = "Secret Trance: Trancer";

require_once "header.php";
require_once "hidestatus.php";
?>




<table border=0 width=100%><? //1 
?>
<tr>
<td bgcolor="4A4553">
<table border=0 width=100%>
<tr>
<td bgcolor="312D37"><a href="trancer.php?g=<? echo $gall ?>"><img src="<? echo $user[16]; ?>" width=50 height=50 border=0></a>
<tr>
<td>
</table>


</table><? //1 
?>



<?
require_once "footer.php";
?>

 

There`s the code I have for the entire page to display profiles. Currently I have in the stuff to display the icon. Yes, there is an icon in the database for the thing to pull out & display.

 

There are no error messages coming up on the browser (yes, error logging is on, & for a while error messages were coming up left & right & I got all those to go away but it still isn`t working the way it should). Here`s what the error log has to say:

 

[01-Mar-2007 09:51:55] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 25

[01-Mar-2007 09:51:55] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 26

[01-Mar-2007 09:51:55] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 25

[01-Mar-2007 09:51:55] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 26

[01-Mar-2007 09:52:25] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 25

[01-Mar-2007 09:52:25] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 26

[01-Mar-2007 09:52:26] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 25

[01-Mar-2007 09:52:26] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trancer.php on line 26

 

HOWEVER

As I stated before, the error messages are finally gone off the page & the page is still not displaying the information from the database as it should. That is all the error log shows pertaining to this file. I`m posting it because I know there will be someone asking what the error log says if I don`t post it. Now that I have the error messages gone from the browser display, it is not saying anything more. I know there is still a problem because it still isn`t working, php & the error log just aren`t telling me there is a problem or where it is, or much of anything.

 

I`m stuck. I`ve had other programmers look at it & can`t figure it out. I looked through my huge php book, couldn`t find anything. No online searches had a solution.

Link to comment
Share on other sites

What exactly is the problem? It won't show the icon?

 

Try showing one DB column at a time until it breaks. Then post that simple code.

 

We are going to find it hard to help you if you have icons stored as BLOBS in the DB, cos not many of us can replicate it easily on our local servers  :P

 

monk.e.boy

Link to comment
Share on other sites

What exactly is the problem? It won't show the icon?

 

Try showing one DB column at a time until it breaks. Then post that simple code.

 

We are going to find it hard to help you if you have icons stored as BLOBS in the DB, cos not many of us can replicate it easily on our local servers  :P

 

monk.e.boy

 

The icon in the database is stored as VARCHAR, so all that has to be entered is the url. The page will pull out the url of the icon to display. In this case, it is "defaut.jpg" under the same directory that the file (trancer.php) is under. I know the icon is there & working because the same exact piece of information is called under another file (trances.php). The code for trances.php is as follows:

 

<?php
//Date: February 24 2007
//For: www.secrettrance.net
//Description: Main Index

include("dbcon.php");
include("func.php");
require_once "auth.php";
require_once "includes/defines.php";

$Title = "Secret Trance: Go into a Trance";

require_once "header.php";
require_once "hidestatus.php";
?>




<?
$lev=$_SESSION['level2'];

$res = mysql_query("SELECT id,name,gallNum,URL,rating,numRates,description,views,cat,addDate, feature, literature FROM image WHERE id=$id");
$rows = mysql_fetch_row($res);
mysql_free_result($res);

if($submit){
   $s = $sub." by ".$name;
   $b= emote($bod);
   mysql_query("INSERT INTO comment (imageID,subject,content,date,sender) VALUES ( '$id', '$s', '$b', NOW(),$send)")or die ( mysql_error());
   mysql_query("INSERT INTO messagedata (recBoxID, sendBoxID, content, subject, isNew, date) VALUES ($rows[2], '1', 'You have a new comment on one of your trances that you have submitted.<br><a href=trances.php?id=$id>Click here to read the comment</a>.<br>This is automated message please do not reply.', 'New Comment!', 1, NOW() )");

}
if($policy && ($lev>6)){
   mysql_query("UPDATE userdata SET violations=SUM(violations,1) WHERE login='$name'");
}

$res = mysql_query("SELECT login FROM userdata WHERE id='$rows[2]'");
$by = mysql_fetch_row($res);
mysql_free_result($res);

$res = mysql_query("SELECT icon FROM userdata WHERE id='$rows[2]'");
$icon = mysql_fetch_row($res);
mysql_free_result($res);

$res = mysql_query("SELECT name, id FROM imagecats WHERE id=$rows[8]");
$catName = mysql_fetch_row($res);
mysql_free_result($res);

$res = mysql_query("SELECT COUNT(*) FROM comment WHERE imageID='$id'");
$numCom = mysql_fetch_row($res);
mysql_free_result($res);

//Update unique pageview counter
if( !$_SESSION["sess_$id"] ){
   $_SESSION["sess_$id"] = "visited";
   $v = $rows[7] + 1;
   mysql_query("UPDATE image SET views=$v WHERE id='$id'");
}
?>




<table border=0 width=100%><? //1 
?>
<tr>
<td width=15% valign=top>
<?
require_once "leftbar.php";
?>


<td width=80% valign=top>

<table border=0 width=100%>
<tr>
<td>





<table border=0 width=100%>
<tr>
<td bgcolor="4A4553">
<table border=0 width=100%>
<tr>
<td bgcolor="312D37"><table border=0><tr><td valign=center><a href="trancer.php?g=<? echo $rows[2] ?>"><img src="<? echo $icon[0] ?>" border=0></a>
<td valign=center><b><font size=5><? echo $rows[1]?></font>
<br><font size=4>by <a href="trancer.php?g=<? echo $rows[2] ?>"><? echo $by[0] ?></font></a></b></table>
<tr>
<td>
<center><img src="<? echo $rows[3]?>">
<br>© <? echo $by[0] ?>
<p>
<font size=2>If this trance is not the artist`s original work or violates any of the policies, <a href="report.php">report</a> it immediately.</font></center>
</table>
</table>


<table border=0 width=100%>
<tr>
<td>
<tr>
<td bgcolor="4A4553" valign=top width=50%>
<table border=0 width=100%>
<tr>
<td bgcolor="312D37"><b>Trancer Comments</b>
<tr>
<td valign=top><? echo $rows[6]?>
</table>
<td>
<td valign=top bgcolor="4A4553" width=50%>
<table border=0 width=100%>
<tr>
<td bgcolor="312D37"><b>Details</b>
<tr>
<td>
<font size=2>
Title: <b><? echo $rows[1]?></b>
<br>Trancer: <b><a href="trancer.php?g=<? echo $rows[2] ?>"><? echo $by[0] ?></a></b>
<br>Date: <b><?echo $rows[9] ?></b>
<br>Category: <b><a href="search.php?cat=<? echo $catName[1] ?>"><? echo $catName[0] ?></a></b>
</font>
<tr>
<td bgcolor="312D37"><b>Stats</b>
<tr>
<td>
<font size=2>
Views: <b><? echo $rows[7] ?></b>
<br>Comments: <b><? echo $numCom[0] ?></b>
<br>Favourites: <b><? echo $numFavs[0] ?></b>
<? //%%%%%%%%%%%%%%%%
$rate=$rows[4]/$rows[5];
//%%%%%%%%%%%%%%%%%%% ?>

<br>Rating: <b><? echo $rate ?></b> (<? echo $rows[5]?> votes)</font>
<tr>
<td bgcolor="312D37"><b>Fav Trance
<tr>
<td>
<?
if($_SESSION['sess_name']){
  echo "<font size=2><a href=trancefavorite.php?id=$rows[0]&g=$rows[2]>Add Trance to Your Favourites</a></font>";
}
?>
<tr>
<td bgcolor="312D37"><b>Rate Trance
<tr>
<td>
<?
if($_SESSION['sess_name'] && !$_SESSION["img_$id"]){
?>
  <form action="trancerate.php">
  <input type="radio" name="r" value=0>0
  <input type="radio" name="r" value=1>1
  <input type="radio" name="r" value=2>2
  <input type="radio" name="r" value=3>3
  <input type="radio" name="r" value=4>4
  <input type="radio" name="r" value=5>5
  <input type="radio" name="r" value=6>6
  <input type="radio" name="r" value=7>7
  <input type="radio" name="r" value=8>8
  <input type="radio" name="r" value=9>9
  <input type="radio" name="r" value=10>10
  <input type="hidden" name="id" value="<? echo $id ?>">
  <br><input type="submit" value="Rate Trance">
  </form>
<?
}else if($_SESSION["img_$id"]){
  echo "You have already rated this trance for the day.";
}else if(!$_SESSION['sess_name']){
  echo "To rate this trance, you must be logged in.";
}
?>
<tr>
<td bgcolor="312D37"><b>Featured</b>
<tr>
<td>
<font size=2><?echo $rows[10] ?></font>
</table>

</table>





<table border=0 width=100%>
<tr>
<td>
<tr>
<td bgcolor="4A4553">

<table border=0 width=100%>
<tr>
<td bgcolor="312D37"><b>Literature Trance
<tr>
<td>
<?echo $rows[11] ?>
</table>

</table>






<table border=0 width=100%>
<tr>
<td>
<tr>
<td bgcolor="4A4553">

<table border=0 width=100%>
<tr>
<td bgcolor="312D37"><b>Entranced Comments</b> (<font size=2><a href="#leavecomment">Leave Your Own Entranced Comment</a></font>)
<tr>
<td>
<?
$res = mysql_query("SELECT subject,content,date,id,sender FROM comment WHERE imageID=$id ORDER BY id DESC");
while($r = mysql_fetch_row($res) ) $comments[] = $r;

if ($comments) foreach($comments as $c){
?>

<tr><td bgcolor="312D37" colspan=2><a href="trancer.php?g=<? echo $c[4] ?>"><? echo $c[0] ?></a>       Date: <? echo $c[2] ?>       #<? echo $c[3] ?>
<tr><td colspan=2><? echo $c[1] ?>

<tr><td>
<?
}
?>

</table>

</table>






<table border=0 width=100%>
<tr>
<td>
<tr>
<td bgcolor="4A4553">
<a name="leavecomment">
<table border=0 width=100%>
<tr>
<td bgcolor="312D37"><b>Leave an Entranced Comment
<tr>
<td>
<?
if( $_SESSION['sess_name'] ){
$sender= $_SESSION['gal'];
?>
<tr>
<td>
<table border=0 width=100%>
<tr>
<td valign=top>
<form action="trances.php">
<input type=hidden name="name" value="<? echo $_SESSION['sess_name'] ?>">
<input type=hidden name="id" value="<? echo $id ?>">
<input type=hidden name="send" value="<? echo $sender ?>">
Subject:
<td valign=top><input type="text" name="sub" size=40>
<tr>
<td valign=top>Comment:
<br><font size=2><a href="emoticons.php" target="_blank">Emoticon Legend</a></font>
<td valign=top>
<textarea rows="5" cols="70" name="bod" style="border: 0px; background-color:#141317; color: #B6ABCE;"></textarea>
<tr>
<td><td>
<input type="submit" name="submit" value="Leave Entranced Comment">
</form>
</table>
<? 
}
?>
</table>

</table>







</table>



</table><? //1 
?>



<?
require_once "footer.php";
?>

 

What bothers me the most about this, is that both trances.php & trancer.php (see first post) both access the same database, the same tables (both recall some information from userdata), they both use the same code. But trances.php works while trancer.php doesn`t. The code all seems the same to me. So I cannot figure out why trancer doesn`t work or even what the problem is (aside from trancer not loading the information as it is supposed to).

Link to comment
Share on other sites

Why not take the code that works. Put it in a function. Test it. Then put the function in an include file. Test it. Then call the function from both PHP pages.

 

That's how it should be done anyway - why write the same code twice, then look for bugs in the second page?

 

monk.e.boy

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.