cant update? |
cant update? |
xxkasperxx |
Feb 9 2012, 10:33 PM
Post
#41
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
i got all my cms pretty much finished.. i cant figure out the session stuff though..
I have a login page.. "admin.php" and that redirects to "login.php" when you enter your data. and then there is a link on login.php to go to "aboutUpdate.php" and when you go to members .php is says you must be logged in.. here is my code. please help i have been pulling my hair out trying to figure this out.. admin.php (i know i havent assigned the type of html it will be.. i will fix that soon, i just want to get this figured out..) CODE <html> <form action='login.php' method='POST'> Username:<input type='text' name='username'><br> Password:<input type='password' name='password'><br> <input type='submit' value='Log In'> </form> </html> login.php CODE <?php $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("filled in on mine")or die("Couldnt connect to the database! Sorry."); mysql_select_db("filled in on mine") or die ("Couldnt find table Database. Sorry"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_numrows($query); if ($numrows!=0) // code to login { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } // check to see if the match! if($username==$dbusername&&$password==$dbpassword) { //$_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo "<p>Welcome, ".$_SESSION['username']."!<a href='logout.php'> Logout</a></p><br>"; echo "<br> <p>Please click on a link to edit that page!</p>"; } else echo "Incorrect password!"; } else die ("User doest exist!"); } else die("Please enter a username and password."); ?> <!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> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Colby Bright Music</title> <link href="css/main.css" type="text/css" rel="stylesheet" /> <link href="css/admin.css" type="text/css" rel="stylesheet" /> <!--[if IE ]> <link href="css/ie.css" type="text/css" rel="stylesheet" /> <![endif]--> <!-- Browser Icon --> <link rel="shortcut icon" href=".\favicon.ico"> <!-- End browser Icon --> </head> <body id="sector1"> <!-- Black Menu --> <div id="menu_wrapper" class="black"> <div class="left"></div> <ul id="menu"> <li><a href="filled in">Home</a></li> <li><a href="filled in">Music</a></li> <li><a href="filled in">Videos</a></li> <li><a href="filled in">Shows</a></li> <li><a href="filled in">Interviews</a></li> </ul> </div> </body> </html> aboutUpdate.php CODE <?php session_start(); $left = $_POST['leftside']; if($_SESSION['username']) { $_SESSION['username']=$username; echo "Welcome, ".$_SESSION['username']."!<a href='logout.php'> Logout</a><br>"; $directions = "<h3>Directions:</h3>To edit text, simply click in one of the boxes you wish to change.<br> Delete/change the current text to what you desire.<br> Press update and the update will be automatically sent to the Live Site!<br><br><br>"; $connect = mysql_connect("filled in")or die("Couldnt connect to the database! Sorry."); mysql_select_db("filled in") or die ("Couldnt find table Database. Sorry"); $query = mysql_query("SELECT * FROM about"); $query_row=mysql_fetch_array($query); echo $directions; } else die("You must be logged in!"); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="css/admin.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="column one"> <form method="POST" action="update.php"> Left-Side: <br/> <textarea name="updateLeft" rows="10" cols="80"><?php echo($query_row[leftside]); ?></textarea><br><br> Right-Side:<br> <textarea name="updateRight" rows="10" cols="80"><?php echo($query_row[rightside]); ?></textarea><br><br> <input type="submit" value="Finished" /> </form> <p><a href="">Return to edit selection</a> </div> <!-- <form action='sent.php' method='POST'> Home-Right-Side: <input type='textarea' cols="30" rows="20" name='rightside'> <input type='submit' value='Log In'> </form>--> </body> </html> update.php CODE <?php session_start(); //if($_SESSION['username']) //{ $connect = mysql_connect("filled in")or die("Couldnt connect to the database! Sorry."); mysql_select_db("filled in") or die ("Couldnt find table Database. Sorry"); $left = $_POST['updateLeft']; $right = $_POST['updateRight']; if ($left=="") { echo "Please enter valid data!"; }else { //$result = mysql_query("UPDATE about SET rightside = '$right' WHERE id = '1' "); $result = mysql_query("UPDATE about SET leftside = '$left' WHERE id = '1' "); } /*if (!$result) { die('Invalid query: ' . mysql_error()); }else {*/ echo "Update Sucessfull! Click"."<a href='filled in'> here</a>"." to view update"; //} /*} else die ("You must be logged in!");*/ ?> |
Ephraim F. Moya |
Feb 10 2012, 10:34 AM
Post
#42
|
Advanced Member Group: Members Posts: 167 Joined: 2-September 07 From: New Mexico Member No.: 3,702 |
What I haven't seen and I think you sorely need is:
A design for the sessions system. Questions: 1) How are you going to differentiate between one user and another? 2) How many levels of status are you going to maintain? 3) How are you going to tell what level to assign to a particular user? 4) What are you going to check for when another user logs in? 5) Where is the SESSIONS['...'] display code? 6) What happens if someone attempts to hi-jack a session? |
xxkasperxx |
Feb 10 2012, 04:17 PM
Post
#43
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
there is only one user, and one level.. admin. i have not gotten to the hi-jack part, i want to get the log-in part up and running
Thanks for the quick reply! |
Ephraim F. Moya |
Feb 10 2012, 09:50 PM
Post
#44
|
Advanced Member Group: Members Posts: 167 Joined: 2-September 07 From: New Mexico Member No.: 3,702 |
there is only one user, and one level.. admin. i have not gotten to the hi-jack part, i want to get the log-in part up and running Thanks for the quick reply! To do what you want you just have to remove all SESSIONS stuff. Just assume that a valid user already signed in. A one level session doesn't make any sense. You should have at least two levels. When I first started this posting I said that ALL HTML HAD TO BE VALID. If you don't intend to do that I'll bow out. |
xxkasperxx |
Feb 14 2012, 08:27 AM
Post
#45
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
so, i decided i will use 2 levels for accounts. One Admin and then user. user will be able to just look at the information and edit it, and admin will be able to insert new information and delete it. I have all of the html validated and will post it as soon as i get back home.
Thanks for your help! |
Lo-Fi Version | Time is now: 26th April 2024 - 09:54 AM |