Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 16th, 2002, 03:34 PM
tek tek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 tek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to tek
mysql with php help!

Im a newbie @ myswl. I have a script that handles voting for weblinks. The problem is the it is updating one of the tables correctly but nothing in the second table.

1 The first is "links_links" this table is not being updated.

2 The second is "links_vote_data" this table is being updated.

I have looked this over and over still I cant figure it out. I didnt write this but I would love for it to work.

php Code:
Original - php Code
  1. <?php
  2. // File: $Id: wl-rating.php,v 1.18 2002/03/10 14:44:54 niceguyeddie Exp $ $Name:  $
  3. // ----------------------------------------------------------------------
  4. //
  5. //
  6. //
  7. // ----------------------------------------------------------------------
  8. //
  9. //
  10. //
  11. //
  12. // ----------------------------------------------------------------------
  13. // LICENSE
  14. //
  15. // This program is free software; you can redistribute it and/or
  16. // modify it under the terms of the GNU General Public License (GPL)
  17. // as published by the Free Software Foundation; either version 2
  18. // of the License, or (at your option) any later version.
  19. //
  20. // This program is distributed in the hope that it will be useful,
  21. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. // GNU General Public License for more details.
  24. //
  25. // To read the license please visit http://www.gnu.org/copyleft/gpl.html
  26. // ----------------------------------------------------------------------
  27. // Original Author of file: Francisco Burzi
  28. // Purpose of file:
  29. // ----------------------------------------------------------------------
  30. // 11-30-2001:ahumphr - created file as part of modularistation
  31.  
  32. /**
  33. * @usedby index
  34. */
  35. function rateinfo($lid)
  36. {
  37.     list($dbconn) = pnDBGetConn();
  38.     $pntable = pnDBGetTables();
  39.  
  40.     $column = &$pntable['links_links_column'];
  41.     $dbconn->Execute("UPDATE $pntable[links_links]
  42.                     SET $column[hits]=$column[hits]+1
  43.                     WHERE $column[lid]=".pnVarPrepForStore($lid)."");
  44.     $result = $dbconn->Execute("SELECT $column[url]
  45.                     FROM $pntable[links_links]
  46.                     WHERE $column[lid]=".pnVarPrepForStore($lid)."");
  47.     list($url) = $result->fields;
  48.     Header('Location: '.$url);
  49. }
  50.  
  51. /**
  52. *@usedby index, navigation
  53. */
  54. function addrating($ratinglid, $ratinguser, $rating, $ratinghost_name, $ratingcomments)
  55. {
  56.     list($dbconn) = pnDBGetConn();
  57.     $pntable = pnDBGetTables();
  58.  
  59.     $passtest = "yes";
  60.     include("header.php");
  61.         if (!(pnSecAuthAction(0, 'Web Links::', '::', ACCESS_READ))) {
  62.             echo _WEBLINKSNOAUTH;
  63.             include 'footer.php';
  64.             return;
  65.         }
  66.     include(WHERE_IS_PERSO."config.php");
  67.     completevoteheader();
  68.     if (pnUserLoggedIn()) {
  69.         $ratinguser = pnUserGetVar('uname');
  70.     } else if ($ratinguser=="outside") {
  71.         $ratinguser = "outside";
  72.     } else {
  73.         $ratinguser = pnConfigGetVar("anonymous");
  74.     }
  75.     $column = &$pntable['links_links_column'];
  76.     $results3 = $dbconn->Execute("SELECT $column[title]
  77.                                 FROM $pntable[links_links]
  78.                                 WHERE $column[lid]=".pnVarPrepForStore($ratinglid)."");
  79.    while(list($title)=$results3->fields)   {
  80.         $ttitle = $title;
  81.         $results3->MoveNext();
  82.     }
  83.     /* Make sure only 1 anonymous from an IP in a single day. */
  84.     $ip = getenv("REMOTE_HOST");
  85.     if (empty($ip)) {
  86.         $ip = getenv("REMOTE_ADDR");
  87.     }
  88.     /* Check if Rating is Null */
  89.     if ($rating=="--") {
  90.         $error = "nullerror";
  91.         completevote($error);
  92.         $passtest = "no";
  93.     }
  94.     /* Check if Link POSTER is voting (UNLESS Anonymous users allowed to post) */
  95.     if ($ratinguser != pnConfigGetVar("anonymous") && $ratinguser != "outside") {
  96.         $column = &$pntable['links_links_column'];
  97.         $result=$dbconn->Execute("SELECT $column[submitter]
  98.                                 FROM $pntable[links_links]
  99.                                 WHERE $column[lid]=".pnVarPrepForStore($ratinglid)."");
  100.         while(list($ratinguserDB)=$result->fields) {
  101.  
  102.             $result->MoveNext();
  103.             if ($ratinguserDB==$ratinguser) {
  104.                 $error = "postervote";
  105.                 completevote($error);
  106.                 $passtest = "no";
  107.             }
  108.         }
  109.     }
  110.     /* Check if REG user is trying to vote twice. */
  111.     if ($ratinguser != pnConfigGetVar("anonymous") && $ratinguser != "outside") {
  112.         $column = &$pntable['links_votedata_column'];
  113.         $results=$dbconn->Execute("SELECT $column[ratinguser] FROM $pntable[links_votedata] WHERE $column[ratinglid]=".pnVarPrepForStore($ratinglid)."");
  114.         while(list($ratinguserDB)=$result->fields) {
  115.  
  116.             $result->MoveNext();
  117.             if ($ratinguserDB==$ratinguser) {
  118.                 $error = "regflood";
  119.                 completevote($error);
  120.                 $passtest = "no";
  121.             }
  122.         }
  123.     }
  124.     /* Check if ANONYMOUS user is trying to vote more than once per day. */
  125.     if ($ratinguser == pnConfigGetVar("anonymous")){
  126.         $yesterdaytimestamp = (time()-(86400 * $anonwaitdays));
  127.         $ytsDB = Date("Y-m-d H:i:s", $yesterdaytimestamp);
  128.         $column = &$pntable['links_votedata_column'];
  129.         $result=$dbconn->Execute("SELECT count(*)
  130.                                 FROM $pntable[links_votedata]
  131.                                 WHERE $column[ratinglid]=".pnVarPrepForStore($ratinglid)."
  132.                                 AND $column[ratinguser]='".pnConfigGetVar("anonymous")."'
  133.                                 AND $column[ratinghostname]='".pnVarPrepForStore($ip)."'
  134.                                 AND TO_DAYS(NOW()) - TO_DAYS($column[ratingtimestamp]) < ".pnVarPrepForStore($anonwaitdays)."");
  135.         list($anonvotecount) = $result->fields;
  136.         if ($anonvotecount >= 1) {
  137.             $error = "anonflood";
  138.             completevote($error);
  139.             $passtest = "no";
  140.         }
  141.     }
  142.     /* Check if OUTSIDE user is trying to vote more than once per day. */
  143.     if ($ratinguser == "outside"){
  144.         $yesterdaytimestamp = (time()-(86400 * $outsidewaitdays));
  145.         $ytsDB = date("Y-m-d H:i:s", $yesterdaytimestamp);
  146.         $column = &$pntable['links_votedata_column'];
  147.         $result=$dbconn->Execute("SELECT count(*) FROM $pntable[links_votedata]
  148.                                 WHERE $column[ratinglid]=".pnVarPrepForStore($ratinglid)."
  149.                                 AND $column[ratinguser]='outside'
  150.                                 AND $column[ratinghostname]='".pnVarPrepForStore($ip)."'
  151.                                 AND TO_DAYS(NOW()) - TO_DAYS($column[ratingtimestamp]) < ".pnVarPrepForStore($outsidewaitdays)."");
  152.         list($outsidevotecount) = $result->fields;
  153.         if ($outsidevotecount >= 1) {
  154.             $error = "outsideflood";
  155.             completevote($error);
  156.             $passtest = "no";
  157.         }
  158.     }
  159.     /* Passed Tests */
  160.     if ($passtest == "yes") {
  161.         /* All is well.  Add to Line Item Rate to DB. */
  162.         $nextid = $dbconn->GenId($pntable['links_votedata']);
  163.         $column = &$pntable['links_votedata_column'];
  164.         $dbconn->Execute("INSERT INTO $pntable[links_votedata]
  165.                             ($column[ratingdbid], $column[ratinglid],
  166.                              $column[ratinguser], $column[rating],
  167.                              $column[ratinghostname], $column[ratingcomments],
  168.                              $column[ratingtimestamp])
  169.                              VALUES ($nextid,".pnVarPrepForStore($ratinglid).", '".pnVarPrepForStore($ratinguser)."', '".pnVarPrepForStore($rating)."',
  170.                              '".pnVarPrepForStore($ip)."', '".pnVarPrepForStore($ratingcomments)."', now())");
  171.         /* All is well.  Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. */
  172.         /* NOTE: If weight is modified, ALL links need to be refreshed with new weight. */
  173.         /*   Running a SQL statement with your modded calc for ALL links will accomplish this. */
  174.         $voteresult = $dbconn->Execute("SELECT $column[rating], $column[ratinguser],
  175.                                         $column[ratingcomments]
  176.                                         FROM $pntable[links_votedata]
  177.                                         WHERE $column[ratinglid] = ".pnVarPrepForStore($ratinglid)."");
  178.         $totalvotesDB = $voteresult->PO_RecordCount();
  179.         $finalrating = calculateVote($voteresult, $totalvotesDB);
  180.         $column = &$pntable['links_links_column'];
  181.         $dbconn->Execute("UPDATE $pntable[links_links]
  182.                         SET $column[linkratingsummary] = ".pnVarPrepForStore($finalrating).",                                                    $column[totalvotes] = ".pnVarPrepForStore($totalvotesDB).",
  183.                             $column[totalcomments]= ".pnVarPrepForStore($truecomments)."
  184.                          WHERE $column[lid]=".pnVarPrepForStore($ratinglid)."");
  185.         $error = "none";
  186.         completevote($error);
  187.     }
  188.     completevotefooter($ratinglid, $ttitle, $ratinguser);
  189.     include("footer.php");
  190. }
  191.  
  192. /*
  193. * @usedby function addrating
  194. */
  195. function completevoteheader(){
  196.     menu(1);
  197.  
  198.     OpenTable();
  199. }
  200.  
  201. function completevotefooter($lid, $ttitle, $ratinguser)
  202. {
  203.     list($dbconn) = pnDBGetConn();
  204.     $pntable = pnDBGetTables();
  205.  
  206.     $sitename = pnConfigGetVar('sitename');
  207.  
  208.     $column = &$pntable['links_links_column'];
  209.     $result=$dbconn->Execute("SELECT $column[url]
  210.                     FROM $pntable[links_links]
  211.                     WHERE $column[lid]=".pnVarPrepForStore($lid)."");
  212.     list($url)=$result->fields;
  213.     echo "<font class="pn-normal">"._THANKSTOTAKETIME." $sitename. "._LETSDECIDE."</font><br /><br /><br />";
  214.     if ($ratinguser=="outside") {
  215.         echo "<center><font class="pn-normal">".WEAPPREACIATE." ".pnVarPrepForDisplay($sitename)."!<br /><a class="pn-normal" href="".pnVarPrepForDisplay($url)."">"._RETURNTO." ".pnVarPrepForDisplay($ttitle)."</a></font><center><br /><br />";
  216.         $result=$dbconn->Execute("SELECT $column[title] FROM $pntable[links_links]
  217.                         WHERE $column[lid]=".pnVarPrepForStore($lid)."");
  218.         list($title)=$result->fields;
  219.         $ttitle = ereg_replace (" ", "_", $title);
  220.     }
  221.     echo "<center>";
  222.     linkinfomenu($lid,$ttitle);
  223.     echo "</center>";
  224.     CloseTable();
  225. }
  226.  
  227. function completevote($error) {
  228.     if ($error == "none")
  229.     {
  230.         echo "<center><font class="pn-normal"><b>"._RATENOTE1ERROR."</b></font></center>";
  231.     }
  232.     elseif ($error == "anonflood")
  233.     {
  234.         $anonwaitdays = pnConfigGetVar('anonwaitdays');
  235.         echo "<center><font class="pn-normal"><b>"._RATENOTE2ERROR."</b></font></center><br />";
  236.     }
  237.     elseif ($error == "regflood")
  238.     {
  239.         echo "<center><font class="pn-normal"><b>"._RATENOTE3ERROR."</b></font></center><br />";
  240.     }
  241.     elseif ($error == "postervote")
  242.     {
  243.         echo "<center><font class="pn-normal"><b>"._RATENOTE4ERROR."</b></font></center><br />";
  244.     }
  245.     elseif ($error == "nullerror")
  246.     {
  247.         echo "<center><font class="pn-normal"><b>"._RATENOTE5ERROR."</b></font></center><br />";
  248.     }
  249.     elseif ($error == "outsideflood")
  250.     {
  251.         $outsidewaitdays = pnConfigGetVar('outsidewaitdays');
  252.         echo "<center><font class="pn-normal"><b>Only one vote per IP address allowed every $outsidewaitdays day(s).</b></font></center><br />";
  253.     }
  254. }
  255.  
  256. /**
  257. * @usedby index
  258. */
  259. function ratelink($lid, $ttitle) {
  260.     include("header.php");
  261.         if (!(pnSecAuthAction(0, 'Web Links::', '::', ACCESS_COMMENT))) {
  262.             echo _WEBLINKSNOAUTH;
  263.             include 'footer.php';
  264.             return;
  265.         }
  266.     menu(1);
  267.  
  268.     OpenTable();
  269.     $transfertitle = ereg_replace ("_", " ", $ttitle);
  270.     $displaytitle = $transfertitle;
  271.     global $datetime, $ModName, $modurl;
  272.     $ip = getenv("REMOTE_HOST");
  273.     if (empty($ip)) {
  274.        $ip = getenv("REMOTE_ADDR");
  275.     }
  276.     echo "<font class="pn-normal"><b>".pnVarPrepForDisplay($displaytitle)."</b></font>"
  277.     ."<ul>"
  278.     ."<li><font class="pn-sub">"._RATENOTE1."</font>"
  279.     ."<li><font class="pn-sub">"._RATENOTE2."</font>"
  280.     ."<li><font class="pn-sub">"._RATENOTE3."</font>"
  281.     ."<li><font class="pn-sub">"._RATENOTE4."</font>"
  282.     ."<li><font class="pn-sub">"._RATENOTE5."</font>";
  283.     if (pnUserLoggedIn()) {
  284.         $name = pnUserGetVar('uname');
  285.         echo "<li><font class="pn-sub">"._YOUAREREGGED."</font>"
  286.             ."<li><font class="pn-sub">"._FEELFREE2ADD."</font>";
  287.     } else {
  288.         echo "<li><font class="pn-sub">"._YOUARENOTREGGED."</font>"
  289.             ."<li><font class="pn-sub">"._IFYOUWEREREG."</font>";
  290.         $name = pnConfigGetVar("anonymous");
  291.     }
  292.     echo "</ul>"
  293.         ."<form method="post" action="${modurl}&req=addrating">"
  294.         ."<table border="0" cellpadding="1" cellspacing="0" width="100%">"
  295.         ."<tr><td width="25" nowrap></td>"
  296.         ."<tr><td width="25" nowrap></td><td width="550">"
  297.         ."<input type="hidden" name="ratinglid" value="$lid">"
  298.         ."<input type="hidden" name="ratinguser" value="$name">"
  299.         ."<input type="hidden" name="ratinghost_name" value="$ip">"
  300.         ."<font class="pn-normal">"._RATETHISSITE."&nbsp;&nbsp;"
  301.         ."<select name="rating">"
  302.         ."<option>--</option>"
  303.         ."<option>10</option>"
  304.         ."<option>9</option>"
  305.         ."<option>8</option>"
  306.         ."<option>7</option>"
  307.         ."<option>6</option>"
  308.         ."<option>5</option>"
  309.         ."<option>4</option>"
  310.         ."<option>3</option>"
  311.         ."<option>2</option>"
  312.         ."<option>1</option>"
  313.         ."</select></font>"
  314.     ."<font class="pn-sub"><input type="submit" value=""._RATETHISSITE.""></font>"
  315.         ."<br /><br />";
  316.     if (pnUserLoggedIn()) {
  317.         echo "<font class="pn-normal"><b>"._COMMENTS.":</b></font><br /><textarea wrap="virtual" cols="50" rows="10" name="ratingcomments"></textarea>"
  318.             ."<br /><br /><br />"
  319.             ."</font></td>";
  320.     } else {
  321.         echo"<input type="hidden" name="ratingcomments" value="">";
  322.     }
  323.     echo "</tr></table></form>";
  324.     echo "<center>";
  325.     linkfooterchild($lid);
  326.     echo "</center>";
  327.     CloseTable();
  328.     include("footer.php");
  329. }
  330. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > mysql with php help!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek