phpnoob needs help with code
09-18-2008, 03:04 AM
|
phpnoob needs help with code
|
Posts: 20
|
Hi to all,i have some code(its add to favorites script),that code works fine on php4 server,but i have php5 server and i need to know what i must change on this code to get it working on php5 server,so maybe somebody can help,i would be very thankful!
tnx
here is code
PHP Code:
<?php if ($_GET['m']=='add' && strlen($id)) { $fav=$_COOKIE['favorites']; $favorites=explode('|', $fav); if(!array_search($id, $favorites)) { if(setcookie('favorites', $_COOKIE['favorites'].'|'.$id, time()+1209600)) { echo '<title>Add program</title>'; echo'<body style="font-family: Arial, Helvetica; font-size:12px">'; echo '<div style="text-align:center; color:#009900;font-weight:bold">Program added to favorites.<br><br><a href="javascript:window.close()">close window</a></div>'; } else { echo '<title>Add program</title>'; echo'<body style="font-family: Arial, Helvetica"'; echo '<div style="text-align:center; color:#ff0000;font-weight:bold">Program not added to favorites<br>Maybe your browser no accept cookies.<br><br><a href="javascript:window.close()" style="">close window</a></div>'; } } } elseif($_GET['m']=='del' && $_GET['id']) { $fav=$_COOKIE['favorites']; $favorites=explode('|', $fav); if(!strlen($favorites[0])) array_shift($favorites); $key=array_search($_GET['id'], $favorites); unset($favorites[$key]); $fav=implode('|', $favorites); setcookie('favorites', $fav, time()+1209600); header("Location: favorites.php"); } else { $PageTitle='Favourites'; require_once('config/config.php'); require_once('config/func.php'); require('config/begin.php'); ?> <script language="JavaScript"> function paystat(url) { var Win = window.open("payouts.php?id=" + url + "&m=statistic","payouts",'width=400,height=450,toolbar=0,status=0,scrollbars=1,resizable=0,menubar=0'); } </script> <table width="600" border="0" align="center"> <tr> <td> <h1>Favorites</h1> </td> </tr> <tr> <td align="center"> <?php $fav=$_COOKIE['favorites']; if(strlen($fav)) { $favorites=explode('|',$fav); if(!strlen($favorites[0])) array_shift($favorites); if (empty($_GET['p'])) $p = 1; $nawigacja=new navigation(NULL, NULL, $maxProgramsPerPageFavorite, sizeof($favorites)); $from=$nawigacja->navArray[$p]; $nawigacja->nav(); for($i=$from;$i<=($maxProgramsPerPageFavorite-1)+$from;$i++) { $favorite=$favorites[$i]; if(empty($favorite)) continue; if($result=mysql_query("SELECT `nazwa`,`url`,`rating`,`status`,`time_payout`,`total`,`forum` FROM `programs` WHERE `id_program`='$favorite'")) { if(mysql_num_rows($result)) { $row=mysql_fetch_assoc($result); ?> <table style="border-top: 1px solid #666666; border-bottom: 1px solid #666666; width:500px"> <tr> <td width="180"> <b><a href="<?php echo $row['url'] ?>" target="_blank"><?php echo $row['nazwa'] ?></a></b> <img src="gfx/icons/del.gif" width="10" height="10" align="absmiddle" style="cursor:pointer;margin-bottom:2px" onClick="window.location='favorites.php?m=del&id=<?php echo $favorite ?>'"><br> users rating: <b><?php echo $row['rating'] ?></b><br> [<a href="rate.php?id=<?php echo $favorite ?>">rate now</a>] <?php if($row['forum']!='') echo '<br><a href="'. $row['forum'] .'"><img src="gfx/icons/forum.gif" width="17" height="16" align="absmiddle" style="margin-right:5px;margin-top:3px">Visit program forum</a>'; ?> </td> <td width="165" valign="top"> <span style="color: #FF6600; font-weight:bold"><?php echo $row['time_payout'] ?></span><br> <a href="programs.php?m=details&id=<?php echo $favorite ?>">program details</a> </td> <td width="155"> status: <?php echo '<img src="gfx/icons/status_'.$row['status'].'.png" width="100" height="16" align="absmiddle">' ?><br> total payout: <b><?php echo $row['total'] ?> USD</b><br> <a href="javascript:paystat(<?php echo $favorite ?>)">payout statistic</a><br><br> </td> </tr> </table><br> <?php mysql_free_result($result); } else error("No information about program (id: $favorite)."); } else error("Error in SQL query. Cannot display program (id: $favorite)!. Please contact with administrator. "); } $nawigacja->nav(); } else { ?> <br><b>You have no favorites programs.</b><br> Click on icon <img src="gfx/icons/fav.png" width="13" height="12" align="absmiddle"> to add program to favorites.<br> You must have cookies enabled in your browser<br><br> <?php } ?> </td> </tr> </table> <?php require('config/end.php'); } ?>
|
|
|
|
09-18-2008, 09:16 AM
|
Re: phpnoob needs help with code
|
Posts: 20
|
nobody knows whats wrong with code? Sry but i just started learning php and
i cant figure it out yet,so maybe someone be so kindful and help me.
big tnx 
|
|
|
|
09-18-2008, 04:18 PM
|
Re: phpnoob needs help with code
|
Posts: 843
Name: Mike
Location: United Kingdom
|
What exactly is not working about it? What I could guess (And I'm just guessing here, I didn't really look at the code) is that one of the tags has depreciated and needs updating.
__________________
My Blog/Site: Please login or register to view this content. Registration is FREE
|
|
|
|
09-19-2008, 01:39 AM
|
Re: phpnoob needs help with code
|
Posts: 20
|
Quote:
Originally Posted by rogem002
What exactly is not working about it?
|
When i try to add favorite,its not add nothing,this is not bookmark script,its add programs as favorite script,but i tested and its works on php4 server,but not on php5 server
it displays program added to favorites when i change second line like these
PHP Code:
if ($_GET['m']=='add' && $_GET['id'])
but still no programs added to favorites 
Last edited by eazy24; 09-19-2008 at 12:01 PM..
|
|
|
|
10-01-2008, 02:50 PM
|
Re: need help with code
|
Posts: 20
|
Please anybody look that code and tell me whats wrong with that,it works on php 4 but not on php5,what i need to change in code?????
PHP Code:
<?php if ($_GET['m']=='add' && strlen($id)) { $fav=$_COOKIE['favorites']; $favorites=explode('|', $fav); if(!array_search($id, $favorites)) { if(setcookie('favorites', $_COOKIE['favorites'].'|'.$id, time()+1209600)) { echo '<title>Add program</title>'; echo'<body style="font-family: Arial, Helvetica; font-size:12px">'; echo '<div style="text-align:center; color:#009900;font-weight:bold">Program added to favorites.<br><br><a href="javascript:window.close()">close window</a></div>'; } else { echo '<title>Add program</title>'; echo'<body style="font-family: Arial, Helvetica"'; echo '<div style="text-align:center; color:#ff0000;font-weight:bold">Program not added to favorites<br>Maybe your browser no accept cookies.<br><br><a href="javascript:window.close()" style="">close window</a></div>'; } } } elseif($_GET['m']=='del' && $_GET['id']) { $fav=$_COOKIE['favorites']; $favorites=explode('|', $fav); if(!strlen($favorites[0])) array_shift($favorites); $key=array_search($_GET['id'], $favorites); unset($favorites[$key]); $fav=implode('|', $favorites); setcookie('favorites', $fav, time()+1209600); header("Location: favorites.php"); } else { $PageTitle='Favourites'; require_once('config/config.php'); require_once('config/func.php'); require('config/begin.php'); ?> <script language="JavaScript"> function paystat(url) { var Win = window.open("payouts.php?id=" + url + "&m=statistic","payouts",'width=400,height=450,toolbar=0,status=0,scrollbars=1,resizable=0,menubar=0'); } </script> <table width="600" border="0" align="center"> <tr> <td> <h1>Favorites</h1> </td> </tr> <tr> <td align="center"> <?php $fav=$_COOKIE['favorites']; if(strlen($fav)) { $favorites=explode('|',$fav); if(!strlen($favorites[0])) array_shift($favorites); if (empty($_GET['p'])) $p = 1; $nawigacja=new navigation(NULL, NULL, $maxProgramsPerPageFavorite, sizeof($favorites)); $from=$nawigacja->navArray[$p]; $nawigacja->nav(); for($i=$from;$i<=($maxProgramsPerPageFavorite-1)+$from;$i++) { $favorite=$favorites[$i]; if(empty($favorite)) continue; if($result=mysql_query("SELECT `nazwa`,`url`,`rating`,`status`,`time_payout`,`total`,`forum` FROM `programs` WHERE `id_program`='$favorite'")) { if(mysql_num_rows($result)) { $row=mysql_fetch_assoc($result); ?> <table style="border-top: 1px solid #666666; border-bottom: 1px solid #666666; width:500px"> <tr> <td width="180"> <b><a href="<?php echo $row['url'] ?>" target="_blank"><?php echo $row['nazwa'] ?></a></b> <img src="gfx/icons/del.gif" width="10" height="10" align="absmiddle" style="cursor:pointer;margin-bottom:2px" onClick="window.location='favorites.php?m=del&id=<?php echo $favorite ?>'"><br> users rating: <b><?php echo $row['rating'] ?></b><br> [<a href="rate.php?id=<?php echo $favorite ?>">rate now</a>] <?php if($row['forum']!='') echo '<br><a href="'. $row['forum'] .'"><img src="gfx/icons/forum.gif" width="17" height="16" align="absmiddle" style="margin-right:5px;margin-top:3px">Visit program forum</a>'; ?> </td> <td width="165" valign="top"> <span style="color: #FF6600; font-weight:bold"><?php echo $row['time_payout'] ?></span><br> <a href="programs.php?m=details&id=<?php echo $favorite ?>">program details</a> </td> <td width="155"> status: <?php echo '<img src="gfx/icons/status_'.$row['status'].'.png" width="100" height="16" align="absmiddle">' ?><br> total payout: <b><?php echo $row['total'] ?> USD</b><br> <a href="javascript:paystat(<?php echo $favorite ?>)">payout statistic</a><br><br> </td> </tr> </table><br> <?php mysql_free_result($result); } else error("No information about program (id: $favorite)."); } else error("Error in SQL query. Cannot display program (id: $favorite)!. Please contact with administrator. "); } $nawigacja->nav(); } else { ?> <br><b>You have no favorites programs.</b><br> Click on icon <img src="gfx/icons/fav.png" width="13" height="12" align="absmiddle"> to add program to favorites.<br> You must have cookies enabled in your browser<br><br> <?php } ?> </td> </tr> </table> <?php require('config/end.php'); } ?>
|
|
|
|
10-01-2008, 04:04 PM
|
Re: phpnoob needs help with code
|
Posts: 843
Name: Mike
Location: United Kingdom
|
try:
PHP Code:
<?php if ($_GET['m']=='add' && strlen($id) == TRUE) // changed this line { $fav=$_COOKIE['favorites']; $favorites=explode('|', $fav); if(!array_search($id, $favorites)) { if(setcookie('favorites', $_COOKIE['favorites'].'|'.$id, time()+1209600)) { echo '<title>Add program</title>'; echo'<body style="font-family: Arial, Helvetica; font-size:12px">'; echo '<div style="text-align:center; color:#009900;font-weight:bold">Program added to favorites.<br><br><a href="javascript:window.close()">close window</a></div>'; } else { echo '<title>Add program</title>'; echo'<body style="font-family: Arial, Helvetica"'; echo '<div style="text-align:center; color:#ff0000;font-weight:bold">Program not added to favorites<br>Maybe your browser no accept cookies.<br><br><a href="javascript:window.close()" style="">close window</a></div>'; } } } elseif($_GET['m']=='del' && $_GET['id'] == TRUE) // changed this line { $fav=$_COOKIE['favorites']; $favorites=explode('|', $fav); if(!strlen($favorites[0])) array_shift($favorites); $key=array_search($_GET['id'], $favorites); unset($favorites[$key]); $fav=implode('|', $favorites); setcookie('favorites', $fav, time()+1209600); header("Location: favorites.php"); } else { $PageTitle='Favourites'; require_once('config/config.php'); require_once('config/func.php'); require('config/begin.php'); ?> <script language="JavaScript"> function paystat(url) { var Win = window.open("payouts.php?id=" + url + "&m=statistic","payouts",'width=400,height=450,toolbar=0,status=0,scrollbars=1,resizable=0,menubar=0'); } </script> <table width="600" border="0" align="center"> <tr> <td> <h1>Favorites</h1> </td> </tr> <tr> <td align="center"> <?php $fav=$_COOKIE['favorites']; if(strlen($fav)) { $favorites=explode('|',$fav); if(!strlen($favorites[0])) array_shift($favorites); if (empty($_GET['p'])) $p = 1; $nawigacja=new navigation(NULL, NULL, $maxProgramsPerPageFavorite, sizeof($favorites)); $from=$nawigacja->navArray[$p]; $nawigacja->nav(); for($i=$from;$i<=($maxProgramsPerPageFavorite-1)+$from;$i++) { $favorite=$favorites[$i]; if(empty($favorite)) continue; if($result=mysql_query("SELECT `nazwa`,`url`,`rating`,`status`,`time_payout`,`total`,`forum` FROM `programs` WHERE `id_program`='$favorite'")) { if(mysql_num_rows($result)) { $row=mysql_fetch_assoc($result); ?> <table style="border-top: 1px solid #666666; border-bottom: 1px solid #666666; width:500px"> <tr> <td width="180"> <b><a href="<?php echo $row['url'] ?>" target="_blank"><?php echo $row['nazwa'] ?></a></b> <img src="gfx/icons/del.gif" width="10" height="10" align="absmiddle" style="cursor:pointer;margin-bottom:2px" onClick="window.location='favorites.php?m=del&id=<?php echo $favorite ?>'"><br> users rating: <b><?php echo $row['rating'] ?></b><br> [<a href="rate.php?id=<?php echo $favorite ?>">rate now</a>] <?php if($row['forum']!='') echo '<br><a href="'. $row['forum'] .'"><img src="gfx/icons/forum.gif" width="17" height="16" align="absmiddle" style="margin-right:5px;margin-top:3px">Visit program forum</a>'; ?> </td> <td width="165" valign="top"> <span style="color: #FF6600; font-weight:bold"><?php echo $row['time_payout'] ?></span><br> <a href="programs.php?m=details&id=<?php echo $favorite ?>">program details</a> </td> <td width="155"> status: <?php echo '<img src="gfx/icons/status_'.$row['status'].'.png" width="100" height="16" align="absmiddle">' ?><br> total payout: <b><?php echo $row['total'] ?> USD</b><br> <a href="javascript:paystat(<?php echo $favorite ?>)">payout statistic</a><br><br> </td> </tr> </table><br> <?php mysql_free_result($result); } else error("No information about program (id: $favorite)."); } else error("Error in SQL query. Cannot display program (id: $favorite)!. Please contact with administrator. "); } $nawigacja->nav(); } else { ?> <br><b>You have no favorites programs.</b><br> Click on icon <img src="gfx/icons/fav.png" width="13" height="12" align="absmiddle"> to add program to favorites.<br> You must have cookies enabled in your browser<br><br> <?php } ?> </td> </tr> </table> <?php require('config/end.php'); } ?>
__________________
My Blog/Site: Please login or register to view this content. Registration is FREE
|
|
|
|
10-01-2008, 04:33 PM
|
Re: phpnoob needs help with code
|
Posts: 20
|
Quote:
Originally Posted by rogem002
try:
|
still nothing,nothing stored to favorites and wont display notice that favorite is added 
|
|
|
|
10-01-2008, 09:42 PM
|
Re: phpnoob needs help with code
|
Posts: 41
Name: Jabis Sevon
Location: Tampere, Finland
|
Just a quick thought before heading to bed;
try adding issets around your gets, lik if(isset($_GET['m']) && $_GET['m'] != "")
many many times it's gotten down to them. I'll check back here later today (4:41 am here where I live nao)
-Jabis-
|
|
|
|
10-02-2008, 05:49 AM
|
Re: phpnoob needs help with code
|
Posts: 20
|
Quote:
Originally Posted by jabis
Just a quick thought before heading to bed;
try adding issets around your gets, lik if(isset($_GET['m']) && $_GET['m'] != "")
many many times it's gotten down to them. I'll check back here later today (4:41 am here where I live nao)
-Jabis-
|
Hi,tnx for answering,i changed it like:
//favorite add line
PHP Code:
if(isset($_GET['m']) && $_GET['id'] != "add")
//favorite delete line
PHP Code:
elseif(isset($_GET['m']) && $_GET['id'] != "del")
now it displays Program added to favorites,but no programs on favorites,i know i did something wrong because i am noob on php yet,but at least i tried,so i still need your help 
tnx 
Last edited by eazy24; 10-02-2008 at 05:50 AM..
|
|
|
|
|
« Reply to phpnoob needs help with code
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|