PHP - Moved: Trouble Implementing Javascript Into Php
This topic has been moved to Ajax Help.
http://www.phpfreaks.com/forums/index.php?topic=351506.0 Similar TutorialsI registered a few days ago for help on this thread but didn't post again on it now because it has been marked answered and I thought I'd better not bump it. I received help in a way that has been the most encouraging since I began my calendar project. I'm wondering, though, if you would help me understand why I'm not successful at implementing the advice to the point that events are inserting into my calendar.
My testing database has only one table: events and in events, only two columns (other than id): "startdt" and "description". This is a screenshot of how the table's columns are set upL
screenshot.jpg 37.21KB
0 downloads
This is a screenshot of the table content:
screenshot2.jpg 9.35KB
0 downloads
This is my code with the edits added from the support thread:
<?PHP $var = mysql_real_escape_string($_GET['startdt, description']); $con=mysql_connect("localhost","user","password"); // Check connection if (mysql_connect_error()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //select a database to work with $selected = mysql_select_db("mydatabase_",$con) or die("Could not select mydatabase_"); //execute the SQL query and return records $result = mysql_query("SELECT information FROM events WHERE value='$startdt', 'description'"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo $row{'startdt, description'}; } //close the connection mysql_close($con); ?> <!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" /> <link rel="stylesheet" href="css/master.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html" /> <title>Yet Another Test</title> </head> <body> <?php $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n'); $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y'); $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0; $prevMonth = $currMonth==1 ? 12 : $currMonth-1; $nextMonth = $currMonth==12? 1 : $currMonth+1; $prevYear = $currMonth==1 ? $currYear-1 : $currYear; $nextYear = $currMonth==12? $currYear+1 : $currYear; $day1 = mktime(0,0,0,$currMonth,1,$currYear); $dim = date('t', $day1); $dayN = mktime(0,0,0,$currMonth,$dim,$currYear); $dow1 = (date('w',$day1)+0) % 7; $dowN = (date('w',$dayN)+0) % 7; $calHead = date('F Y',$day1); echo <<<EOT <div class="calwrapper"> <div class="caltitle"><h1>Calendar</h1></div> <div class="container"> <div class="fnl first"></div> <div class="adjust"></div> <div class="fnl last"></div> </div> <div class="caldisplay"> <table cellspacing="0"> <tr> <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td> <td colspan="5" class="adjust">$calHead</td> <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td> </tr> <tr> <th class="we">Sun</th> <th class="wd">Mon</th> <th class="wd">Tue</th> <th class="wd">Wed</th> <th class="wd">Thu</th> <th class="wd">Fri</th> <th class="we">Sat</th> </tr> <tr> EOT; for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>"; $c = $dow1; for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>'; echo "</tr></table>\n"; echo '</div></div>'; // calander entries. Use the date as the key (in YYYY/MM/DD format) $entries = array( '2014/8/16' => array( 'Event', ), ); for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } // construct the date, this will be used to check to if the key exists in the $entries array $dateKey = "$currYear/$currMonth/$d"; // check if the key exists in the $entries array if(array_key_exists($dateKey, $entries)) { // for each event, list it in a seperate tool tip foreach($entries[$dateKey] as $entry) { echo '<div class="has-tooltip"> Event <span class="tooltip">'.$entry.'</span> </div>'; } } ?> </body> </html>I am not getting any errors in the PHP Code Checker (although I am receiving the notice that these functions are now deprecated): mysql_close() mysql_connect() mysql_fetch_array() mysql_query() mysql_real_escape_string() mysql_select_db() When I upload my page to the server, everything seems fine, except that no information is added to the table. When I check the page source, I see this: <!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" /> <link rel="stylesheet" href="css/master.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html" /> <title>Yet Another Test</title> </head> <body> <div class="calwrapper"> <div class="caltitle"><h1>Calendar</h1></div> <div class="container"> <div class="fnl first"></div> <div class="adjust"></div> <div class="fnl last"></div> </div> <div class="caldisplay"> <table cellspacing="0"> <tr> <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=7"> Prev </a></td> <td colspan="5" class="adjust">August 2014</td> <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=9"> Next </a></td> </tr> <tr> <th class="we">Sun</th> <th class="wd">Mon</th> <th class="wd">Tue</th> <th class="wd">Wed</th> <th class="wd">Thu</th> <th class="wd">Fri</th> <th class="we">Sat</th> </tr> <tr><!--DEBUG: year=$currYear and month=$currMonth<hr/--><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="we" > 1</td> <td class="we" > 2</td> </tr><tr><td class="wd" > 3</td> <td class="wd" > 4</td> <td class="wd" > 5</td> <td class="wd" > 6</td> <td class="wd" > 7</td> <td class="we" > 8</td> <td class="we" > 9</td> </tr><tr><td class="wd" > 10</td> <td class="wd" > 11</td> <td class="wd" > 12</td> <td class="wd" > 13</td> <td class="wd" > 14</td> <td class="we" style='padding: 0px;'> 15</td> <td class="we" > 16</td> </tr><tr><td class="wd" > 17</td> <td class="wd" > 18</td> <td class="wd" > 19</td> <td class="wd" > 20</td> <td class="wd" > 21</td> <td class="we" > 22</td> <td class="we" > 23</td> </tr><tr><td class="wd" > 24</td> <td class="wd" > 25</td> <td class="wd" > 26</td> <td class="wd" > 27</td> <td class="wd" > 28</td> <td class="we" > 29</td> <td class="we" > 30</td> </tr><tr><td class="wd" > 31</td> <td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td></tr></table> </div></div></body> </html>I don't have an understanding of what the Debug is telling me although I note the number "1" within the tag and find that interesting because on those occasions, earlier today, when the file upload would result in a white page, viewing the page source would reveal nothing but the numeral "1" in the upper left top. Are the deprecated functions enough to cause the event not to insert into the calendar? I'd appreciate any help in sorting why I'm not succeeding. As you see so often around here, I'm not a coder. I'm just forced into a position to have to fend for myself, as of late, and so I'm trying to learn what I can. Thank you for any help. Edited by Izzy-B, 15 August 2014 - 07:24 PM. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=358005.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=342058.0 This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=321684.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=306321.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=330011.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=322457.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=349151.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319295.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=351914.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313679.0 So I want to implement the concept of "entitlements" on my website for articles, but am unsure of the most efficient way to code things. @Barand looked at and was okay with my table structure, but my question deal with PHP... Here is a basic ERD of the relevant tables... MEMBER >|-------||- MEMBERSHIP_PLAN -||-------|< MEMBESHIP_PLAN_VERSION -||-------|< ENTTLEMENT >0-------||- ARTICLE
Up until now, the user would click on an Article link, and my "article.php" script would grab the Category, Sub-Category and Article slug from the URL, and go look for the particular instance of the Article in MySQL. But now I want to control who can see what - that is only Members at a certain paid level can see "premium" content.
Here are my tables...
MEMBERSHIP_PLAN - id - name
MEMBERSHIP_PLAN_VERSION - id - plan_id - version_no - start_date - end_date
ENTITLEMENT - id - plan_id - version_id -article_id
ARTICLE - id - slug - title - body
And here is how I am thinking of approaching things, but would appreciate your thoughts...
- Member clicks on a link to the article: "How to use Indexes to Tune MySQL" - article.php loads and grabs the category/Sub-Category/Slug from the URL **new** - call getMembershipPlan( ) which grabs memberID from $_SESSION, queries MySQL , and returns "Membership Plan" - call getMembershipPlanVersion( ) which takes the Member's "Membership Plan", queries MySQL, and returns current/latest version - call getArticleEntitlement( ) which takes "Membership Plan", "Membership Plan Version" and "Article Slug", queries MySQL, and returns TRUE if this member is "entitled" to view the chosen Article **end of new** - Take "Category", "Sub-Category' and "Article Slug", query MySQL, and return Article and related metadata - Populate Article on page, OR display error: "This article is only available to Premium Members..."
What do you think about this approach?
Is it a sin to have 3 PHP functions and make 3 calls to MySQL? (This relates to my last thread asking about how much to store in my SESSION variable.
Edited February 18, 2020 by SaranacLake I am trying to write a PHP script that implements the MD5 algorithm just so that I can better understand MD5's inner-workings. For those of you already familiar with how MD5 works, could you help me figure out why my script is not producing the correct output? <?php $string = ""; $a = "01100111010001010010001100000001"; // 0x67452301 $b = "11101111110011011010101110001001"; // 0xEFCDAB89 $c = "10011000101110101101110011111110"; // 0x98BADCFE $d = "00010000001100100101010001110110"; // 0x10325476 $aa = $a; $bb = $b; $cc = $c; $dd = $d; // PADDED BINARY FOR NULL STRING, I.E.: "" $binary_md5 = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; $binary_md5_words = strlen($binary_md5) / 32; // SPLIT BINARY INTO 16 32-BIT WORDS for($i = 1; $i <= $binary_md5_words; $i++) { $m[] = substr($binary_md5, ($i - 1) * 32, 32); } // GENERATE T-VALUES for($i = 0; $i < 64; $i++) { $T[] = Pad(decbin(floor(4294967296 * abs(sin($i+1)))), 32); } /* // PRINT THE M[K] ARRAY echo "<h1>m[k] Array</h1><br>"; print_r($m); echo "<br><br>"; // PRINT THE T[t] ARRAY echo "<h1>T[t] Array</h1><br>"; print_r($T); echo "<br><br>"; // TEST ANDxy echo "<h1>Test ANDxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo ANDxy($m[0], $T[0]); echo "<br><br>"; // TEST ORxy echo "<h1>Test ORxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo ORxy($m[0], $T[0]); echo "<br><br>"; // TEST ADDxy echo "<h1>Test ADDxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo ADDxy($m[0], $T[0]); echo "<br><br>"; // TEST XORxy echo "<h1>Test XORxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo XORxy($m[0], $T[0]); echo "<br><br>"; // TEST NOTx echo "<h1>Test NOTx</h1><br>"; echo "$m[0]<br>"; echo NOTx($m[0]); echo "<br><br>"; // TEST SHIFTleft echo "<h1>Test SHIFTleft</h1><br>"; echo "$m[0]<br>"; echo SHIFTleft($m[0], 1); echo "<br><br>"; // TEST F echo "<h1>Test F</h1><br>"; echo "X = $m[0]<br>Y = $m[1]<br>Z = $m[2]<br>F = "; echo F($m[0], $m[1], $m[2]); $step1 = ANDxy($m[0], $m[1]); $step2 = ANDxy(NOTx($m[0]), $m[2]); $step3 = ORxy($step1, $step2); echo "<br>F = $step3"; echo "<br><br>"; // TEST H echo "<h1>Test H</h1><br>"; echo "X = $m[0]<br>Y = $m[1]<br>Z = $m[2]<br>F = "; echo H($m[0], $m[1], $m[2]); echo "<br><br>"; */ // ROUND 1 $a = ff($a, $b, $c, $d, $m, 0, 7, $T[0]); $d = ff($d, $a, $b, $c, $m, 1, 12, $T[1]); $c = ff($c, $d, $a, $b, $m, 2, 17, $T[2]); $b = ff($b, $c, $d, $a, $m, 3, 22, $T[3]); $a = ff($a, $b, $c, $d, $m, 4, 7, $T[4]); $d = ff($d, $a, $b, $c, $m, 5, 12, $T[5]); $c = ff($c, $d, $a, $b, $m, 6, 17, $T[6]); $b = ff($b, $c, $d, $a, $m, 7, 22, $T[7]); $a = ff($a, $b, $c, $d, $m, 8, 7, $T[8]); $d = ff($d, $a, $b, $c, $m, 9, 12, $T[9]); $c = ff($c, $d, $a, $b, $m, 10, 17, $T[10]); $b = ff($b, $c, $d, $a, $m, 11, 22, $T[11]); $a = ff($a, $b, $c, $d, $m, 12, 17, $T[12]); $d = ff($d, $a, $b, $c, $m, 13, 12, $T[13]); $c = ff($c, $d, $a, $b, $m, 14, 17, $T[14]); $b = ff($b, $c, $d, $a, $m, 15, 22, $T[15]); // ROUND 2 $a = gg($a, $b, $c, $d, $m, 1, 5, $T[16]); $d = gg($d, $a, $b, $c, $m, 6, 9, $T[17]); $c = gg($c, $d, $a, $b, $m, 11, 14, $T[18]); $b = gg($b, $c, $d, $a, $m, 0, 20, $T[19]); $a = gg($a, $b, $c, $d, $m, 5, 5, $T[20]); $d = gg($d, $a, $b, $c, $m, 10, 9, $T[21]); $c = gg($c, $d, $a, $b, $m, 15, 14, $T[22]); $b = gg($b, $c, $d, $a, $m, 4, 20, $T[23]); $a = gg($a, $b, $c, $d, $m, 9, 5, $T[24]); $d = gg($d, $a, $b, $c, $m, 14, 9, $T[25]); $c = gg($c, $d, $a, $b, $m, 3, 14, $T[26]); $b = gg($b, $c, $d, $a, $m, 8, 20, $T[27]); $a = gg($a, $b, $c, $d, $m, 13, 5, $T[28]); $d = gg($d, $a, $b, $c, $m, 2, 9, $T[29]); $c = gg($c, $d, $a, $b, $m, 7, 14, $T[30]); $b = gg($b, $c, $d, $a, $m, 12, 20, $T[31]); // ROUND 3 $a = hh($a, $b, $c, $d, $m, 5, 4, $T[32]); $d = hh($d, $a, $b, $c, $m, 8, 11, $T[33]); $c = hh($c, $d, $a, $b, $m, 11, 16, $T[34]); $b = hh($b, $c, $d, $a, $m, 14, 23, $T[35]); $a = hh($a, $b, $c, $d, $m, 1, 4, $T[36]); $d = hh($d, $a, $b, $c, $m, 4, 11, $T[37]); $c = hh($c, $d, $a, $b, $m, 7, 16, $T[38]); $b = hh($b, $c, $d, $a, $m, 10, 23, $T[39]); $a = hh($a, $b, $c, $d, $m, 13, 4, $T[40]); $d = hh($d, $a, $b, $c, $m, 0, 11, $T[41]); $c = hh($c, $d, $a, $b, $m, 3, 16, $T[42]); $b = hh($b, $c, $d, $a, $m, 6, 23, $T[43]); $a = hh($a, $b, $c, $d, $m, 9, 4, $T[44]); $d = hh($d, $a, $b, $c, $m, 12, 11, $T[45]); $c = hh($c, $d, $a, $b, $m, 15, 16, $T[46]); $b = hh($b, $c, $d, $a, $m, 2, 23, $T[47]); // ROUND 4 $a = ii($a, $b, $c, $d, $m, 0, 6, $T[48]); $d = ii($d, $a, $b, $c, $m, 7, 10, $T[49]); $c = ii($c, $d, $a, $b, $m, 14, 15, $T[50]); $b = ii($b, $c, $d, $a, $m, 5, 21, $T[51]); $a = ii($a, $b, $c, $d, $m, 12, 6, $T[52]); $d = ii($d, $a, $b, $c, $m, 3, 10, $T[53]); $c = ii($c, $d, $a, $b, $m, 10, 15, $T[54]); $b = ii($b, $c, $d, $a, $m, 1, 21, $T[55]); $a = ii($a, $b, $c, $d, $m, 8, 6, $T[56]); $d = ii($d, $a, $b, $c, $m, 15, 10, $T[57]); $c = ii($c, $d, $a, $b, $m, 6, 15, $T[58]); $b = ii($b, $c, $d, $a, $m, 13, 21, $T[59]); $a = ii($a, $b, $c, $d, $m, 4, 6, $T[60]); $d = ii($d, $a, $b, $c, $m, 11, 10, $T[61]); $c = ii($c, $d, $a, $b, $m, 2, 15, $T[62]); $b = ii($b, $c, $d, $a, $m, 9, 21, $T[63]); $a = ADDxy($a, $aa); $b = ADDxy($b, $bb); $c = ADDxy($c, $cc); $d = ADDxy($d, $dd); // ECHO RESULTS echo "<h1>String</h1><br>"; echo "String: '$string'<br>"; $md5 = md5($string); echo "MD5: $md5<br><br>"; $md5_1 = substr($md5, 0, 8); $md5_2 = substr($md5, 8, 8); $md5_3 = substr($md5, 16, 8); $md5_4 = substr($md5, 24, 8); echo "A = $md5_1<br>B = $md5_2<br>C = $md5_3<br>D = $md5_4<br><br>"; $md5_bin_a = Pad(decbin(hexdec($md5_1)), 32); $md5_bin_b = Pad(decbin(hexdec($md5_2)), 32); $md5_bin_c = Pad(decbin(hexdec($md5_3)), 32); $md5_bin_d = Pad(decbin(hexdec($md5_4)), 32); echo "A = $md5_bin_a<br>B = $md5_bin_b<br>C = $md5_bin_c<br>D = $md5_bin_d<br><br>"; echo "<h1>Results</h1><br>"; echo "A = $a<br>B = $b<br>C = $c<br>D = $d<br><br>"; $a_dec = bindec($a); $b_dec = bindec($b); $c_dec = bindec($c); $d_dec = bindec($d); $a_hex = dechex($a_dec); $b_hex = dechex($b_dec); $c_hex = dechex($c_dec); $d_hex = dechex($d_dec); echo "A = $a_hex<br>B = $b_hex<br>C = $c_hex<br>D = $d_hex<br><br>"; // FUNCTIONS function ff($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, F($b, $c, $d)), $m[$k]), $t), $s)); } function gg($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, G($b, $c, $d)), $m[$k]), $t), $s)); } function hh($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, H($b, $c, $d)), $m[$k]), $t), $s)); } function ii($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, I($b, $c, $d)), $m[$k]), $t), $s)); } function F($X, $Y, $Z) { //return ($X & $Y) | ((~$X) & $Z); return ORxy(ANDxy($X, $Y), ANDxy(NOTx($X), $Z)); } function G($X, $Y, $Z) { //return ($X & $Z) | ($Y & (~$Z)); return ORxy(ANDxy($X, $Z), ANDxy($Y, NOTx($Z))); } function H($X, $Y, $Z) { //return $X ^ $Y ^ $Z; return XORxy(XORxy($X, $Y), $Z); } function I($X, $Y, $Z) { //return $Y ^ ($X | (~$Z)); return XORxy($Y, ORxy($X, NOTx($Z))); } function Pad($binary, $pad_length) { $pad_length = $pad_length - strlen($binary); for($i = 0; $i < $pad_length; $i++) { $padding .= '0'; } return $padding . $binary; } function mod($val, $div) { $r = $val - (floor($val/$div)*$div); return $r; } function ANDxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = $x_dec & $y_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function ORxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = $x_dec | $y_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function ADDxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = mod($x_dec + $y_dec, pow(2, 32)); $result = Pad(decbin($result), strlen($x)); return $result; } function XORxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = $x_dec ^ $y_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function NOTx($x) { $x_dec = bindec($x); $result = ~$x_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function SHIFTleft($x, $y) { $x_dec = bindec($x); $result = $x_dec << $y; $result = Pad(decbin($result), strlen($x)); return $result; } function SHIFTright($x, $y) { $x_dec = bindec($x); $result = $x_dec >> $y; $result = Pad(decbin($result), strlen($x)); return $result; } ?> Can someone help me please?.... I'm using this Code: [Select] <form name="form1" method="post" action="create-b.php" enctype="application/x-www-form-urlencoded" style="margin:0px"> <input name="name" value="Anonymous" type="text" MAXLENGTH="15" style="position:absolute;width:650px;left:67px;top:142px;z-index:4"> <input name="subject" value="(No subject)" MAXLENGTH="15" type="text" style="position:absolute;width:650px;left:67px;top:166px;z-index:5"> <textarea name="body" MAXLENGTH="255" type="text" style="position:absolute;left:67px;top:191px;width:650px;height:98px;z-index:6"></textarea> <div id="captcha" style="position:absolute; overflow:hidden; left:10px; top:296px; z-index:8"> <input name="submit" type="submit" value="Create thread" style="position:absolute;left:614px;top:291px;z-index:7"> <?php require_once('captc/recaptchalib.php'); $publickey = "**************************************"; echo recaptcha_get_html($publickey); ?> </form>On the HTML side and this require_once('captc/recaptchalib.php'); $privatekey = "************************"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("<font color='red'><font size='12'><strong><center>The verification code you entered appears to be incorrect!"); } else { CONTENT CONTENT CONTENT CONTENT CONTENT ETC But it always returns "The verification code you entered appears to be incorrect!" Any idea what I'm doing wrong?... I am trying to implement what I call private uploads. Basically, users can check a box to indicate they want their file "private" If so, the upload location is then (exampled as): _domain_/private-folder/$randomfolder Upon uploading their file, the random folder is created, their file moved to the directory, the upload information stored to the database, .htaccess file is created like so: info to add to new .htaccess: Code: [Select] <files "*.*"> Deny from All </files> <files "*.*"> Allow from $domains </files> the string $domains is the domains they enter each seperated by a new line in a form textarea. The problem - how can I make sure this is safe. i.e. I want the string to be obviously proofed with php so that no matter what they input, only domains will be outputted. I don't need code written for me (maybe), I'm just unsure of the necessary methods I should use. So I'm implementing a ratings system into my site, the problem here though is my WHILE loop for the voting part of the rating system seems to be bugged. The SQL queries that are used for this script work, the problem seems to be that the $rating variable used to start the while loop never seems to contain anything - I've tried echoing it to confirm this fact. Can anyone see what I've done wrong in this script? Code: [Select] <?php include 'connect.php'; session_start(); $_SESSION['username']; $username = $_SESSION['username']; $member = $_GET['usr']; if(!(isset($_SESSION['login']) && $_SESSION['login']!= " ")){ header("Location: login.php"); } $tablename = 'usr_test'; $sql1 = "SELECT * FROM $tablename WHERE usr = '$member'"; $result1 = mysql_query($sql1) or die (mysql_error()); $display = mysql_fetch_row($result1); $newline = "\n"; ?> <html> <h1>User Profile</h1> <body> <div ="userprofile"> Username: <?php echo $member; ?> <br></br> Email: <?php echo $display[3]; ?> <br></br> University: <?php echo $display[4];?> <br></br> Subject: <?php echo $display[5];?> <br></br> </div> <div ="rating"> <?php while($rating = mysql_fetch_array($result1)) { if ($rating['rating'] != 0) $curr = $rating['total'] / $rating['rating']; else $curr = 0; echo "Rating: ". round($curr, 1) . "<br>"; echo "Rate this seller: "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =1&id =".$rating[usr].">Vote 1</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =2&id=".$rating[usr].">Vote 2</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =3&id=".$rating[usr].">Vote 3</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode =vote & voted =4&id=".$rating[usr].">Vote 4</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =5&id=".$rating[usr].">Vote 5</a><p>"; } ?> </div> <div> </html> Hello. Through MySQL, I created a database using the following code: Code: [Select] create database auth; use auth; create table authorized_users ( name varchar(20), password varchar(40), primary key (name) ); insert into authorized_users values ( 'username', 'password' ); insert into authorized_users values ( 'testuser', sha1('password') ); grant select on auth.* to 'webauth' identified by 'webauth'; flush privileges; Then I used the following code to set up a simple log in page. Code: [Select] <?php $name = $_POST['name']; $password = $_POST['password']; if ((!isset($name)) || (!isset($password))) { //Visitor needs to enter a name and password ?> <h1>Please Log In</h1> <p>This page is secret.</p> <form method="post" action="secretdb.php"> <p>Username: <input type="text" name="name"></p> <p>Password: <input type="password" name="password"></p> <p><input type="submit" name="submit" value="Log In"></p> </form> <?php } else { // connect to mysql $mysql = mysqli_connect("localhost", "webauth", "webauth"); if(!$mysql) { echo "Cannot connect to database."; exit; } // select the appropriate database $selected = mysqli_select_db($mysql, "auth"); if(!$selected) { echo "Cannot select database."; exit; } // query the database to see if there is a record which matches $query = "select count(*) from authorized_users where name = '".$name."' and password = sha1('".$password."')"; $result = mysqli_query($mysql, $query); if(!$result) { echo "Cannot run query."; exit; } $row = mysqli_fetch_row($result); $count = $row[0]; if ($count > 0) { // visitor's name and password combination are correct echo "<h1>Here it is!</h1> <p>I bet you are glad you can see this secret page.</p>"; } else { // visitor's name and password combination are not correct echo "<h1>Go Away!</h1> <p>You are not authorized to use this resource.</p>"; } } ?> When I open up this page, above "Please Log In", I get this error: Notice: Undefined index: name in C:\xampp\htdocs\learning\secretdb.php on line 2 Notice: Undefined index: password in C:\xampp\htdocs\learning\secretdb.php on line 3 Moreover, when I type in an authorized username and password, I get another error: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'webauth'@'localhost' (using password: YES) in C:\xampp\htdocs\learning\secretdb.php on line 19 Cannot connect to database. Does anyone know what I'm doing wrong? I'm fairly new to PHP and MySQL and I'm pretty stuck. Thanks. Hey sup guys i need help Implementing top 10 users script into index.php. I got a screen shot of where it needs to go. I need to Implement it so its inside the grey container as in the picture. Here is the php for the top 10 users : Code: [Select] <span style="float:right;"> <table width="200"> <tr><td colspan="2" align="center">TOP 10 USERS</td></tr> <tr><td align="left"><b>Username<b></td><td align="left"><b>Points</b></td></tr> <?php $i=0; if($num>0){ while ($i < $num) { $username6=mysql_result($result4,$i,"username"); $points6=mysql_result($result4,$i,"points"); $i++; echo "<tr><td>".$username6."</td><td>".$points6."</td></tr>"; Here is the image file for the graphic : Code: [Select] <table width="165" height="236" bgcolor="#FFFFFF" td background="images/tablebg.png" > And here is the index.php : Code: [Select] <? session_start(); include_once"config.php"; if(isset($_POST['login'])){ $username= trim($_POST['username']); $password = trim($_POST['password']); if($username == NULL OR $password == NULL){ $final_report.="Please complete both fields"; }else{ $check_user_data = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error()); if(mysql_num_rows($check_user_data) == 0){ $final_report.="This username does not exist"; }else{ $get_user_data = mysql_fetch_array($check_user_data); if($get_user_data['password'] == $password){ $start_idsess = $_SESSION['username'] = "".$get_user_data['username'].""; $start_passsess = $_SESSION['password'] = "".$get_user_data['password'].""; $final_report.="<meta http-equiv='Refresh' content='0; URL=members.php'/>"; }}}} if(isset($_SESSION['username']) && isset($_SESSION['password'])){ header("Location: members.php"); } ?> <?php include("includes.php");?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo $title ?> | #1 Spot for Free Paid Surveys</title> <link rel="shortcut icon" href="favicon.ico" > <link rel="icon" type="image/gif" href="animated_favicon1.gif" > <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="Get free vouchers for online stores such as Amazon, ASOS, iTunes and more. It takes a few seconds to get started. Register now to start shopping for free." /> <link rel="stylesheet" href="style.css" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/script.js"></script> <script type="text/javascript" src="js/dimensions.min.js"></script> <script type="text/javascript" src="js/func.js"></script> <script type="text/javascript" src="js/SHA1.js"></script> <script>var _wau = _wau || []; _wau.push(["tab", "72vlo7dmnb8j", "w12", "bottom-center"]);(function() { var s=document.createElement("script"); s.async=true; document.getElementsByTagName("head")[0].appendChild(s);})();</script> <style> #logoPart { background:#000; height:90px;} #bannerTD { width:900px; height:85px; background-color:#333; background-repeat: no-repeat;} #bannerTD #bannerContainer { width:900px; height:325px; text-align:center;} #bannerTD #bannerContainerCover { width:900px; height:325px; text-align:center;} #bannerTD #bannerBody { height:245px; text-align:center;} #bannerTD #bannerFooter { position: relative; background:#000; height:80px; display:none; width:900px; top: -39px; /* 1x the distance of the footer used to be 78 */ } #bannerTD #bannerFooterNav { position: relative; border: 1px solid grey; top: -117px; /* 2x the distance of the footer used to be 156*/ } .footerCell{ padding:5px; text-align:left; border:0px #F90 solid;} .footerCell .footerTitle {font-family:tahoma, arial; font-size:11px; color:#fff; font-weight: bold;} .footerCell .footerDesc {font-family:tahoma, arial; font-size:11px; color:#efefef;} .footerCell ul {list-style: none; margin: 2px; margin-left: 75px; padding-left: 10px;} .footerCell ul li {margin: 2px; line-height: 13px; padding: 0;} .footerLink {text-align: right;} .footerCell .imgDiv{ position:relative; float:left; width:80px; height:65px; margin: 2px 1px 0px 1px;} .bttnMore {width:57px; height:19px; float: right;} .bttnMore a{display: block; background:url(images/welcome-banner/gen/bttn_more_small.png) 0 0 no-repeat; line-height: 19px; text-decoration: none;} .imgBgDiv_i { width:82px; height:67px; //background: url(images/welcome-banner/gen/thumbBgBordered.png) 0 0 no-repeat; padding: 0; float:left; } </style> </head> <body> <body id="exterior"> <div id="body-bg"> </div> <div id="container"> <div id="header"> <a href="index.php<?php echo $referral_string?>"> <div id="logo"> </div></a><!--end of logo--> <div id="updates"> <span> </span> </div><!--end of updates--> <div id="login"> <div id="loginwelcome"> <?php if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ ?> <?php if($final_report !=""){?> <font color="red"><? echo $final_report;?></font> <?php }else { ?>Welcome Guest, not a member? <a href="register.php<?php echo $referral_string?>"><b>Register Now!</b></a> <?php } ?> </div><!--end of loginwelcome--> <form action="" method="post"> <p> <input type="text" title="username" name="username" class="username" value="Username" onclick="if ( value == 'Username' ) { value = ''; }"/> <input name="password" type="password" class="password" title="password" value="Password" onclick="if ( value == 'Password' ) { value = ''; }"/> <input type="Submit" name="login" class="submit" value="login" tabindex="3" /> </p> </form> </div><!--end of login--> <?php } ?> <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])){ ?> <table> <tr> <td> Welcome <b><?php echo $membername ?></b> </td> </tr> <tr> <td align="right" width="310"> Total Points: <b><?php echo $memberpoints ?></b><br> <?php if ($pointsneeded<=0){ ?> You can now request a reward!<?php }else { ?> Points Needed: <b><?php echo $pointsneeded ?> <?php } ?> </b><br> </td> </tr> </table> </div> <!--end of header--> <?php } ?> <div id="navigation"> <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])){ ?> <table id="navi-items"> <tr><td> <div class="navi-item navi-item-selected"> <div class="navi-heading navi-heading-selected"> <a href="index.php"><img src="images/home.png" alt="Home" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="vouchers.php"><img src="images/rewards.png" alt="Rewards" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="testimonials.php"><img src="images/testimonials.png" alt="Testimonials" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="terms.php"><img src="images/terms.png" alt="Terms" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="help.php"><img src="images/help.png" alt="Help" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="contact.php"><img src="images/contact-us.png" alt="Contact Us" /></a> </div> </div> </td></tr> </table> <?php }else { ?> <table id="navi-items"> <tr><td> <div class="navi-item navi-item-selected"> <div class="navi-heading navi-heading-selected"> <a href="index.php"><img src="images/home.png" alt="Home" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="vouchers.php"><img src="images/rewards.png" alt="Rewards" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="testimonials.php"><img src="images/testimonials.png" alt="Testimonials" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="terms.php"><img src="images/terms.png" alt="Terms" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="help.php"><img src="images/help.png" alt="Help" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="contact.php"><img src="images/contact-us.png" alt="Contact Us" /></a> </div> </div> </td></tr> </table> <?php } ?> </div><!--end of navigation--> <!-- ______________________ BANNER ___________________--> <tr><td id="bannerTD"> <div id="bannerContainer"> <div id="bannerBody"> <br /><img src="images/banner.png" border="0" alt="Banner" /> </div> </div> <a href="register.php"><img src="images/signup.png" /></a> <a href="points.php"><img src="images/earn.png" /></a> <a href="vouchers.php"><img src="images/get.png" /></a> </td></tr> <!-- ______________________ /BANNER ___________________--> <div id="contents-top"></div> <div id="contents"> <div class="content-block"> <h1>How does <?php echo $title?> work?</h1><br><br> <a href="register.php<?php echo $referral_string?>"><center><img src="images/step1.png" border="0"><img src="images/step1a.png" border="0"></a><a href="points.php<?php echo $referral_string?>"><img src="images/step2.png" border="0"><img src="images/step2a.png" border="0"><a href="vouchers.php<?php echo $referral_string?>"><img src="images/step3.png" border="0"></center></a> <br> <br> <p> It's easy to use your free time to earn <a href="vouchers.php<?php echo $referral_string?>"><b>rewards</b></a>. While you certainly won't get rich quick or instantly win prizes, if you put in a bit of effort you can earn whatever you want! You can redeem points for online goods or for vouchers such as Amazon, iTunes, ASOS and Xbox Live, the choice is yours. <br><br> While you learn about new products, share information about yourself, or sign up for online services, you earn points. While MOST OFFERS ARE FREE, you will also find cashback shopping and paid/trial offers - a great way to get a deal on your online purchases! <br><br> </p> <h1>Just 3 steps to success!</h1> <p><br> 1. <b>Register:</b> The sign up process takes about 10 seconds, and we'll even give you <font color=#fcbc0c><b><?php echo $bonuspoints ?> FREE BONUS POINTS</b></font> when you <a href="register.php<?php echo $referral_string?>"><b>register</b></a>.<br><br> 2. <b>Earn points:</b> To be able to offer our users FREE gift vouchers to use at online stores such as Amazon and ASOS, you need to earn points. Earning these points are FREE, and you just need to complete a few surveys to get enough points to claim a free voucher. You can also earn points by signing up to some trial offers, but we recommend you stick to the free surveys for now.<br><br> 3. <b>Get Rewards:</b> Once you have earned <?php echo $mainpointsneeded ?> points on <?php echo $title?> you can swap them for REAL products or vouchers, which can be used at online stores/communities. Basically, you can request ANY product or voucher, as long as we can buy it online and send to you via email or shipping. On top of this, if you wish to have something custom ordered, feel free to tell us something what it is and we can always help you out! The rewards you can receive are endless........ </p> <h1>What are points worth?</h1> <p> <br> 10 points = $1.00/£0.50<br> 50 points = $5.00/£2.50<br> 100 points = $10.00/£5.00<br> 200 points = $20.00/£10.00 <br><br> You need <?php echo $mainpointsneeded ?> points before you can redeem them for <a href="vouchers.php<?php echo $referral_string?>">rewards</a>. <br> </p> <h1>How do I know Simple Rewards is legit?</h1> <p>There's no doubt that in today's world fake companies are everywhere. So how do you know Simple Rewards is, in fact, legit? To start, Simple Rewards has already paid out over $10,000 in the last month. This shows not only that we are a legitimate business but also that we are a very active one. If you would like to see more proof of our legitimacy, feel free to check out our <a href="testimonials.php">Testimonials </a> section and read some of the latest testimonials written by Simple Rewards users! </p> <br /> <h1>Reward Ideas</h1> <p> <br /> <img src="images/ps3.png"> <img src="images/giftcards.png"> <img src="images/ipodtouch.png"> </p> <p><center> <p><a href="index.php"><img src="images/largebanner.gif" /><hr width="75%"> <script type=text/javascript language=JavaScript src=http://www.linkreferral.com/networkads2.pl?refid=341046&height=1&width=3&category=money making opportunities&subcategory=services ></script></a></p> </center></p> </div><!--end of contentblock--> </div><!--end of contents--> <div id="contents-bottom"></div> </div><!--end of container--> </div> <?php include("footer.php");?> This question is PHP and javascript/jQuery so I wasn't sure where to post it, but anyway... Here is the code I am using so far. Currently it just displays a larger version of the image in a new window. I would like a lighbox instead. I have tried this with "FancyBox" but couldn't get it to work on all the images, just the first one. Any suggestions? Code: [Select] <?php //GET PRODUCT VAR etc. ^^ $directory = "Images/items/$product/"; //get all image files with a .jpg extension. $images = glob($directory . "*.jpg"); $imgone = $images[0]; $gallery = ''; foreach($images as $image) { $tn = explode("/", $image); $tnname = $tn[3]; $gallery .= '<a href="#" rel="'.$image.'" class="image" title="Images/items/'.$product.'/large/'.$tnname.'" alt="'.$product.'"><img src="Images/items/'.$product.'/thumbs/'.$tnname.'" class="thumb" border="1" style="margin-bottom:7px;"/></a> '; } if(is_dir("Images/items/".$product)){ $gallery .= "<div id='image' class='bigimg' align='left'>"; $gallery .= '<a href="largeimg.php?id='.$product.'&i=Images/items/'.$product.'/large/0main_img.jpg" target="_new"> <img src="Images/items/'.$product.'/0main_img.jpg" border="0" alt='.$name.'/> <span class="more"><img src="Images/zoom.png" /></span></a></div>'; } ?> <!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><?php echo $name; ?></title> <script type="text/javascript" src="js/ddsmoothmenu.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <link href="CSS/style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="CSS/ddsmoothmenu.css" /> </head> <body> <div class="hidden"> <script type="text/javascript"> $(function() { $(".image").click(function() { var image = $(this).attr("rel"); var large = $(this).attr("title"); var product = $(this).attr("alt"); $('#image').hide(); $('#image').fadeIn('slow'); $('#image').html('<a href="largeimg.php?id='+ product +'&i=' + large + '" target="_new"><img src="' + image + '"/><span class="more"><img src="Images/zoom.png" /></span></a>'); return false; }); }); </script> I am having trouble implementing PHP inside a HTML attribute. Every time I try to fix it, I seem to make things worse. Can someone please help me: <INPUT name="id" type="text" value=""<?php echo "$row['id']"; ?>""> |