DarkHavn Posted August 26, 2006 Share Posted August 26, 2006 I don't know what is going on, everything with my process.php script was running fine.Then all of a sudden i turned on my laptop and the whole process.php script is falling apart, every header(); i have done in for re-direction to other pages after insering, or looking through the database.Dunno whats going on, but the header i have is on line 57 (of a 300odd line process page) that is the first header and it stuffs up, heres the following code up till that line[code] //Welcome to the process page, //The following are functions for connecting to the database function connect() { mysql_connect('localhost', 'root', ''); mysql_select_db('localfind'); } //The current function selects the agent database and selects all information so it can easily be searched //if it doesnt connect the proper actions are taking and the ip and error message are recorded into the database function agentdb_select() { connect(); if(mysql_select_db('agent')) { $query ='SELECT * FROM agent'; mysql_query("$query"); } else { mysql_select_db('information'); $error = mysql_error(); $query = 'INSERT INTO INTO information (ip, error) VALUES (' . "$ip" . "$error" . ')'; mysql_query("$query"); } } //The following is used for encryption purposes (md5()) function encrypt($pass) { md5("$value"); } //The following functions are for security, stripping the slashes and going through all of the input from the forms //to make sure there isn't anything that isn't supposed to be inserted into the database. //Strips tags and slashes and replaces with the correct measures function clean($post) { strip_tags("$value"); stripslashes("$value"); } /*if($_POST['newclient']){ header('location: ../newagent/newagent.php'); } */ //This section receives the post and sets a session variable because the stupid php query link didn't //seem to like my mysql and phpadmin lol if($_POST['newagent']) { header("Location: ../newagent/newagent.php"); } [/code](If you look closley the first 50 od lines are mainly //comments)Please guys any help would be appreciated im really stuck and only have a few hours left to debug this :( Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/ Share on other sites More sharing options...
kenrbnsn Posted August 26, 2006 Share Posted August 26, 2006 If "everything" was working and "suddenly" it's not, what did you change?Also, what do you mean by "it's not working" -- errors, results, non-results, what is it doing or not doing.Just a few comments:These two functions don't do anything:[code]<?php function encrypt($pass) { md5("$value"); } //The following functions are for security, stripping the slashes and going through all of the input from the forms //to make sure there isn't anything that isn't supposed to be inserted into the database. //Strips tags and slashes and replaces with the correct measures function clean($post) { strip_tags("$value"); stripslashes("$value"); }?>[/code]In order for them to do anything, you need to do something with the variable you pass to the functions and return the value, something like:[code]<?php function encrypt($pass) { return(md5($pass)); } //The following functions are for security, stripping the slashes and going through all of the input from the forms //to make sure there isn't anything that isn't supposed to be inserted into the database. //Strips tags and slashes and replaces with the correct measures function clean($post) { return (striptags(stripslashes($post))); }?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80713 Share on other sites More sharing options...
DarkHavn Posted August 26, 2006 Author Share Posted August 26, 2006 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\xampp\htdocs\localfind\process\process.php:141) in C:\xampp\xampp\htdocs\localfind\process\process.php on line 152Thats one of the errors that im getting, it's continously that, and now even my mysql queries with mysql_num_rows condition statement isn't working either.The only thing i had been building on was a search function, but i commented that out to see if that was what was stuffing around with everything but it hasn't.It's weird, lol and very unexpected. Can header(); stuff up on it's self, is there anyway to clear the header or something long those lines?for my mysql_num_rows i have the following[code]if($_POST['cata2']) { connect(); $username = $_POST['agentlogin']; $pass = md5($_POST['agentpass']); $mysqlquery = "SELECT * FROM agent WHERE `names`='$username' AND `pass`='$pass'"; $mysqlquery2 = mysql_query("$mysqlquery"); if(mysql_num_rows(mysql_query("SELECT * FROM agent WHERE `names`='$username' AND `pass`='$pass'") == 1)) { $loggedinquery = "UPDATE agent SET loggedin='1' WHERE `name`='$username' "; mysql_query("$loggedinquery"); $_SESSION['username'] = $username; $_SESSION['login'] = true; unset($username); unset($pass); header("Location: ../newagent/newagent.php"); } else { $_SESSION['loginerror'] = "Sorry the information you supplied was Incorrect, try again."; header("Location: ../newagent/newagent.php"); } } [/code] Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80721 Share on other sites More sharing options...
kenrbnsn Posted August 26, 2006 Share Posted August 26, 2006 What's a line 152 of process.php? That's where PHP think's you've written something to the screen.Ken Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80731 Share on other sites More sharing options...
DarkHavn Posted August 26, 2006 Author Share Posted August 26, 2006 That's the thing, ive debugged it all and went through it, everything above it, and after it is working properly, that's why i can understand why the header won't redirect.There is nothing being outputted before the redirection happens, it's fucked up.I'm currently just going through the script and making small alterations to get alet a temp set up for the presentation tomorrow so some redirection works.I have no idea to what it could be though.Line 152 was a simple if($_POST['login']){//connects to the database and checks the information is really the users//then redirects}debugged that 50 times over, the queries work, and find the user, but then it wont redirect Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80747 Share on other sites More sharing options...
kenrbnsn Posted August 26, 2006 Share Posted August 26, 2006 Somewhere the script is sending a character to the screen. Did you read the sticky topic at the top of thie forum here? Are you sure you have no unseen characters before the first "<?php"?Ken Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80767 Share on other sites More sharing options...
wildteen88 Posted August 26, 2006 Share Posted August 26, 2006 According to the error some from of output was detected around line 141 in process.php. Post the code from lines 136 through to 146 here. Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80768 Share on other sites More sharing options...
DarkHavn Posted August 26, 2006 Author Share Posted August 26, 2006 [code] if($_POST['logout']) { connect(); //$logout = ; $username = $_SESSION['username']; $logout = "UPDATE agent SET `loggedin`='0' WHERE `name`='$username';"; if(mysql_query("$logout")) { $_SESSION['login'] = false; header("Location: ../index.php"); }else { $error = mysql_error(); $ip = $_SERVER['REMOTE_ADDR']; $errorquery = "INSERT INTO information (`error`, `ip`) VALUES ('$error', '$ip');"; mysql_query('$errorquery'); } //header("Location: ../index.php"); } [/code]lines 130-146 Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80770 Share on other sites More sharing options...
wildteen88 Posted August 26, 2006 Share Posted August 26, 2006 How strange. Everthink is fine there. Not sure then. Is this the ony error message you get. Do you get any notice messages or any other error messages.The only thing I can see that isnt ok which is this:[code]mysql_query('$errorquery');[/code]Change that to:[code]mysql_query($errorquery);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80772 Share on other sites More sharing options...
DarkHavn Posted August 26, 2006 Author Share Posted August 26, 2006 i just got errors back from the headers(); and also my mysql_fetch_assoc, and mysql_num_rows, but ive debugged them all and they work fine, it's really confusing lolThink i might just redo the thing again it's starting to piss me off Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80773 Share on other sites More sharing options...
wildteen88 Posted August 26, 2006 Share Posted August 26, 2006 There is one more option which I dont like when it comes to this. Its to use output buffering.Add ob_start(); at the top of process.php. so it is just under <?phpand add ob_end_flush(); at the bottom of process.php so its just before ?>Do you get any errors now? Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80777 Share on other sites More sharing options...
DarkHavn Posted August 26, 2006 Author Share Posted August 26, 2006 ah its abit late to go back now, i'm redoing the process page, and going through it section by section, and clearing up anything.Cheers for the help though, i will mark this solved for now. But if the problem still appears when i try the process.php page again i will try your advice and post another topic.Cheers for the help :) Quote Link to comment https://forums.phpfreaks.com/topic/18719-header-problem/#findComment-80782 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.