FortMyersDrew Posted June 26, 2007 Share Posted June 26, 2007 Alright I have my shout box set up too how i want it and all but i need help on my shoutbox admin <?php //Start the session so you would stay logged in..//must be ABOVE ANY outputsession_start(); //Get the cmd variable$cmd=$_GET['cmd'];$idg=$_GET['id'];?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><title>ACP</title></head><body><?php//include config.phpinclude 'config.php';//get the username from the form and add some security//so you cant get hacked so easy $username = mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username'])));$password = md5($_POST['password']);//if login button is pressedif ($_POST['login']){//check if username and password are insertedif((!$username) || (!$password)){//if not tell them to...do insert all of infoecho "Please enter both values<br>";}//when they have we check if the username and the password exists$sql = mysql_query("SELECT * FROM `shoutbox_admin` WHERE `name` = '$username' AND `password`= '$password'") OR die(mysql_error());//so we need to check it for real //mysql_num_rows() counts the rows which are returned as true$login_check = mysql_num_rows($sql);//if the check is true....true = 1 and $login check is set as $login_check=1if($login_check > 0){//so if it is larger than 1 we set some session variables -//username and id$r=mysql_fetch_array($sql);$_SESSION['id'] = $r['id'];$_SESSION['username'] = $r['name'];//if it's not let's make him suffer...moahahahaa...//reload the page I mean.. }else {header("Refresh:2;admin.php");echo 'Go and login <-<';}}//so if session username isn't set show user the login formif(!isset($_SESSION['username'])){?><center><form action='<?=$_SERVER['PHP_SELF']?>' method='POST'>Username: <input type='text' size='15' name='username'><br>Password: <input type='password' size='15' name='password'><br><input name="login" type="submit" value="Submit"></form></center><? }//if not - show him the contents and stuff...else{//welcome message and logout link...echo "<center>Welcome, ". $_SESSION['username'] ."! <a href='logout.php'>Log Out</a></center>";echo "<br><br><center>";//see my ?id= browsing tutorial to understand switch()switch($cmd){default://getting all of the shouts and adding `delete me` link...$result = mysql_query("select * from shoutbox order by id desc"); while($r=mysql_fetch_array($result)) { $name=$r["name"];$message=$r["message"];$time=$r["time"];$id=$r["id"];echo "Shout by: ".$name." <strong>@</strong> ".$time."<br>".$message."<br><a href='?cmd=delete&id=".$id."'>Delete me</a><br><br>";}break;case 'delete':$sql = "DELETE FROM shoutbox WHERE id=".$idg."";$result = mysql_query($sql);header('Refresh:2;admin.php');echo "deleted";};} This is what my friend helped me with but he gave me it like this... and i dont think its working right Quote Link to comment Share on other sites More sharing options...
DJTim666 Posted June 26, 2007 Share Posted June 26, 2007 Can you spce out the code a little so we can see it properly. Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 26, 2007 Author Share Posted June 26, 2007 Yea give me a second Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 26, 2007 Author Share Posted June 26, 2007 Admin.php <?php //Start the session so you would stay logged in.. //must be ABOVE ANY output session_start(); //Get the cmd variable $cmd=$_GET['cmd']; $idg=$_GET['id']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> <title>ACP</title> </head> <body> <?php //include config.php include 'config.php'; //get the username from the form and add some security //so you cant get hacked so easy $username = mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username']))); $password = md5($_POST['password']); //if login button is pressed if ($_POST['login']){ //check if username and password are inserted if((!$username) || (!$password)){ //if not tell them to...do insert all of info echo "Please enter both values<br>";} //when they have we check if the username and the password exists $sql = mysql_query("SELECT * FROM `shoutbox_admin` WHERE `name` = '$username' AND `password`= '$password'") OR die(mysql_error()); //so we need to check it for real //mysql_num_rows() counts the rows which are returned as true $login_check = mysql_num_rows($sql); //if the check is true....true = 1 and $login check is set as $login_check=1 if($login_check > 0){ //so if it is larger than 1 we set some session variables - //username and id $r=mysql_fetch_array($sql); $_SESSION['id'] = $r['id']; $_SESSION['username'] = $r['name']; //if it's not let's make him suffer...moahahahaa... //reload the page I mean.. }else { header("Refresh:2;admin.php"); echo 'Go and login <-<'; } } //so if session username isn't set show user the login form if(!isset($_SESSION['username'])){ ?> <center> <form action='<?=$_SERVER['PHP_SELF']?>' method='POST'> Username: <input type='text' size='15' name='username'><br> Password: <input type='password' size='15' name='password'><br> <input name="login" type="submit" value="Submit"> </form></center> <? } //if not - show him the contents and stuff...else{ else{ //welcome message and logout link... echo "<center>Welcome, ". $_SESSION['username'] ."! <a href='logout.php'>Log Out</a></center>"; echo "<br><br><center>"; //see my ?id= browsing tutorial to understand switch() switch($cmd){ default: //getting all of the shouts and adding `delete me` link... $result = mysql_query("select * from shoutbox order by id desc"); while($r=mysql_fetch_array($result)) { $name=$r["name"]; $message=$r["message"]; $time=$r["time"]; $id=$r["id"]; echo "Shout by: ".$name." <strong>@</strong> ".$time."<br>".$message."<br><a href='?cmd=delete&id=".$id."'>Delete me</a><br><br>"; } break; case 'delete': $sql = "DELETE FROM shoutbox WHERE id=".$idg.""; $result = mysql_query($sql); header('Refresh:2;admin.php'); echo "deleted"; } ;} ?> Phew long file but here it is. Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 26, 2007 Author Share Posted June 26, 2007 Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/r/e/drewsmedia/html/admin.php:16) in /home/content/d/r/e/drewsmedia/html/admin.php on line 44 Go and login <-< I get this error message! Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 26, 2007 Author Share Posted June 26, 2007 Line 44 header("Refresh:2;admin.php"); Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 26, 2007 Author Share Posted June 26, 2007 Does anyone know what i should do Quote Link to comment Share on other sites More sharing options...
per1os Posted June 26, 2007 Share Posted June 26, 2007 Do not output any html or data for that matter before the header call, that or make it a META tag or Javascript. Headers can only be sent if no ouput has been sent to the screen, which in that call obviously there is a bunch of output sent to the screen. Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 26, 2007 Author Share Posted June 26, 2007 wait i dont get it so where should i put that code? <?php //Start the session so you would stay logged in.. //must be ABOVE ANY output session_start(); //Get the cmd variable $cmd=$_GET['cmd']; $idg=$_GET['id']; ?> Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 26, 2007 Author Share Posted June 26, 2007 Can anyone help me out on this lol Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 *BUMP* Still Unsolved Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 <?php //Start the session so you would stay logged in.. //must be ABOVE ANY output session_start(); //Get the cmd variable $cmd=$_GET['cmd']; $idg=$_GET['id']; ?> remove this //Start the session so you would stay logged in.. //must be ABOVE ANY output that will give you the error message about header and dont put white space on the top of session start Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 I don't know what I am doing wrong but no matter what I delete I am still getting the same error message Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 to debug comment the session start then run if the same error occur the your declaration headers is the prob pls check note you cannot perform echo or printing if you will have the header function Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 To tell you the truth i have no idea what any of that means i mean i can provide the code but can you help me out Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 { header("Refresh:2;admin.php"); echo 'Go and login <-<'; } try to remove the echo like on that ^^ remove the echo Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 Parse error: parse error, unexpected $ in /home/content/d/r/e/drewsmedia/html/admin.php on line 82 I get that error at line 82 ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 can see the code Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 <?php //Start the session so you would stay logged in.. //must be ABOVE ANY output session_start(); //Get the cmd variable $cmd=$_GET['cmd']; $idg=$_GET['id']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> <title>ACP</title> </head> <body> <?php //include config.php include 'config.php'; //get the username from the form and add some security //so you cant get hacked so easy $username = mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username']))); $password = md5($_POST['password']); //if login button is pressed if ($_POST['login']){ //check if username and password are inserted if((!$username) || (!$password)){ //if not tell them to...do insert all of info echo "Please enter both values<br>";} //when they have we check if the username and the password exists $sql = mysql_query("SELECT * FROM `shoutbox_admin` WHERE `name` = '$username' AND `password`= '$password'") OR die(mysql_error()); //so we need to check it for real //mysql_num_rows() counts the rows which are returned as true $login_check = mysql_num_rows($sql); //if the check is true....true = 1 and $login check is set as $login_check=1 if($login_check > 0){ //so if it is larger than 1 we set some session variables - //username and id $r=mysql_fetch_array($sql); $_SESSION['id'] = $r['id']; $_SESSION['username'] = $r['name']; //if it's not let's make him suffer...moahahahaa... //reload the page I mean.. }else { header("Refresh:2;admin.php"); echo 'Go and login <-<'; } } //so if session username isn't set show user the login form if(!isset($_SESSION['username'])){ ?> <center> <form action='<?=$_SERVER['PHP_SELF']?>' method='POST'> Username: <input type='text' size='15' name='username'><br> Password: <input type='password' size='15' name='password'><br> <input name="login" type="submit" value="Submit"> </form></center> <? } //if not - show him the contents and stuff...else{ else{ //welcome message and logout link... echo "<center>Welcome, ". $_SESSION['username'] ."! <a href='logout.php'>Log Out</a></center>"; echo "<br><br><center>"; //see my ?id= browsing tutorial to understand switch() switch($cmd){ default: //getting all of the shouts and adding `delete me` link... $result = mysql_query("select * from shoutbox order by id desc"); while($r=mysql_fetch_array($result)) { $name=$r["name"]; $message=$r["message"]; $time=$r["time"]; $id=$r["id"]; echo "Shout by: ".$name." <strong>@</strong> ".$time."<br>".$message."<br><a href='?cmd=delete&id=".$id."'>Delete me</a><br><br>"; } break; case 'delete': $sql = "DELETE FROM shoutbox WHERE id=".$idg.""; $result = mysql_query($sql); header('Refresh:2;admin.php'); echo "deleted"; } ;} ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 <?php session_start(); //Get the cmd variable $cmd=$_GET['cmd']; $idg=$_GET['id']; //include config.php include 'config.php'; //get the username from the form and add some security //so you cant get hacked so easy $username = mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username']))); $password = md5($_POST['password']); //if login button is pressed if ($_POST['login']){ //check if username and password are inserted if((!$username) || (!$password)){ //if not tell them to...do insert all of info //echo "Please enter both values<br>"; } //when they have we check if the username and the password exists $sql = mysql_query("SELECT * FROM `shoutbox_admin` WHERE `name` = '$username' AND `password`= '$password'") OR die(mysql_error()); //so we need to check it for real //mysql_num_rows() counts the rows which are returned as true $login_check = mysql_num_rows($sql); //if the check is true....true = 1 and $login check is set as $login_check=1 if($login_check > 0){ //so if it is larger than 1 we set some session variables - //username and id $r=mysql_fetch_array($sql); $_SESSION['id'] = $r['id']; $_SESSION['username'] = $r['name']; //if it's not let's make him suffer...moahahahaa... //reload the page I mean.. }else { header("Refresh:2;admin.php"); exit(); } } //so if session username isn't set show user the login form if(!isset($_SESSION['username'])){ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> <title>ACP</title> </head> <body> <center> <form action='<?=$_SERVER['PHP_SELF']?>' method='POST'> Username: <input type='text' size='15' name='username'><br> Password: <input type='password' size='15' name='password'><br> <input name="login" type="submit" value="Submit"> </form></center> <? } //if not - show him the contents and stuff...else{ else{ //welcome message and logout link... echo "<center>Welcome, ". $_SESSION['username'] ."! <a href='logout.php'>Log Out</a></center>"; echo "<br><br><center>"; //see my ?id= browsing tutorial to understand switch() switch($cmd){ default: //getting all of the shouts and adding `delete me` link... $result = mysql_query("select * from shoutbox order by id desc"); while($r=mysql_fetch_array($result)) { $name=$r["name"]; $message=$r["message"]; $time=$r["time"]; $id=$r["id"]; echo "Shout by: ".$name." <strong>@</strong> ".$time."<br>".$message."<br><a href='?cmd=delete&id=".$id."'>Delete me</a><br><br>"; } break; case 'delete': $sql = "DELETE FROM shoutbox WHERE id=".$idg.""; $result = mysql_query($sql); header('Refresh:2;admin.php'); exit(); } } ?> Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 Try it just like that? Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 ya and tell me if theres an error Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 Parse error: parse error, unexpected T_STRING in /home/content/d/r/e/drewsmedia/html/admin.php on line 21 $sql = mysql_query("SELECT * FROM `shoutbox_admin` WHERE `name` = '$username' AND `password`= '$password'") OR die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 <?php session_start(); //Get the cmd variable $cmd=$_GET['cmd']; $idg=$_GET['id']; //include config.php include 'config.php'; //get the username from the form and add some security //so you cant get hacked so easy $username = mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username']))); $password = md5($_POST['password']); //if login button is pressed if ($_POST['login']){ //check if username and password are inserted if((!$username) || (!$password)){ //if not tell them to...do insert all of info //echo "Please enter both values"; } //when they have we check if the username and the password exists $sql = mysql_query("SELECT * FROM `shoutbox_admin` WHERE `name` = '$username' AND `password`= '$password'") OR die(mysql_error()); //so we need to check it for real //mysql_num_rows() counts the rows which are returned as true $login_check = mysql_num_rows($sql); //if the check is true....true = 1 and $login check is set as $login_check=1 if($login_check > 0){ //so if it is larger than 1 we set some session variables - //username and id $r=mysql_fetch_array($sql); $_SESSION['id'] = $r['id']; $_SESSION['username'] = $r['name']; //if it's not let's make him suffer...moahahahaa... //reload the page I mean.. }else { header("Refresh:2;admin.php"); exit(); } } //so if session username isn't set show user the login form if(!isset($_SESSION['username'])){ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> <title>ACP</title> </head> <body> <center> <form action='<?=$_SERVER['PHP_SELF']?>' method='POST'> Username: <input type='text' size='15' name='username'> Password: <input type='password' size='15' name='password'> <input name="login" type="submit" value="Submit"> </form></center> <? } //if not - show him the contents and stuff...else{ else{ //welcome message and logout link... echo "<center>Welcome, ". $_SESSION['username'] ."! <a href='logout.php'>Log Out[/url]</center>"; echo " <center>"; //see my ?id= browsing tutorial to understand switch() switch($cmd){ default: //getting all of the shouts and adding `delete me` link... $result = mysql_query("select * from shoutbox order by id desc"); while($r=mysql_fetch_array($result)) { $name=$r["name"]; $message=$r["message"]; $time=$r["time"]; $id=$r["id"]; echo "Shout by: ".$name." <strong>@</strong> ".$time." ".$message." <a href='?cmd=delete&id=".$id."'>Delete me[/url] "; } break; case 'delete': $sql = "DELETE FROM shoutbox WHERE id=".$idg.""; $result = mysql_query($sql); header('Refresh:2;admin.php'); exit(); } } ?> that should run cause it works fine on me Quote Link to comment Share on other sites More sharing options...
FortMyersDrew Posted June 27, 2007 Author Share Posted June 27, 2007 alright it works it brings up all the shouts however when i click delete the shout it goes to this Welcome, FortMyersDrew! Log Out[/url] Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/r/e/drewsmedia/html/admin.php:60) in /home/content/d/r/e/drewsmedia/html/admin.php on line 85 However it is deleting the files, but they are all put together like this aaaaaaaaaaaabbbbbbbbbbbbccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeffffffffffffffffffgggggggggggggggggggggghhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkklllllllllllllllllllllllllllllllll and when i delete one it kicks me off its still coming off line 85 header('Refresh:2;admin.php'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.