jesushax Posted February 21, 2008 Share Posted February 21, 2008 Hi here is my code, im new to php and dont know my way around error messages yet, i belive it to be something to do with undefined variables? yes? <?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php'); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CW Marketing Services</title> <link href="/includes/css/layout.css" rel="stylesheet" type="text/css" /> <link href="/includes/css/styles.css" rel="stylesheet" type="text/css" /> <script src="/includes/js/content.js" type="text/javascript"></script> </head> <body> <div id="container"> <a href="/default.php"><div id="header" style="cursor:pointer;"></div></a> <div id="left-column"> <?php if ( $_SESSION['UserAccess'] == True) { if ( $_SESSION['UserAdmin'] ==1) { include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_menu.inc'); } else{ include($_SERVER['DOCUMENT_ROOT'] . '/includes/user_menu.inc'); } } else{ include($_SERVER['DOCUMENT_ROOT'] . '/includes/default_menu.inc'); } if ( $_SESSION['UserAdmin'] ==0) { ?> <div class="menu-title-left"></div> <div class="menu-title-middle">News</div> <div class="menu-title-right"></div> <div style="clear:both;"></div> <?php } ?> </div> <div id="center-column"> here is my error message Notice: Undefined index: UserAccess in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/includes/header.php on line 17 Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/ Share on other sites More sharing options...
Sulman Posted February 21, 2008 Share Posted February 21, 2008 hi jesushax This error means that the index you are using in your session vars has not been set yet: <?php $_SESSION['UserAccess'] ?> you can check like this: <?php if(isset($_SESSION['UserAccess'])) { //do stuff } else { //oops, it's not set yet. } ?> Where do you set this session var first? Do you have session_start(); at the top of each page that uses sessions? Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472569 Share on other sites More sharing options...
jesushax Posted February 21, 2008 Author Share Posted February 21, 2008 thanks, what ive done now is check if the session exists using the isset then if the sesion exists check its values and disaplay the correct menus cheers however nother problem ina different page line green is line 12, not quite sure on how to parse these lines yet, ill be able to pick it up if you could show me once? Thanks! <? <? $result = mysql_query("SELECT TOP 3 * FROM tblUsers ORDER BY NewsDateAdded DESC"); while ($news = mysql_fetch_array($result)) echo "<table width=\"90%\" class=\"news\"><tr><td><strong style=\"font-size:12px;\">"; echo $news["title"]."</strong></td></tr>"."\n"; echo "<tr><td>"; if (IsNull ($news["image1"]) == "") { echo ""; } else { echo "<div style=\"float:right;\">"; [color=limegreen]echo "<img src=\"/news/uploads/." $news["image1"] ".\" style=\"width:80px;\" /></div>";[/color] } echo $news["shortstory"]."</td></tr>"."\n"; echo "<tr><td style=\"text-align:right;\"><a href=\"/news/full_news.asp?ID=."($news["newsid"])." \">read more...</a></td></tr></table>"; ?> Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/news/news_front.php on line 12 Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472583 Share on other sites More sharing options...
Sulman Posted February 21, 2008 Share Posted February 21, 2008 There you go: <?php echo "<img src=\"/news/uploads/".$news['image1']."\" style=\"width:80px;\" /></div>"; ?> Just some syntax issues. Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472594 Share on other sites More sharing options...
akitchin Posted February 21, 2008 Share Posted February 21, 2008 it should be noted that notices are not errors. they are distinct from one another in that notices are a sign of sloppy coding; errors will actually impair or halt the performance of your script entirely. to turn notices off (even though they are a good indicator of where you need to clean up your programming act), change the level of error reporting using error_reporting(). Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472603 Share on other sites More sharing options...
jesushax Posted February 21, 2008 Author Share Posted February 21, 2008 ok, i just started using php and needed to be shown how to use proper syntax, now i know mysql error now though :S $result = mysql_query("SELECT TOP 3 * FROM tblNews ORDER BY NewsDateAdded DESC"); while ($news = mysql_fetch_array($result)) Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/news/news_front.php on line 3 once in know what all these errors mean and what to look for, ill be ok with the rest of my site Cheers for any and all support though , its greatly apprectiated Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472605 Share on other sites More sharing options...
akitchin Posted February 21, 2008 Share Posted February 21, 2008 the actual error tells you that the $result is an invalid MySQL resource. what that translates to most often is that your query has a syntax error and that mysql_query() has failed to run a query properly. to diagnose query issues, use the following or die() clause: $result = mysql_query("SELECT TOP 3 * FROM tblNews ORDER BY NewsDateAdded DESC") or die(mysql_error()); what this does is tell the script to completely halt if mysql_query() fails and echo the resulting MySQL error. it should be standard practice while you're starting to learn PHP/MySQL because it's a useful debugging tool. Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472608 Share on other sites More sharing options...
jesushax Posted February 21, 2008 Author Share Posted February 21, 2008 cheers ill remember that sorted that one now now theres another one with my if statement hope im not being a pain here, but once i got it sussed ill be ok im trying so see if the record image1 has no data in it if it has no data in it, echo nothing if it does echo the image i get this error message Parse error: syntax error, unexpected T_IS_EQUAL in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/news/news_front.php on line 8 if ($news["image1"]) == "")) { echo ""; } else { echo "<div style=\"float:right;\">"; echo "<img src=\"/news/uploads/". $news["image1"]. "\" style=\"width:80px;\" /></div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472619 Share on other sites More sharing options...
aschk Posted February 21, 2008 Share Posted February 21, 2008 if ($news["image1"]) == "")) { should be if ($news["image1"] == "") { check your brackets... Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472625 Share on other sites More sharing options...
akitchin Posted February 21, 2008 Share Posted February 21, 2008 i should add that when checking if something is empty, use the empty() function. it works for more instances (see the manual for an explanation): if (empty($news['image1'])) Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472626 Share on other sites More sharing options...
jesushax Posted February 21, 2008 Author Share Posted February 21, 2008 thanks alot! picking up quite a bit of knowledge here, sorry to keep pesetering you until i got it sussed though :S whats wrong with this sql SELECT * FROM tblNews LIMIT 0,3 ORDER BY NewsDateAdded DESC You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY NewsDateAdded DESC' at line 1 that order by is fine is it not? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472631 Share on other sites More sharing options...
aschk Posted February 21, 2008 Share Posted February 21, 2008 Your LIMIT clause is in the wrong place corrected: SELECT * FROM tblNews ORDER BY NewsDateAdded DESC LIMIT 0,3 Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472640 Share on other sites More sharing options...
jesushax Posted February 21, 2008 Author Share Posted February 21, 2008 Thankyou! proper cracking on now i am lol, getting loads figured out just stumped here though <?php switch($_GET['mode']){ case 'done': include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php'); echo "Account has been created."; include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); break; case 'add': $strUserName = mysql_real_escape_string($_POST["txtUserName"]); $strFirstName = mysql_real_escape_string($_POST["txtFirstName"]); $strlastName = mysql_real_escape_string($_POST["txtLastName"]); $strTel = mysql_real_escape_string($_POST["txtTel"]); $strHomePage = mysql_real_escape_string($_POST["txtHomePage"]); $strCompanyName = mysql_real_escape_string($_POST["txtCompanyName"]); $strUserPass = md5($_POST["txtUserPass"]); $strEmail = mysql_real_escape_string($_POST["txtEmail"]); $strDate = date("d/m/y"); if(!strlen($strUserName)){ $error = '<p style="color:#FF0000;">Error: Username Was Left Blank</p>'; }elseif(!strlen($strEmail)){ $error = '<p style="color:#FF0000;">Error: Email Was Left Blank</p>'; }else{ if (mysql_query("SELECT UserName From tblUsers Where UserName=". $strUserName ." ")or die(mysql_error()) ) { $error = '<p style="color:#FF0000;">Error: Username Taken</p>'; } else{ mysql_query("INSERT INTO tblUsers (UserName, UserPassword, UserEmail, UserCompanyName, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded, UserSuspend) Values( '".$strUserName."', '".$strUserPass."', '".$strEmail."', '".$strCompanyName."', '".$strFirstName."', '".$strLastName."', '".$strTel."', '".$strHomePage."', '".$strDate."', '1')") or die(mysql_error()); header('Location: ?mode=done'); exit; } } default: include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php'); echo $error; mysql_close($con); ?> <b>Register for an account</b> <form id="Profile" method="post" action="?mode=add"> <table width="100%" border="0" style="padding:0px; margin:0px;"> <tr> <td>Username: </td> <td><input type="text" name="txtUserName" size="50" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="txtUserPass" size="25" /></td> </tr> <tr> <td>Confirm Password:</td> <td><input type="password" name="txtUserPass2" size="25" /></td> </tr> <tr> <td>Email Address:</td> <td><input type="text" name="txtEmail" size="50" /></td> </tr> <tr> <td>Company Name</td> <td><input type="text" name="txtCompanyName" size="50" /></td> </tr> <tr> <td>First Name:</td> <td><table width="100%" border="0" style="padding:0px; margin-left:-3px;"> <tr> <td><input type="text" name="txtFirstName" size="20" /></td> <td> Last Name:</td> <td><input type="text" name="txtLastName" size="20" /></td> </tr> </table></td> </tr> <tr> <td>Website Address</td> <td><input type="text" name="txtHomePage" size="50" /></td> </tr> <tr> <td>Tel: </td> <td><input type="text" name="txtTel" size="15" /></td> </tr> <tr> <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Submit Registration" alt="Enter" /> <input type="Reset" name="Reset" value="Cancel" alt="Cancel" /></td> </tr> </table> </form> * a valid working email is required as your login and activation information will be sent there, thankyou. [color=teal]<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?>[/[/color]code] line 89 is teal error: [quote]Parse error: syntax error, unexpected $end in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/register.php on line 89[/quote] nothing the matter with that line though is there :S Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472646 Share on other sites More sharing options...
akitchin Posted February 21, 2008 Share Posted February 21, 2008 an unexpected $end on the last line of your script means that you are missing a closing brace "}" somewhere. go back through your script and count the braces, making sure that each one is matched as necessary. Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472666 Share on other sites More sharing options...
jesushax Posted February 21, 2008 Author Share Posted February 21, 2008 checked and double checked now, counted theres 12 so even ammount thats right getting different error now Parse error: syntax error, unexpected T_STRING in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/register.php on line 30 brown is line 30 Thanks <?php switch($_GET['mode']){ case 'done': include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_header.php'); echo "Account has been created."; include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_footer.php'); break; case 'add': $strUserName = mysql_real_escape_string($_POST["txtUserName"]); $strFirstName = mysql_real_escape_string($_POST["txtFirstName"]); $strlastName = mysql_real_escape_string($_POST["txtLastName"]); $strTel = mysql_real_escape_string($_POST["txtTel"]); $strHomePage = mysql_real_escape_string($_POST["txtHomePage"]); $strCompanyName = mysql_real_escape_string($_POST["txtCompanyName"]); $strUserPass = md5($_POST["txtUserPass"]); $strEmail = mysql_real_escape_string($_POST["txtEmail"]); $strDate = date("d/m/y"); if(!strlen($strUserName)) { $error = '<p style="color:#FF0000;">Error: Username Was Left Blank</p>'; } elseif(!strlen($strEmail)){ $error = '<p style="color:#FF0000;">Error: Email Was Left Blank</p>'; } else{ if (mysql_query("SELECT UserName From tblUsers Where UserName=". $strUserName ." ")or die(mysql_error()) ) { $error = '<p style="color:#FF0000;">Error: Username Taken</p>'; } else{ mysql_query("INSERT INTO tblUsers (UserName, UserPassword, UserEmail, UserCompanyName, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded, UserSuspend) Values( '".$strUserName."', '".$strUserPass."', '".$strEmail."', '".$strCompanyName."', '".$strFirstName."', '".$strLastName."', '".$strTel."', '".$strHomePage."', '".$strDate."', '1')") or die(mysql_error()) [color=brown]header('Location: ?mode=done')[/color] exit; } } break; default: include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_header.php'); echo $error; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472674 Share on other sites More sharing options...
uniflare Posted February 21, 2008 Share Posted February 21, 2008 for a note dont try to make lines a specific color, we can count and it slows us down. change these lines mysql_query("INSERT INTO tblUsers (UserName, UserPassword, UserEmail, UserCompanyName, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded, UserSuspend) Values( '".$strUserName."', '".$strUserPass."', '".$strEmail."', '".$strCompanyName."', '".$strFirstName."', '".$strLastName."', '".$strTel."', '".$strHomePage."', '".$strDate."', '1')") or die(mysql_error()) header('Location: ?mode=done') exit; } to this mysql_query("INSERT INTO tblUsers (UserName, UserPassword, UserEmail, UserCompanyName, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded, UserSuspend) Values( '".$strUserName."', '".$strUserPass."', '".$strEmail."', '".$strCompanyName."', '".$strFirstName."', '".$strLastName."', '".$strTel."', '".$strHomePage."', '".$strDate."', '1')") or die(mysql_error()); header('Location: ?mode=done'); exit; }[/ Quote Link to comment https://forums.phpfreaks.com/topic/92247-undefined-index-error-message/#findComment-472676 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.