HogDog Posted August 5, 2008 Share Posted August 5, 2008 Hello all first time poster here, I'm new to PHP and have run into some trouble. What I want to do is when a user logs in a session is created using a company name (a username basically). Then once the user has logged in they are redirected to account.php which takes the session created when the user logged in and sees what the companies corresponding url in the mysql database is then redirects the user to that url. Now everything works fine until the user gets to the accounts page and the output is the following: logged in Unknown column 'company_name' in 'where clause' Heres the php for account.php <?php $query = mysql_connect("*********", "******", "***********") or die(mysql_error()); mysql_select_db('******', $query) or die(mysql_error()); session_start(); if(isset($_SESSION['Company'])) { echo "logged in <br/>" ; $query = mysql_query("SELECT url FROM links WHERE company = " . $_SESSION['Company'] . " LIMIT 1") or die(mysql_error()); list($url) = mysql_fetch_row($query); header('Location: . $url .'); die('<a href=". $url .">Contiune</a>'); } else { header('location: login.php'); } ?> Thanks for the help, -HogDog Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 5, 2008 Share Posted August 5, 2008 Well, seeing as your query doesn't "appear" to have company_name in it, I would have to assume either 1) That is not the query creating the error or 2) The variable you are using has more information in it that it should. Also, you are not enclosing the value of $_SESSION['Company'] within single quotes in the query. Unless the value is a number, the query will also fail. You should create your queries as a variable so you can echo them to the page when an error occurs for debugging purposes. <?php $query = mysql_connect("*********", "******", "***********") or die(mysql_error()); mysql_select_db('******', $query) or die(mysql_error()); session_start(); if(isset($_SESSION['Company'])) { echo "logged in <br>" ; $query = "SELECT url FROM links WHERE company = '" . $_SESSION['Company'] . "' LIMIT 1"; $result = mysql_query($query) or die("Query:<br>$query<br>Error:<br>".mysql_error()); list($url) = mysql_fetch_row($result); header('Location: . $url .'); die('<a href=". $url .">Contiune[/url]'); } else { header('location: login.php'); } ?> Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 5, 2008 Share Posted August 5, 2008 I used to use this lol Its from ages ago so it's a bit crap lol <?php function sqlErr($line = NULL,$file = NULL,$err = NULL){ echo '<link rel="stylesheet" type="text/css" href="style.css" />'; $l = "<font color='red'><strong>A SYNTAX error has occured, please read on...<br /><br />"; if ($err != NULL){ $l1 = "Error: ".$err."<br /><br />"; }else{ $l1 = ""; } if ($file != NULL){ $l2 = "File: ".$file."<br /><br />"; }else{ $l1 = ""; } if ($line != NULL){ $l3 = "Line: ".$line."<br /><br />"; }else{ $l3 = ""; } $l4 = "Please report this to an administrator.</strong></font>"; $fullLine = $l.$l1.$l2.$l3.$l4; $return = '<table width="500" height="300" border="1" cellspacing="0" cellpadding="0" valign="middle" align="center" bordercolor="red"> <tr><td align="center"><h3><font color="red"><strong>[ ERROR ]</strong></font></h3></td></tr> <tr><td align="center">'.$fullLine.'</td></tr> </table>'; return $return; } function displayError($errormsg = NULL){ if ( (!empty($errormsg)) && ($errormsg != NULL) ){ echo '<center><fieldset class="fieldset" width="500"><legend><strong><font color="red">Error:</strong></legend>'.$errormsg.'</font></fieldset></center>'; } } function displayUpdate($successMsg = NULL){ if ( (!empty($successMsg)) && ($successMsg != NULL) ){ echo '<center><fieldset class="fieldset" width="500"><legend><strong><font color="green">Error:</strong></legend>'.$successMsg.'</font></fieldset></center>'; } } mysql_query($query)or die(sqlErr(__LINE__.__FILE__.mysql_error())); ?> Quote Link to comment Share on other sites More sharing options...
HogDog Posted August 5, 2008 Author Share Posted August 5, 2008 Thanks guys that solved one problem but now I have another, when the page redirects the URL reads: http://www.mysite.com/.%20$url%20. Heres my updated PHP: <?php ob_start(); $query = mysql_connect("*************", "******", "********") or die(mysql_error()); mysql_select_db('*******', $query) or die(mysql_error()); session_start(); if(isset($_SESSION['Company'])) { echo "logged in <br>" ; $query = "SELECT url FROM links WHERE company = '" . $_SESSION['Company'] . "' LIMIT 1"; $result = mysql_query($query) or die("Query:<br>$query<br>Error:<br>".mysql_error()); list($url) = mysql_fetch_row($result); header('Location: . $url .'); die('<a href=". $url .">Contiune</a>'); } else { header('location: login.php'); } ?> thanks again -HogDog Quote Link to comment Share on other sites More sharing options...
abdfahim Posted August 5, 2008 Share Posted August 5, 2008 can you tell us what is the listed url against the concern company name in your database? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 5, 2008 Share Posted August 5, 2008 Thanks guys that solved one problem but now I have another, when the page redirects the URL reads: http://www.mysite.com/.%20$url%20. it's because you're using variables within single quotes. PHP wont parse variables within single quotes. header('Location: . $url .'); die('<a href=". $url .">Contiune</a>'); The above line should be header("Location: $url"); die('<a href="'. $url .'">Contiune</a>'); 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.