• Content count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About warrens0017

  • Rank
  1. Hi everyone, I need a little help with trying to figure out what I need to do. I am writing an IF statement that allowed only certain users can see. So what I am trying to do, in my DB i have it created that if you are going to have certain access, the value in the DB is set to '1' for true. What I need help with is seeing how I can write and IF statement that reads that value and allows the user to see it. This is the current code I have: <?php if (isset($_SESSION['id'])) { echo "Welcome"; } else { echo "You not logged in or don't have access."; } ?> With this code, anyone that logs in will be able to see it. What I want is another line of code that allows those with the value of '1' in the DB to see it. I have tried many different ways of seeing if I can get it to work but it never does. It either always returned the value TRUE and reads the code or the value is FALSE; even if when I am login, the value turn FALSE. So if anyone can give me just a quick moment of their time, that would be great. NOTE: My DB Connection is in a header.
  2. Ahhhh....I see it. I had to move around the <form> before the getNote().
  3. <?php if (isset($_SESSION['id'])) { echo "<table id='Table_note'>"; echo "<tr class='noteTable'>"; echo "<th>Notes</th>"; echo "<th></th></tr>"; getNote($conn); echo "</table><br>"; echo "<form method='POST' action='".setNote($conn)."'> <input type='hidden' name='id' value='".$_SESSION['id']."'> <input type='hidden' name='date' value='".date('Y-m-d')."'> <textarea name='note'></textarea><br> <button class='button-YT' type='submit' name='NoteSubmit'>Sent Note</button> </form>"; } else { echo "<p>You Need to Login</p>"; } ?> This is where the setNote() and getNote() is placed.
  4. See now I understand that but I have something very similar to the code that i wrote. BUT, with the other code that is not different in anyway, I can submit a text to the database, and have it come write back out without any errors. I did find out that with the code above that I can send one thing to the database and get it back without any issues, it only when I am trying to send more information to the database that I get the error. And that is where I am at and I am confused. That a very similar code work but not this one.
  5. Hi, I am having an issue with a warning that keeps popping up. I have edited the line it is saying but still getting the error. Warning: Cannot modify header information - headers already sent by (output started at /Pages/Forums/comments.php:227) in /Pages/Forums/comments.php on line 88 Here are the two lines that the warning is saying function setNote($conn) { if (isset($_POST['NoteSubmit'])) { $id = mysqli_real_escape_string($conn, $_POST['id']); $date = mysqli_real_escape_string($conn, $_POST['date']); $note = mysqli_real_escape_string($conn, $_POST['note']); $sql = "INSERT INTO note (id, date, note) VALUES ('$id', '$date', '$note')"; $result = mysqli_query($conn, $sql); header("Location: /Pages/Profile.php"); //This line has the error - LINE 88 } } And the other function getNote($conn) { $id = $_SESSION['id']; $sql = "SELECT * FROM note WHERE id='$id'"; $result = mysqli_query($conn, $sql); while ($row = $result->fetch_assoc()) { echo "<div class='comment-box'><p><b>"; echo "Note: </b><br>"; echo nl2br($row['note']); echo "</p></div> <form class='delete-form' method='POST' action='".deleteNote($conn)."'> <input type='hidden' name='nid' value='".$row['nid']."'> <button type='submit' name='deleteNote'>Delete</button> </form>"; //This line has the error - LINE 227 } } Now after I refresh the page, I see what i typed. Hope someone has and answer. Thanks!
  6. Okay one more thing and I should be good. I got all that fixed and worked out, but now I am trying to create a login and I am getting this error: Warning: mysqli_fetch_assoc() expects parameter 1 to be resource, boolean given in Here is the code that I am working with: login.php <?php include 'dbh.php'; $uid = $_POST['uid']; $pwd = $_POST['pwd']; $sql = "SELECT * FROM username WHERE uid='$uid' AND pwd'$pwd'"; $result = mysqli_query($conn, $sql); if (!$row = mysqli_fetch_assoc($result)) { echo "Username or password is incorrect"; } else { echo "You are logging in"; } //header("Location: index.php"); ?>
  7. Thank you very much. I read over the code like ten times and didn't notice that.
  8. Hi everyone. So I am have an issue to were I am trying to send information to my database and I get this error: NOTICE: Undefined index This is the code I am using: index.php <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Test Page</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <form action="signup.php" methos="POST"> <input type="text" name="first" placeholder="First Name"><br> <input type="text" name="last" placeholder="Last Name"><br> <input type="text" name="uid" placeholder="Username"><br> <input type="password" name="pwd" placeholder="Password"><br> <button type="submit">SIGN UP</button> </form> </body> </html> signup.php <?php include 'dbh.php'; $first = $_POST['first']; $last = $_POST['last']; $uid = $_POST['uid']; $pwd = $_POST['pwd']; $sql = "INSERT INTO username (first, last, uid, pwd) VALUES ('$first', '$last', '$uid', '$pwd')"; $result = mysqli_query($conn, $sql); ?> dbh.php <?php $conn = mysqli_connect("localhost", "root", "", "logintest"); if (!$conn) { die("Connection failed: ".mysqli_connect_error()); } ?> So this is the code I am using. I know it is connecting to the database because the PRIMARY KEY is entering without an issue but the information is now being filled in. I.E. First name, Last name, User, and Password. If anyone can help me that would be great.