ryanmetzler3
Members-
Posts
77 -
Joined
-
Last visited
ryanmetzler3's Achievements
Member (2/5)
1
Reputation
-
Header() not working, and sessions not starting
ryanmetzler3 replied to ryanmetzler3's topic in PHP Coding Help
I have found that the error is always at the line where the first php tag occurs. Right now it is reading an error at line 12 which is the first php tag in the code. If I delete that section (because it does not contribute to the functionality of the code) , the errror reads line 19 which is the next php tag. If I delete that, the error jumps to the next php tag. It doesnt like the first php tag for some reason. -
Header() not working, and sessions not starting
ryanmetzler3 replied to ryanmetzler3's topic in PHP Coding Help
Here is all the code. I put line 12 in red so you can see it easier. Thank you <html> <head> <link rel="stylesheet" type="text/css" href="/style.css" /> <link rel="stylesheet" type="text/css" href="/login_scripts/user_style.css" /> <title>Wet Dog Nose Polls</title> </head> <body> <div id="wrapper"> <div id="headerwrap"> <div id="header"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/header_source/index.php'; ?> <a href="/index.php"> <img src="/images/wetdognose.jpg"> </a> </div> </div> <div id="navigationwrap"> <div id="navigation"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/menu_source/index.php'; ?> </div> </div> <div id="loginwrap"> <div id="login"> <h2>Welcome back! Sign in here.</h2> <?php include $_SERVER['DOCUMENT_ROOT'] . '/login_scripts/sessionstart.php'; if (isset($_POST['loginbtn']) or ($username && $userid)) {} else{echo "";} if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='/login_scripts/logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='/login_scripts/login.php' method='post'> <table class='forms'> <td><input type='text' name='user' placeholder='Username' class='input_style'/></td> </tr> <tr> <td><input type='password' name='password' placeholder='Password' class='input_style'/></td> </tr> <td><input type='submit' name='loginbtn' id='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='/login_scripts/register.php'>Register</a> <a href='/login_scripts/forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; } if ($_POST['loginbtn']) { $user = $_POST['user']; $password = $_POST['password']; if ($user) { if ($password) { include $_SERVER['DOCUMENT_ROOT'] . '/login_scripts/connect.php'; $password = md5(md5("R4E2M0".$password."R4E2M0")); $link = mysqli_connect("localhost","wetdogno_ryan","Relztem$3","wetdogno_login") or die ("Cannot connect"); $query = mysqli_query($link, "SELECT * FROM user WHERE username='$user'") or die (mysqli_error()); $numrows = mysqli_num_rows($query); if ($numrows ==1) { $row = mysqli_fetch_assoc($query); $dbid= $row['id']; $dbuser= $row['username']; $dbpass = $row['password']; $dbactive = $row['active']; if ($password == $dbpass) { if ($dbactive == 1) { $_SESSION['userid'] = $dbid; $_SESSION['username'] = $dbuser; header('Location:/login_scripts/member.php'); } else { echo "<font color='red'>You must activate your account to login. $form</font>"; } } else { echo "<font color='red'>You did not enter the correct password. $form</font>"; } } else { echo "<font color='red'>The username you entered was not found. Be sure that you are entering your username and not email.$form</font>"; } } else { echo "<font color='red'>You must enter your password . $form</font>"; } } else { echo "<font color='red'><p>You must enter your username. Be sure you are entering your username and not your email. $form</font>"; } } else{ echo $form; } ?> </div> </div> <div id="rightcolumnwrap"> <div id="rightcolumn"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/ad.php'; ?> </div> </div> <div id="footerwrap"> <div id="footer"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/footerlinks.php'; ?> </div> </div> </div> </body> </html> -
I have a script where a user can register and then login to my site. It all works fine on WAMP. When I put it on a live server I am having issues. I am getting this error when you try to login. Warning: Cannot modify header information - headers already sent by (output started at /home/wetdogno/public_html/login_scripts/login.php:12) in /home/wetdogno/public_html/login_scripts/login.phpon line 75 I know sessions are not starting becuase normally when you register, it automatically logs you into the account you just created, but its not doing that. It creates the user, because their information gets injected into my DB. Their session just isn't starting. Also the header() function is not working. Here is the code that the error message describes. I really don't think its a white space issue like many of the blogs that I have read indicated. f ($password == $dbpass) { if ($dbactive == 1) { $_SESSION['userid'] = $dbid; $_SESSION['username'] = $dbuser; header('Location:/login_scripts/member.php'); }
-
Hello everyone, I just wrote a significiant amount of code using mysql commands. I am now finding out that mysqli is the better option. Will mysql commands not work in the future? Do you have to switch to mysqli to avoid any potential issues?
-
I have a comment section. It is comprised of 3 major files. One file creates the form where you fill in your name and comment. Another file sends your comment to the DB. The third file displays the already existing comments on the page. You have the option to reply to the existing comments on the page. When you click the reply button I would like the comment text box to light up so the user knows its working but I have hit a brick wall. This is the comment form the user actually types into: <div id="comment-container" > <form id="comment_form" action="/comm_1/post_comment.php" method='post' onsubmit=" return validateForm()"> <table> <tr> <td id="error"></td> </tr> <tr> <td><textarea name="comment_body" id='comment_body' placeholder="Comment"></textarea></td> </tr> <?php if(!$username && !$userid): ?> <tr> <td><input type="text" name="name" class="input_style" placeholder="Name"/> <input type="submit" id="loginbtn" value="Or Login" onclick="window.location='/login_scripts/login.php'" /></td> </tr> <tr> <td><input type="email" name="email" class="input_style" placeholder="Email"/></td> </tr> <?php endif; ?> <?php if($username && $userid): ?> <input type="hidden" name="name" value="<?php echo htmlspecialchars($username) ?>"/> <input type="hidden" name="email" value="<?php echo htmlspecialchars($email) ?>"/> <?php endif; ?> <tr> <input type='hidden' name='parent_id' id='parent_id' value='0'/> <td><input type="submit" name="submitbtn" id="submitbtn" value="Add comment"/></td> </tr> </table> </form> This how the existing comments are displayed on the page: You can see on line 7 is the button to the reply to a comment. When this is clicked I need the "comment_body" from the above code to highlight. <?php function getComments($row) { echo "<li class='comment'>"; echo "<div class='aut'>".$row['author']."</div>"; echo "<div class='timestamp'>".$row['created_at']."</div>"; echo "<div class='comment-body'>".$row['comment']."</div>"; echo "<a href='#comment_form' name='replybtn' class='reply' id='".$row['id']."'>Reply</a></script>"; $q = "SELECT * FROM threaded_comments WHERE parent_id = ".$row['id'].""; $r = mysql_query($q); echo "</li>"; if(mysql_num_rows($r)>0) { echo "<ul>"; while($row = mysql_fetch_assoc($r)) { getComments($row); } echo "</ul>"; } } ?> I tried this with JS, but it does not work: $(function(){ $("a.reply").click(function() { var id = $(this).attr("id"); $("#parent_id").attr("value", id); $("#comment_body").focus(); }); });
-
clearing cache or something for all users
ryanmetzler3 replied to ryanmetzler3's topic in PHP Coding Help
I have a poll on my website. The question and answers for the poll are stored in a database. When I want to change the poll I simply change the question and answer options in the database. Here is the problem. When you vote it registers a cookie and then knows to display the results rather than the question. Like so: setcookie("voted".$_POST['pollid'], 'yes', time()+86400*300); Unfortunately when I change the question the old cookies are still in place. So it is automatically showing the results to the new question even if you only already voted on the previous question. Is there a way to detect if you voted on the old poll, and clear your cookie if you voted on the old one?. Really lost on how to solve this. I was thinking something like this: if(some constraint to distinguish old cookies maybe a time-stamp?){ $_COOKIES = array(); } -
clearing cache or something for all users
ryanmetzler3 replied to ryanmetzler3's topic in PHP Coding Help
yea sorry about. I though I could simplify my question a lot better but could not figure out how to delete the old one. -
clearing cache or something for all users
ryanmetzler3 replied to ryanmetzler3's topic in PHP Coding Help
I have a poll on my website. If you vote, then it registers a cookie and displays the results. It will continue to show the results even if you refresh the page because of that cookie. My problem is if I change the question then I want it to start fresh. Unfortunately if the user has not cleared their cookies from the last time they voted, it automatically displays the results even if the question was updated. I tried something like this: $_COOKIE = array(); this does not work because then it always clears it every time anyone visits. I just need to somehow wipe everyone's clean once when I update the question?? -
I downloaded a script for a poll/voting kinda thing for all my site visitors a while ago and then I tweaked it a bit. It is linked to a database. It grabs the question and possible answers from one database. It also stores user votes, ip addresses, and the date they voted in a database. I went to change the question and possible answers in my poll by simply changing the options in the Database. This worked fine, but I found a big problem! If you have already voted in the poll, then it displays the results to you every time you visit the site . I assumed this was based off your IP since it is recorded in the database. So logically I thought if you cleared all the IP's in the DB, then the new question would display for every user, but to my alarm it is based off cookies. This is problem because even though I changed the question and options, if people have not cleared their cookies from the last time then the poll still displays the results even though they have not voted on the new question yet. Is there someway to clear everyone cookies or make the poll start fresh for everyone without drastically changing the code and how the entire thing works?
-
I have two comment sections. The data from the first is saved in threaded_comments (a table), the second comment section saves its data in threaded_comments2. I have attached a screen shot of the structure of the tables. The two tables have the same structure and sit in one DB. If you post an original comment, it gets a parent_id of 0. If you reply to a comment its parent_id matches the id of the comment it is in reply to (You can see this in the pic). If a user logs in, I would like to have a section where they can view their recent comments ONLY and see if anyone has replied to them. I ran a query to do this as follows: //connection include $_SERVER['DOCUMENT_ROOT'] . '/comm_1/config.php'; // gets original comments only, And only those posted by the user currently logged in. $sql = "SELECT *, 0 as section FROM threaded_comments WHERE parent_id = 0 AND author = '$username'" . "UNION SELECT *, 1 as section FROM threaded_comments2 WHERE parent_id = 0 AND author = '$username'"; $result = mysql_query($sql); while ($link = mysql_fetch_assoc($result)) { yourComments($link); } //this function gets all the information from the rows in the DB function yourComments($row) { echo "<li class='comment'>"; echo "<div class='aut'>".$row['author']."</div>"; echo "<div class='timestamp'>".$row['created_at']."</div>"; echo "<div class='comment-body'>".$row['comment']."</div>"; //this query checks if there is any replies to the comments fetched by the original query and displays them. $q = "SELECT *, 0 as section FROM threaded_comments WHERE parent_id = ".$row['id']." " . "UNION SELECT *, 1 as section FROM threaded_comments2 WHERE parent_id = ".$row['id'].""; $r = mysql_query($q); echo "</li>"; if(mysql_num_rows($r)>0) { echo "<ul>"; while($row = mysql_fetch_assoc($r)) { yourComments($row); } echo "</ul>"; } } The problem is a comment from the first table may have an id of "1" and therefore a reply to this comment would have a parent_id of "1". This same exact scenario is possible to happen in table 2. So for example the comment with the id of 1, displays. Then all the comments with a parent_id of "1" display as a reply to it (even though they could be coming from both table). I will attach a screen shot of this issue to help make it more clear. Any idea how to fix this?
-
I have a DB with 4 tables in it.There is 4 different comment sections on my website, so each table has the same structure, but holds information unique to that comment section. Im trying to query all 4 tables and pull the comments by one specific user from all of them. But the row "comment" is in all 4 tables, it says it is ambiguous and wont work. Is there anyway around this? Or do I have to rename the columns in each table? <?php include $_SERVER['DOCUMENT_ROOT'] . '/comm_1/config.php'; $query= "SELECT comment FROM threaded_comments,threaded_comments2,threaded_comments3,threaded_comments4 WHERE author = '$username'" or die (mysql_error()); $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo $row['comment']; } ?>
-
Do something like this: <input type="image" src="rainbow.gif" name="image" width="60" height="60"> It is technically not a button, but you can use the src attriubute for you image. Then use the onClick function to direct the user wherever you want.
-
I have a comment section that I use 'ul' tags to show the replies to a previous comment with an indent. I attached a picture of this. Right now the 'ul' tag is indenting original comments and indenting replies even more. I want to slide all the original comments over so they sit flush to the left in the box, but keep an indent for the replies. I tried this all of these independently: ul{ padding: 0px; margin-left:0px; padding-left: 0px; } but that takes the indent off of everything. Here is the snippet of code that displays the comments if(mysql_num_rows($r)>0) { echo "<ul>"; while($row = mysql_fetch_assoc($r)) { getComments($row); } echo "</ul>"; } } any idea how to do this?
-
I have a comment section on my website. It requires your name, email, and comment. You can opt to login and then you do not have to fill in your name and email. My form looks like this: <tr> <td><label for="name">Name:</label></td> <input type="submit" id="loginbtn" value="Or Login" onclick="window.location='/login_scripts/login.php'" /></td> </tr> <tr> <td><label for="name">Email:</label></td> <td><input type="email" name="email" id='email'/></td> </tr> Once you login, the name and email fields disappear and you can just comment. I grab your user name from the database and insert that as your comment name. Anyways, how can I redirect them back to the comment section after they have been logged in? assuming they arrived at the login page from this specific login button...
-
script not working when included in different file-
ryanmetzler3 replied to ryanmetzler3's topic in PHP Coding Help
Thanks, since I copied the first file to make the second I have some div's with the same name. I did not think that would matter since they are sitting inside folders with different names but I will change that and see how it works. I appreciate the suggestion!