Jump to content

alphamoment

Members
  • Posts

    31
  • Joined

  • Last visited

Everything posted by alphamoment

  1. Thank you for the reply. The 0's 1's 2's were just examples. I appreciate the responses as they have helped me greatly!
  2. I'm using this current PHP Code in my Index.php; <?php $page = $_GET['page']; if (!isset($page)) { include('home.php'); } if ($page == "Home") { include('home.php'); } if ($page == "0101") { include('0101.php'); } if ($page == "0202") { include('0202.php'); } ?> Then I'm using this for my Navigation link; <li><a href="?page=0101">Members</a></li> Which displays as index.php?page=0101 But on those pages I want to go into another page off of them, for example; index.php?page=0101&subpage=0102 index.php?page=0202&subpage=0201 How can I achieve this?
  3. Hi I'm using PHP for my Navigation Menu, My navbar is in a file named "home.php" looks like this: <ul class="nav navbar-nav navbar-right"> <li><a href="?page=home">Home</a></li> <li><a href="?page=about">About</a></li> <li><a href="?page=services">Services</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="?page=service2">Service 2</a></li> </ul> </ul> Then in my index.php: $page = $_GET['page']; if (!isset($page)) { include('home.php'); } if ($page == "home") { include('home.php'); } if ($page == "about") { include('about.php'); } if ($page == "services") { include('services.php'); } if ($page == "service2") { include('service2.php'); } It all works how I want it to except for one thing; I'd like to add; <li class="active"> To the page that is currently being viewed. How can I do this? Thank you in advance.
  4. Got it! Barand MVP. I really appreciate your help, Thank you once again.
  5. That's a lot cleaner thanks! If I wanted to limit the results to 50 rows being displayed how can I come about that? (Sorry for all the questions)
  6. Haha, thanks! Works perfect, Thank you so much Barand. One last question; for the echo I've used $row['COUNT(t1.ID)'] How can I get it to ORDER BY the highest count descending ORDER BY t1.COUNT(t1.ID) DESC This doesn't seem to do the trick! Edit: I got it working using; ORDER BY COUNT(*) DESC Thank you!
  7. Hello Barand, Thanks for the quick reply. I've tried your Query and the results displayed only 1 row ID COUNT 4017 85 Not quite sure how it got 85 when there is only 3 listings for ID 4017. Hmmmm
  8. Hello. I'm trying to get this piece of code finished but it's not going my way, if anyone could help me out that would be great. Here whats I'm trying to do: Table1 Table2 ---------------- --------------------------------- ID | | PlayerID | PlayerName | ---------------- -------------------------------- 1393 | | 1393 | Player1 | 2097 | | 2097 | Player2 | 3888 | | 3888 | Player3 | 3888 | | 4017 | Player4 | 3888 | --------------------------------- 4017 | 4017 | 4017 | ---------------- I Want to Count the entries in Table1 (3888 has 3 entries so it will display like "3888: 3") Then I want to join Table1 and Table2 using the ID so I can get the players name (3888=Player3 so it would display like Player3 : 3) Here's the code I'm using: <?php //connect to db $query = "SELECT * FROM Table1 INNER JOIN Table2 WHERE Table1.PlayerID = Table2.ID"; $query2 = "SELECT ID, SUM(ID=0) AS n0, SUM(ID=1) AS n1, COUNT(*) AS total FROM Table1 GROUP BY ID"; $result = mysql_query($query) or die($query."<br/><br/>".mysql_error()); $result2 = mysql_query($query2) or die($query2."<br/><br/>".mysql_error()); echo "<table border='1'> <tr> <th>PlayerName</th> <th>Entries</th> </tr>"; while($row2 = mysql_fetch_array($result2)) while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td>" . $row['PlayerName'] . "</td>"; echo "<td>" . $row2['Total'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($link); ?> If I use $query on its own it joins perfectly, If I use $query2 on its own, it displays the results exactly how I want them listed but with the ID instead of the PlayerName, I tried putting them both together as shown above but I can't get them to work together. What I want my end Result to be Player1 1 Player2 1 Player3 3 Player4 3 How it keeps coming out; 1393 1 2097 1 3888 3 4017 3 Can anyone see where I'm going wrong? Thank you!!
  9. I'm running Phpbb3 Version: 3.0.12. I'm trying to get all the topics from my "NEWS" Category posted on to the index.php of my Website. With the code I'm using I can get this working perfectly fine, in it's own .php file. But as soon as I add it into my index.php all of the PHP code below the forum code doesn't show. For example my layout is > Header > Login Function > Blank Space in the middle (Using this for the forum code) > 2 other PHP Scripts. As soon as I apply the forum code the 2 other PHP scripts and their markups completely dissapear from my website. The only way I can prevent this is by putting the Forum code at the bottom of my index.php but then it displays on the far left and I want it in the middle. I have tried putting it in it's own file and doing <?php include_once('external_page.php'); ?> but the same problem persists. Here is my forum code; <?php /* * home.php * Description: example file for displaying latest posts and topics * by battye (for phpBB.com MOD Team) * September 29, 2009 */ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); include($phpbb_root_path . 'includes/bbcode.php'); include($phpbb_root_path . 'includes/functions_display.php'); // Start session management $user->session_begin(); $auth->acl($user->data); $user->setup('viewforum'); $search_limit = 7; $posts_ary = array( 'SELECT' => 'p.*, t.*, u.username, u.user_colour', 'FROM' => array( POSTS_TABLE => 'p', ), 'LEFT_JOIN' => array( array( 'FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = p.poster_id' ), array( 'FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'p.topic_id = t.topic_id' ), ), 'WHERE' => ' t.topic_status <> ' . ITEM_MOVED . ' AND t.topic_approved = 1', 'ORDER_BY' => 'p.post_id DESC', ); $posts = $db->sql_build_query('SELECT', $posts_ary); $posts_result = $db->sql_query_limit($posts, $search_limit); while( $posts_row = $db->sql_fetchrow($posts_result) ) { $topic_title = $posts_row['topic_title']; $post_author = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']); $post_date = $user->format_date($posts_row['post_time']); $post_link = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=" . $posts_row['post_id'] . "#p" . $posts_row['post_id']); $post_text = nl2br($posts_row['post_text']); $bbcode = new bbcode(base64_encode($bbcode_bitfield)); $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']); $post_text = smiley_text($post_text); $template->assign_block_vars('announcements', array( 'TOPIC_TITLE' => censor_text($topic_title), 'POST_AUTHOR' => $post_author, 'POST_DATE' => $post_date, 'POST_LINK' => $post_link, 'POST_TEXT' => censor_text($post_text), )); } page_header('External page'); $template->set_filenames(array( 'body' => 'external_body.html' )); page_footer(); ?> Thanks in advance.
  10. Thank you for the help Mac. Saved me a bunch of time.
  11. I was showing a snippet of the Login authentication process I'm using in hopes someone could help me add to that first created session the users email too. I have tried this; <?php $query= mysql_query("SELECT * FROM `users` WHERE `name` = '".$_SESSION['user']."' ")or die(mysql_error()); $account = mysql_fetch_array($query); $num = mysql_numrows($query); ?> /// <?php echo $account['email']; ?> But the results display empty :s
  12. In my script, users login with their Username & Password. However, I'd like to be able to echo the email address used on their account. I've tried adding the email to the session I'm not having much luck... Here's a piece of the login code(untouched); $username = $_POST['name']; $passwd = $_POST['passwd']; $query = "SELECT name,passwd FROM users WHERE CONCAT('0x', hex(passwd)) = '{$salt}'"; $result = mysql_query($query); $login_ok = false; if(mysql_num_rows($result) > 0) { $login_ok = true; } if($login_ok) { $row = mysql_fetch_array($result, MYSQL_NUM); $_SESSION['user'] = $row; I've also tried messing around with this piece below in a few different ways but still nothing. <?php echo htmlentities($_SESSION['user']['email'], ENT_QUOTES, 'UTF-8'); ?> Any help is greatly appreciated..
  13. Perhaps try creating the qty as a variable. <?php session_start(); $QTY=$_POST['qty']; $conn = mysqli_connect("localhost","root","","skel"); $sql = "INSERT INTO cart VALUES (" . session_id() . ", "NOW()", "$QTY; Something like this.
  14. Not sure if I'm reading this properly given that its 4am lol. However I'll try and shed a little light on this and hopefully can help you out somewhat. From reading I understand you want it to echo the successful registration but also redirect onto another page? If so, have you tried using; $result = mysql_query($query); if($result){ echo '<script>alert("New user has been created!");</script>'; header("Location: xxxxx.php"); die("Redirecting to: xxxxx.php"); } else { print("Something went wrong with your registration."); ?> As for logging a member in.after registering, try creating a session after the script succeeds. $result = mysql_query($query); if($result){ $_SESSION['loggedin'] = $result; // echo // redirect ?> //Then on the top of the form you want them to be logged in with that session <?php if(isset($_SESSION['loggedin'])){ //hi im logged in }else{ // hi im not logged in ?> There might be a few mistakes here. But I hope it helps somewhat! I'm PHP novice =)
  15. Hello. I' have a Table in MySQL That stores data (name/email/time) of when a person last run X script. I'm trying to pull that information for each user unique to their account to display so they know that they've already ran that script today How it works. Run script > Create's Row storing the data > MySQL Events deletes row after 24 hours. My code to display notification if they have already ran it; $sql = 'SELECT a.name, a.time FROM timecheck a, users b WHERE a.name = b.name'; mysql_select_db('My_DB'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "Account: {$row['name']} <br> ". "Last Time Run: {$row['time']} GMT -1<br> "; } echo "It seems you have done this already today!"; ?> Now my problem is. It's displaying every row to every user. I want it to only show the user their row... What I've tried. Creating a session variable "$sessionID" $sql = 'SELECT a.name, a.time FROM timecheck a, users b WHERE a.name = b.name AND a.name=$sessionID"'; But I'm not getting any lucky. All help is appreciated, thank you in advance.
  16. Access denied for user 'sec_user'@'localhost' (using password: YES) in C:\wamp\www\gip\includes\db_connect.php on line 3 sec_user Does your MySQL have a user called "sec_user"? If not, then change it to root, that should work. A Post I recently made may help you; http://forums.phpfreaks.com/topic/287759-loginregister-help/?p=1476134 You can find it here.
  17. <head> <meta http-equiv="REFRESH" content="5;url=http://www.google.com" target="_self"> </head><body oncontextmenu="return false;"> <p>You'll be automatically redirected in <span id="count">5</span> seconds...</p> <script type="text/javascript"> window.onload = function(){ (function(){ var counter = 5; setInterval(function() { counter--; if (counter >= 0) { span = document.getElementById("count"); span.innerHTML = counter; } if (counter === 0) { alert('BYE'); clearInterval(counter); } }, 1000); })(); } </script> Try this, works like a charm for me I use it as a re-directory. When the timer has finished its 5 seconds, it will re-direct to google.com You can change it to suit your needs though.It's fairly simple
  18. Okay, here's my update! After fiddling with the code for goodness how long... I had to change many things that didn't seem to add up. However, The code is now working, thanks to your support! Now; my only issue is. How can I get the row it's created in my table to delete itself automatically after 6 hours?
  19. Thanks for the reply! I will modify my code and try to get it working! I will report back with an update soon, hopefully with a final working code. I appreciate your time.
  20. The database is refusing your connection. Check the connection function and make sure its right. Probably something like this: $link = mysql_connect('localhost', 'root', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; If however your connect function is right, please check your MySQL database users to confirm they exist/match the details you are using. You can also add a new user to connect through in MySQL. CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; If you're using a different IP compared to the one you're trying to connect to; change 'localhost' to the IP you're trying to remote access from. I'm not very good at PHP either but I help this helps you.
  21. This is my current layout Log Table userid int(11) email int(11) zoneid int(11) cash int(11) status int(11) creatime datetime <?php $Result = mysql_query("SELECT * FROM login WHERE name='$name' and email='$email'"); $count=mysql_num_rows($Result); if($count==1) { $row2 = mysql_fetch_array( $Result ); $ID = $row2['ID']; $TIME = $row2['creatime']; MySQL_Query("INSERT INTO log (id, zoneid, cash, status, creatime) VALUES ('$ID', '1', '100', '1', '$TIME')"); $_SESSION['name'] = $row2[name]; $_SESSION['email'] = $row2[email]; header("location:success.php?sys=success"); ?> I'm running a Voting system for a game, When each user Votes for their account, they will receive some rewards. But before the script completes, I want it to store the Email enterd into a seperate document or table, which automates deletion after X hours. So that when they try to run it again using the same Email before X hours is over, it will decline. Example; Users must login to Vote. <form name="form" method="post" target="_blank" action="vote.php?sys=vote"> <input type="text" name="name" value="<?php echo htmlentities($_SESSION['user']['0'], ENT_QUOTES, 'UTF-8'); ?>"><br> <input type="text" name="email" value="Email"> <input type="submit" name="Submit" value="Vote"> This is how I want the process to go.. <?php $name='John Doe', $email='JohnDoe@test.com' Insert $email into $DocumentorTable if $email already exists in $DocumentorTable > Error Try again later. if $email doesnt exist in $DocumentorTable > successful if successful > MySQL_Query("INSERT INTO log (id, zoneid, cash, status, creatime) VALUES ('$ID', '1', '100', '1', '$TIME')"); header("location:success.php?sys=success"); ?> I'm not very good with PHP as of yet, so I'm not entirely sure on how to finish the layout to a working standard.. Any help is very appreciated. However, if this is a process that is difficult or complex, maybe there's a way I can do this with the logged in session? Like, update the users session when they have voted with a mark, then after X hours the mark will automatically delete putting the session back to normal allowing them to vote again. But if the mark still stands, the voting will not commence. Thank you in advance!!
  22. I managed to fix the problem, thank you for the feedback! - I'll post in-case it may help someone else in the future By removing the heredocs feature; <?php if(isset($_SESSION['user'])){ $Return = $_GET['return']; // return info // table info <input name='myusername' placeholder='Username' value='<?php echo htmlentities($_SESSION['user']['0'], ENT_QUOTES, 'UTF-8'); ?>' readonly type='text' id='myusername'>
  23. For the first example; Notice: Array to string conversion in /opt/lampp/htdocs/cpass.php on line 161 /// Line 161 = </table>"; Second example; Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /opt/lampp/htdocs/cpass.php on line 141 And if this helps: <?php print_r($_SESSION); ?> = Array ( [user] => Array ( [0] => alpha [1] => ُHWV ) )
  24. Hello, I'm using a PHP Script that allows users to change their password. however, I'd like it so they can change the password for the account they're logged into only. Here's my code; <?php if(isset($_SESSION['user'])){?> <?php $Return = $_GET['return']; IF ($Return == 0) { echo"Please enter your details into this form and press submit to change your password.<br>"; } IF ($Return == 1) { echo"<font color=red>ERROR: Account information is incorrect!</font><br>"; } ELSE IF ($Return == 2) { echo"<font color=red>ERROR: Length of New Password should be between 5-10 Alphanumeric!</font><br>"; } ELSE IF ($Return == 3) { echo"<font color=green>SUCCESS: Password has been changed!</font><br>"; } ELSE IF ($Return == 4) { echo"<font color=red>ERROR: Blank Information was entered!</font><br>"; } echo"<table width='300' border='0' cellpadding='0' cellspacing='1'> <tr> <form name='form1' method='post' action='changepass.php'> <td> <table width='300' border='0' cellpadding='3' cellspacing='1'> <tr> <td width='294'><input name='myusername' placeholder='Username' readonly='true' type='text' id='myusername'></td> </tr> <tr> <td width='294'><input name='oldpassword' placeholder='Old Password' type='password' id='oldpassword'></td> </tr> <tr> <td width='294'><input name='newpassword' placeholder='New Password' type='password' id='newpassword'></td> </tr> <tr> <br> <td><input type='submit' name='Submit' class='btn btn-primary btn-block' value='Change Password'></td> </tr> </table> </td> </form> </tr> </table>"; ?> </center> <?php }else{ ?> Sorry, you are <u>not</u> authorized to access this page <?php } ?> Here's things I've tried that dont seem to work; if(isset($_SESSION['user'])) $val = $_SESSION['user']; else $val = ""; <input name='myusername' placeholder='Username' value='$val' readonly='true' type='text' id='myusername'> ______________________ <input name='myusername' placeholder='Username' value='echo htmlentities($_SESSION['user']['0']'readonly='true' type='text' id='myusername'> I keep getting errors on trying the methods above. Is thereany other approach I could take? Thanks in advance!
×
×
  • 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.