PHP - Find Out If Error When A File Was Included
Say I have...
Code: [Select] <? echo("do something"); include("include_file.php"); echo("do something else"); ?> include_file.php Code: [Select] <? $a_$string = "a string"; echo($a_string); ?> I have put an error in the include_file.php an extra $ in the variable name. The first script would kick up an error that there is a problem with file include_file.php as line 3 or what ever the line may be. How can I have it so I can choose what the error message is, say a cryptic code and the line number without having the file names show as this is showing up my hidden includes folder and the file name which means that someone may try to visit this page alone and this can cause security issues. Adding in extra lines to every file to see if it is being use correctly a bit like sessions is not an option although I have looked at it as I have houndreds of files to alter in this case. I have just tried this instead of the top script but I does not show the secret code on error Code: [Select] <? echo("top"); @include("dummy.php") or die("secreterrorcode123"); echo("bottom"); ?> Similar TutorialsHow can i find out parent (including) file of included file? Lets imagine that we want to for example auto_prepend file to each file on our server that would write out the name of file its being executed. I know, i can use PHP_SELF but what if i want to write name of file which is already included? I have a web page and i want on it show its name even if it was included, but not the included page itself is showing name but auto_prepend file to each php file, its duty of this auto_prepend_file to write it out i dont want myself to echo it on each page? do you feel me? how to get the name of the file including a file from the included file, This one has me mixed up a bit.. I am trying to record site activity information from a common.php file using a user object. But since the file is included into different php files based on different situations I need a dynamic way of finding the file name that is including it. I could be over complicating things but right now this seems like the best solution other wise I'll have to rewrite the code on every page i write. Is there a function for doing this? Or if someone gets what I'm trying to do if they could point me to the direction of some more information on it. Thanks. I understand that this is a header error but i still do not know how to fix it. I am trying to create a login box that is in the top right corner of my site. Once the user uses it to log in they need to be redirected to the account page. i include the login_box.php file in the appropriate div. however the file uses header("Location: account.php"); to redirect the user. because this file is included after the header i receive Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\index.php:17) in C:\xampp\htdocs\layout_inc\login_box.php on line 76 What would be the correct way to do this. My code is bellow. Thank you in advance <?php //Forms posted if(!empty($_POST)) { $errors = array(); $username = trim($_POST["username"]); $password = trim($_POST["password"]); $remember_choice = trim($_POST["remember_me"]); //Perform some validation //Feel free to edit / change as required if($username == "") { $errors[] = lang("ACCOUNT_SPECIFY_USERNAME"); } if($password == "") { $errors[] = lang("ACCOUNT_SPECIFY_PASSWORD"); } //End data validation if(count($errors) == 0) { //A security note here, never tell the user which credential was incorrect if(!usernameExists($username)) { $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID"); } else { $userdetails = fetchUserDetails($username); //See if the user's account is activation if($userdetails["Active"]==0) { $errors[] = lang("ACCOUNT_INACTIVE"); } else { //Hash the password and use the salt from the database to compare the password. $entered_pass = generateHash($password,$userdetails["Password"]); if($entered_pass != $userdetails["Password"]) { //Again, we know the password is at fault here, but lets not give away the combination incase of someone bruteforcing $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID"); } else { //Passwords match! we're good to go' //Construct a new logged in user object //Transfer some db data to the session object $loggedInUser = new loggedInUser(); $loggedInUser->email = $userdetails["Email"]; $loggedInUser->user_id = $userdetails["User_ID"]; $loggedInUser->hash_pw = $userdetails["Password"]; $loggedInUser->display_username = $userdetails["Username"]; $loggedInUser->clean_username = $userdetails["Username_Clean"]; $loggedInUser->remember_me = $remember_choice; $loggedInUser->remember_me_sessid = generateHash(uniqid(rand(), true)); //Update last sign in $loggedInUser->updateLastSignIn(); if($loggedInUser->remember_me == 0) $_SESSION["userCakeUser"] = $loggedInUser; else if($loggedInUser->remember_me == 1) { $db->sql_query("INSERT INTO ".$db_table_prefix."Sessions VALUES('".time()."', '".serialize($loggedInUser)."', '".$loggedInUser->remember_me_sessid."')"); setcookie("userCakeUser", $loggedInUser->remember_me_sessid, time()+parseLength($remember_me_length)); } //Redirect to user account page header("Location: account.php"); die(); } } } } } if(!isUserLoggedIn()) {?><form name="newUser" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <table> <tr> <td> <label>Username:</label> </td> <td> <input type="text" name="username" /> </td> </tr> <tr> <td> <label>Password:</label> </td> <td> <input type="password" name="password" /> </td> </tr> <tr> <td> <label> </label> <input type="submit" value="Login" class="submit"/> </td> <td> <input type="checkbox" name="remember_me" value="1" /> <label style="font-size:12px">Remember Me?</label> </td> </tr> </table> <div style="text-align:center;"> <a href="register.php" class="info">Register</a> | <a href="forgot-password.php" class="info">Forgot Password?</a> </div> </form><?php } else{?><h1>Welcome <?php echo $loggedInUser->display_username; ?> </h1> <br/> <a href="account.php" class="info">Dashboard</a> | <a href="logout.php" class="info">Logout</a><?php } ?> Hello: I have this code in an included file: myNav.php Code: [Select] function spLeftMenu() { $spLeftMenu = " <p> <div id=\"myLeftNavPaper\"> <img src=\"images/sidePaperTop.png\" alt=\"\" /> <div id=\"myLeftNavPaper2\"> echo \". $mySideBarPageData .\" </div> <img src=\"images/sidePaperBottom.png\" alt=\"\" /> </div> </p> "; return $spLeftMenu; } I can not get: Code: [Select] echo \". $mySideBarPageData .\" To display the results on this page: Page.php Code: [Select] <html> ... <?php echo spLeftMenu(); ?> ... </html> What am I missing ?? Hi, My issue here is that I cant get my if/else statement to work on my secondary page. I include my secondary page (fine.php) from my index page. However, I have an if/else statement in fine.php that keeps reverting back to the index.php and, therefore, outputs the else statement (404.php) here is the if/else on index.php (these links work fine): <?php if($_SERVER['QUERY_STRING']=='/index.php' || $_SERVER['QUERY_STRING']=='') { include 'port.php'; } elseif (isset($_GET['pos'])){ include 'pos.php'; } elseif (isset($_GET['web'])){ include 'web.php'; } elseif (isset($_GET['fine'])){ include 'fine.php'; } else {include '404.php';} here is the if/else on my secondary page (fine.php). These links are supposed to alert the if/else in the next table cell. However, they instead alert the if/else in index.php. <td><br/> <a href="?backset"><img src="fine/thumbs/x-backset.jpg" border="0"></a><br/><br/> <a href="?backside"><img src="fine/thumbs/x-backside.jpg" border="0"></a><br/><br/> <a href="?bannerprint"><img src="fine/thumbs/x-bannerprint.jpg" border="0"></a><br/><br/> <a href="?chopu"><img src="fine/thumbs/x-chopu.jpg" border="0"></a><br/><br/> </td> <td><br/> <div id="DivPiece" align="left"> <?PHP if (isset($_GET['backset'])){ include 'fine/backset.php'; } elseif (isset($_GET['backside'])){ include 'fine/backside.php'; } elseif (isset($_GET['bannerprint'])){ include 'fine/bannerprint.php'; } elseif (isset($_GET['chopu'])){ include 'fine/chopu.php'; } ?> </div> </td> How can I get the links on the secondary page to only alert the if/else statement on that page, and BLOCK the if/else statement on index.php from seeing them? I still want to use the query string though. Thanks! Main script gets class information from a database and prints them so long as the class start date or end date is after today (actually includes today).
Main script calls "instructors.php". It queries another database based on the instructor name ($chef) and then prints the bio information for that instructor.
"instructors.php" works fine on it's own, when I add "$chef = "Chef Name" ("Chef Name" is in the Instructors database). When it's called from the main script, nothing shows up in that area - even though "Chef Name" is in the database. All of the other data is printed fine, just not anything from instructors.php. I verified that it's actually including the file, as I can add "echo "test";" to the top of instructors.php and it prints fine in the main script.
Any ideas of what I'm missing?
Main Script
<?php // Get required login info include "/path/to/login/info/file.php"; // Get required login info - changed for this post. $db = new mysqli('localhost', $username, $password, $database); // Connect to DB using required login info if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } unset($username);// put these variables back to null unset($password);// put these variables back to null unset($database);// put these variables back to null //query db $sql = <<<SQL SELECT * FROM `ft_form_7` WHERE DATE(class_start_date) >= CURDATE() OR DATE(class_end_date) >= CURDATE() ORDER BY class_start_date ASC SQL; if(!$result = $db->query($sql)){ // if there is an error in running the query, show error message. die('There was an error running the query [' . $db->error . ']'); } while($row = $result->fetch_assoc()){ // Get start date information $start_date = $row['class_start_date']; // Get event_start_date for conversion and call it $start_date $start_date_formatted = date("l M d, Y", strtotime($start_date)); // Convert start_date $end_date = $row['class_end_date']; // Get event_end_date for conversion and call it $start_date $end_date_formatted = date("M d, Y", strtotime($end_date)); // Convert start_date // Get time information. $start_time = $row['class_start_time']; // Get event_start_time for conversion and call it $start_time $start_time_formatted = date("h:i A", strtotime($start_time)); // Convert start_time $end_time = $row['class_end_time']; // Get event_end_time for conversion and call it $end_time $end_time_formatted = date("h:i A", strtotime($end_time)); // Convert end_time // echo information... echo "<h2>" , $row['class_name'],"</h2>" ; // echo event name echo "<p><strong>",$start_date_formatted; // echo the start date if (empty($start_time)) { echo ''; } else { echo " (", $start_time; } // echo start time if (empty($end_date)) { echo ''; } else { echo " -","<br />", $end_date_formatted; } // echo end date if (empty($end_time)) { echo ')'; } else { echo " - ", $end_time, ")"; } // echo end time // if there is no start time, echo nothing. (otherwise it seems to echo 4pm). If it does contain a time, echo the time. echo "</strong><br />"; $chef = $row['Instructor']; global $chef; if ($chef != NULL) { require ('instructors.php'); } echo $row['class_description'], "<br />"; echo "<strong>" , $row['type'], " - Cost: $",$row['cost'] , " - #" , $row['course_number'] , "</strong><br />" , "</p>"; // echo class type and cost } $db->close(); $result->free(); ?>instructors.php <?php include "/path/to/login/info/file.php"; // Get required login info - changed for this post. $db_instructors = new mysqli('localhost', $username, $password, $database); // Connect to DB using required login info if($db_instructors->connect_errno > 0){ die('Unable to connect to database [' . $db_instructors->connect_error . ']'); } unset($username);// put these variables back to null unset($password);// put these variables back to null unset($database);// put these variables back to null //query db $sql_instructors = <<<SQL SELECT * FROM ft_form_8 WHERE chef_name = '$chef' SQL; if(!$result_instructors = $db_instructors->query($sql_instructors)) { // if there is an error in running the query, show error message. die('There was an error running the query [' . $db_instructors->error . ']'); } while($row_instructors = $result_instructors->fetch_assoc()) { $chef_full_name = $row_instructors['chef_name']; $chef_id = $row_instructors['submission_id']; $full_bio = $row_instructors['full_bio']; echo "<a href=\"#\" class=\"clickme\">" , $chef_full_name , "</a>"; echo "<div class=\"box\">"; echo $full_bio , "</div>"; } $db_instructors->close(); $result_instructors->free(); ?> Hello, In m script, I need to get the content of another php file as a string, including the content of all the files which are included in it and in lower levels. Any idea how to do it? I tried output buffer+include but it doesn't get the content of the included files. Thanks Hello. Trying to learn MVC better by creating my own little framework to understand how it works. Things were going OK til now. I have a base class: <?php /** * Base class most classes will extend from. * Simply put, this class just has methods that * most, if not all, classes will need. */ class Application { public function includer($path) { if (is_readable($path) == true) { include_once($path); } else { die("404 not found =["); } } } ?> So the above method 'includer' just sees if a file exists/is readable and if so, include it. Here's where I am using said method. class Index extends Application { function __construct($method = 'view') { // load the index model include(ROOT . '/app/models/model.index.php'); // Invoke requested method. $this->$method(); } public function view() { $name = 'Smith'; $this->includer(ROOT . '/app/views/view.index.php'); # Problem here, i think } } view.index.php just contains <?php echo $name; ?> All that is called from the index page, with this line of code Application::includer($controller_path); Now, in line $this->includer(ROOT . '/app/views/view.index.php'); # Problem here, i think If i get rid of $this->includer, the script will work and say 'Smith'. If i have $this->includer(...) or parent::includer(...), it doesn't work. why? I have a snippet of code like this below. If I have it directly on my page, it works fine. But if I move this snippet of code into an include file and use "require_once('thefile.php');", the code no longer works properly. How is that possible? FYI, this snippet is in the middle of a for loop on the regular page. Maybe you can't use includes when in a loop? I don't know. Makes no sense that it works when on the page, but not when included using require once. Any thoughts how this could be possible? I imagine there is some rule with include files that I'm missing??? This is the code and I don't think it matters exactly what its doing so I won't bother you with that. This is how it looks on the page itself... Code: [Select] if ($type=="one") { $_SESSION['cluenum']=1; //so clue #1 begins as the selected clue echo "<script type='text/javascript'>document.getElementById('clue1').style.border = '1px solid red';</script>"; //sets the styling on clue #1 $allcode = "onclick='setnumber($i);'"; } else { // type must be equal to all, so don't do anything special $allcode=""; } This is how it looks in the include file... Code: [Select] <?php if ($type=="one") { $_SESSION['cluenum']=1; //so clue #1 begins as the selected clue echo "<script type='text/javascript'>document.getElementById('clue1').style.border = '1px solid red';</script>"; //sets the styling on clue #1 $allcode = "onclick='setnumber($i);'"; } else { // type must be equal to all, so don't do anything special $allcode=""; } ?> Code: [Select] $date = date('m-d-y'); $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO users VALUES ($username, $password, 0, $ip, $date)") or die(mysql_error()); Error: 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 '.60.116, 03-06-11)' at line 1 I'm not sure why I get this error. :/ So, I feel like I am running up against some beginner's problem. So I am hoping this should be an easy fix. I have had a bit of trouble finding the right search terms to find a fix for this, so I am sorry ahead of time if there is already a post on this, please point me towards it. I am running PHP 4.4.9 and MySQL client API 4.1.22, in case that is of use. I can get the following to work and provide the appropriate output. Note in this first case that the connection info is in the same file as the call to it. <?php // set database access information define ('DB_USER', "*****"); define ('DB_PASSWORD', "*****"); define ('DB_HOST', "localhost"); define ('DB_NAME', "content"); // database connection protocol $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); mysql_select_db (DB_NAME) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); $query = "SELECT content_element_title FROM content_main"; $result = mysql_query ($query); while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo ("<p>" . $row[content_element_title] . "</p>"); } unset($dbc); ?> My problem is, however, that when I separate the connection info into a separate file, I have been having problems. I think I got past the method calling the connection info not being able to see it, but now it isn't returning anything - should be returning "<p>" . $row[content_element_title] . "</p>", for which there are three rows in the db. Here is what the two files look like separated: kinnect.php <?php // set database access information define ('DB_USER', '*****'); define ('DB_PASSWORD', '*****'); define ('DB_HOST', 'localhost'); define ('DB_NAME', 'content'); //// database connection protocol $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); mysql_select_db (DB_NAME, $dbc) or die ('Could not connect to MySQL: Error #' . mysql_errno() . ' - ' . mysql_error()); ?> file.php <?php require_once ("correctpathto/kinnect.php"); $query = "SELECT content_element_title FROM content_main"; $result = mysql_query ($query, $dbc); while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo ("<p>" . $row[content_element_title] . "</p>"); } unset($dbc); ?> So what am I doing wrong? I am getting these error messages now. Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Users/max/Sites/rdbase-llc/preliminary/connecttroubleshoot.php on line 18 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Users/max/Sites/rdbase-llc/preliminary/connecttroubleshoot.php on line 20 Thanks ahead of time for any help! hey, I get this error on line 69 which is the end of my code, but I just can't find the missing or wrong curly bracket :s <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <p> <?php if(isset($_POST['_submit_check'])){ if($form_errors = validate_form()){ show_form($form_errors);} else{ process_form();}} else{ show_form();} function process_form(){ print "Hello, ".$_POST['user'];} if(array_key_exists('user', $_POST)){ process_form();} else{ show_form(); } function validate_form(){ $errors = array(); if(strlen($_POST['user']) < 1){ $errors[] = 'Your name must be at least 1 letter long.'; } return $errors;} if(array_key_exists('_submit_check', $_POST)){ if(validate_form()){ proces_form(); } else{ show_form();} } else{ show_form(); } function show_form($errors = ''){ if($errors){ print 'please correct these errors: <ul><li>'; print implode('</li><li>', $errors); print '</li></ul>'; } print<<<_HTML_ <form method = "POST" action="$_SERVER[PHP_SELF]"> Your name: <input type="text" name="user"> </br> <input type="submit" value="Verzenden"/> </br> <input type="hidden" name="_submit_check_" value="1"> </form> _HTML_; } ?> </p> </body> </html> this code works fine it I take out the checkboxes(repair & replace) in the html & PHP ? Code: [Select] <form name="form" action="<?php $_SERVER[PHP_SELF] ?>" method="post"> <input type="text" size="2" name="apt" id="apt" onkeyup="getResults();if(this.value.length==this.size)document.form.datereceived.focus();" />Apt<br /> <input type="text" size="25" name="name" id="name" />Name<br /> <INPUT TYPE="text" size=10 name="datereceived" onKeyUp="if(this.value.length==this.size)document.form.time.focus();">Date Received<br /> <INPUT TYPE="text" size=7 name="time">Time Received<br /> <br>Kitchen <select name="item"> <option value="kitchen blinds" selected>kitchen blinds</option> <option value="kitchen bifolds">kitchen bifolds</option> <option value="kitchen lights">kitchen light fixtures</option> <option value="kitchen bulbs">kitchen light bulbs</option> <option value="kitchen tile">kitchen tile/linoleum</option> <option value="kitchen countop">kitchen counter top</option> <option value="kitchen cabinets">kitchen cabinets</option> <option value="kitchen drawers">kitchen drawers</option> <option value="fridge">refidgerator</option> <option value="stove">stove</option> <option value="range hood">stove hood</option> <option value="kitchen sink">kitchen sink</option> <option value="under kitchensink">under kitchen sink</option> <option value="kitchen faucet">kitchen faucet</option> <option value="kitchen drain">kitchen drain</option> <option value="kitchen screens">kitchen windows & screens</option> <option value="fire extinguisher">fire extinguisher</option> <option value="kitchen wall plates">kitchen switch plates</option> <option value="kitchen outlets">kitchen electrical outlets</option> <option value="kitchen ceilings">kitchen ceiling paint</option> <option value="kitchen wallpaint">kitchen wall paint</option> </select> <br> repaired <input type=checkbox name="repair" value="Y"> replaced <input type=checkbox name="replace" value="Y"><br> </p> action<INPUT TYPE="text" size=100 name="action"><br /> <INPUT TYPE="text" size=2 name="compday" MAXLENGTH=2 onKeyUp="if(this.value.length==this.size)document.form.compmoyr.focus();"> <INPUT TYPE="text" size=7 name="compmoyr" MAXLENGTH=7 Date Completed - <font color=red>day then mm/yyyy</font <br /><br /> cost<INPUT TYPE="text" size=4 name="cost"> charge<INPUT TYPE="text" size=4 name="charge"> Order#<INPUT TYPE="text" size=4 name="ordno"> - If Insp <p> <INPUT type="submit" value="submit data" /> </p> </form><?php if (isset( $_POST['apt']) ) { $apt=$_POST['apt']; $name=$_POST['name']; $datereceived=$_POST['datereceived']; $time=$_POST['time']; $item=$_POST['item']; $repair=$_POST['repair']; $replace=$_POST['replace']; $action=$_POST['action']; $compday=$_POST['compday']; $compmoyr=$_POST['compmoyr']; $cost=$_POST['cost']; $charge=$_POST['charge']; $ordno=$_POST['ordno']; $stat = mysql_connect("localhost","root","") or die('Unable to connect to database: ' . mysql_error()); $stat = mysql_select_db("maintdb") or die('Unable to select database: ' . mysql_error()); $query = " INSERT INTO maintdata (apt,name,datereceived,time,item,repair,replace,action,compday,compmoyr,cost,charge,ordno) VALUES('$apt','$name','$datereceived','$time','$item','$repair','$replace','$action','$compday','$compmoyr','$cost','$charge','$ordno')"; echo "apt $apt data inserted</font><br /><br />"; $stat = mysql_query($query) or die('Query failed: ' . mysql_error()); mysql_close(); } ?> Hello I am new thought I would ask help here as I was not getting much help on another forum. I have this code Code: [Select] <?php header("content-type: text/xml"); $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>'; $rssfeed .= '<rss version="2.0">'; $rssfeed .= '<channel>'; $rssfeed .= '<title>My Price Savings Coupons.com Feed</title>'; $rssfeed .= '<link>http://www.mypricesavings.com</link>'; $rssfeed .= '<description>This is coupons.com feed</description>'; $rssfeed .= '<language>en-us</language>'; $rssfeed .= '<copyright>Copyright (C) 2011 mypricesavings.com</copyright>'; function compareFeeds($a, $b){ //this function will compare the "val" array element of each $itemRSS if ($a["val"] == $b["val"]) { return 0; } return ($a["val"] < $b["val"]) ? -1 : 1; } $doc = new DOMDocument(); $doc->load('http://rss.coupons.com/xmlserve.asp?go=14520kk5210'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'val' => $node->getElementsByTagName('value')->item(0)->nodeValue, 'image' => $node->getElementsByTagName('image')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'exp' => $node->getElementsByTagName('activedate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } usort($arrFeeds, 'compareFeeds'); foreach($arrFeeds as $itemRSS){ $descrip = '<![CDATA[ <p><a href="'.$itemRSS["link"].'"><img src="'. $itemRSS["image"].'" align="left" border="0" height="80" width="80" alt="'.$itemRSS["desc"].'"/></a></p>]]>'; $descrip .= '' .$itemRSS["desc"]; $rssfeed .= '<item>'; $rssfeed .= '<title>' . $itemRSS["desc"] . '</title>'; $rssfeed .= '<link>' . $itemRSS["link"] . '</link>'; $rssfeed .= '<pubDate>' . $itemRSS["exp"] . '</pubDate>'; $rssfeed .= '<description>'. $descrip . '</description>'; $rssfeed .= '</item>'; } $rssfeed .= '</channel>'; $rssfeed .= '</rss>'; echo $rssfeed; ?> The purpose of this code is to take http://rss.coupons.com/xmlserve.asp?go=14520kk5210 and turn it into a true RSS Feed. I currently have the php above at mypricesavings.com/coupons/couponsfeed.php I receive the error in google chrome on mac, however, in safari it does work, If I were to use RSS Graffiti on facebook it also errors Thank you for any help, Also, If there is a better more efficient way to accomplish what I am trying to do, please share with me so I may learn better Derrick line 11 the while loop <?php //include connect $connect = mysql_connect("localhost","root","") or die ("Could Not Connect To Server"); mysql_select_db('npcs') or die ("Could Not Select Database"); $query = mysql_query("SELECT * FROM npc WHERE LEVEL=1") or die ("Could Not query Database"); echo "<table width='220' border='1' align='center'><tr><th>NPC NAME</th><th>JOB DESCRIPTION</th></tr><tr><th>LEVEL</th></tr><tr><th>EXPERIENCE</th></tr><tr><th>CASH</th></tr><tr><th>REPUTATION</th></tr>" while ($row = mysql_fetch_array($query)) { //set varibles from query $npcname = $row['npcname']; $level = $row['level']; $jobdes = $row['jobdes']; $exper = $row['exper']; $cash = $row['cash']; $rep = $row['rep']; //end getting varibles echo "<tr align='center'><td>{$row['npcname']}</td><td>{$row['jobdes']}</td><td>{$row['level']}</td><td>{$row['exper']}</td><td>{$row['cash']}</td><td>{$row['rep']}</td></tr>"; } ?> Hi I am trying to learn php and am working on a cms website. I keep on getting this error 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 '[id]' at line 1 I looked at the MySql manual and cannot find what is wrong any suggestion would be greatly appreciated. Thank you. The is the line of code to link to the Edit.php page and holds the id of the post. echo "<a href=\"edit.php?id=$posts[ID]\">Edit</a>"; This is in the Edit page and it gives me the error above. <?php include('Connection.php'); $query = 'SELECT * FROM site_content WHERE ID = $_GET[id]'; $result = mysql_query($query) or die(mysql_error()); $post = mysql_fetch_array($result); ?> I cannot see the error. I'm getting syntax errors on line 61 and line 67 indicated in comments on form. What am I missing? <?php $submit = $_POST['submit']; // Form Data $email = strip_tags($_POST['email']); $salonname = strip_tags($_POST['salonname']); if ($_POST[submit]) { echo "TRUE - CONTINUE_1"; //echo $_SESSION[key].' - '.$_POST[user_code].'<br>'; if ($_SESSION[key]==$_POST[user_code]) { echo "TRUE - CONTINUE_2"; $_SESSION[key]=''; } if ($salonname); { echo "TRUE - CONTINUE_3"; $email = trim($_POST['email']); if(!checkEmail($email)) { echo 'Invalid email address!'; echo "FALSE - STOP_4"; } else { echo "TRUE - CONTINUE_4"; // RUN Database Query } }//End IF salonname = TRUE else //LINE 61 {// STOP CODE echo "FALSE - STOP_3"; }// End salonanme check else //LINE 67 {// STOP CODE echo "FALSE - STOP_2"; }// End user code }// End if Sumbit else {// STOP CODE echo "FALSE - STOP_1"; } ?> I just need another pair of eyes as I am not seeing the syntax error. I'm sure I'll figure it out right after I post this as that has happened many times before. query: <?php $sql = " INSERT INTO views (user_id,show,show_id,episode,episode_id) VALUES ( '" . $_SESSION['user']['id'] . "', '" . $showTitle . "', '" . $showID . "', '" . $episodeTitle . "', '" . $episodeID . "')"; ?> output: <?php $output = " INSERT INTO views (user_id,show,show_id,episode,episode_id) VALUES ('1','Criminal Minds','9','Episode Title','1')"; ?> error: Code: [Select] 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 'show,show_id,episode,episode_id) VALUES ( '1', 'Criminal Minds', '9',' at line 2 Hey all, Basically I have this code which technically should work, but I have put an error in the logic somewhere and am really struggling to find it, I've been going over it for about an hour now :/ The error is that in the second part (// Enter them into the activities database if they're not already there), it won't enter them, and it won't show the word 'Randomevent1' either, so clearly somehow I have put in something to prevent it performing that step. Can anybody help me out? I'd be amazingly grateful, I have no clue how I've screwed it up. if(isset($_POST['submit'])){ $ownerid = $_SESSION['id']; // If completed = Y give an error $completeyn = "SELECT completed FROM activities WHERE playerno='$ownerid' AND activityno = '1'"; $completecheck=mysql_query($completeyn) or die(mysql_error()); while($row = mysql_fetch_array( $completecheck )) { if($row['completed'] == 'Y'){ echo 'Oops, you\'ve already done this twice today!';} else { // Enter them into the activities database if they're not already there $stepno2 = "SELECT playerno, timesdone FROM activities WHERE playerno='$ownerid' AND activityno = '1'"; $stepnoanswer2=mysql_query($stepno2) or die(mysql_error()); $num_rows2 = mysql_num_rows($stepnoanswer2); echo $num_rows2; if($num_rows2 == '0'){ $putintodb2 = mysql_query("INSERT INTO activities (playerno, activityno, timesdone) VALUES ('$ownerid', '1', '1')") or die("Error: ".mysql_error()); echo 'Randomevent1'; }else{ // If they are already there update their stepcount $updatestepcount2=("UPDATE activities SET timesdone=timesdone+'1' WHERE playerno='$ownerid' AND activityno = '1'"); $newstepcount2=mysql_query($updatestepcount2); echo 'Randomevent2';} // If this new stepcount is equal to 2, set completed to Y $checkstep = "SELECT timesdone FROM activities WHERE playerno='$ownerid' AND activityno = '1'"; $checkstepresult=mysql_query($checkstep) or die(mysql_error()); while($row = mysql_fetch_array( $checkstepresult )) { if($row['timesdone'] == '2'){ echo $row['timesdone']; $updatestepcount22=("UPDATE activities SET completed = 'Y' WHERE playerno='$ownerid' AND activityno = '1'"); $newstepcount22=mysql_query($updatestepcount22); } }}}} I get the following error: Quote Parse error: syntax error, unexpected ';' in /hermes/web06/b1946/moo.rghollenbeck/index.php on line 35 But here is the only php code on the whole page: . . .more html code above <?php // PHP version: 5.2.12 // MySQL Version: 5.0.77 $link = mysql_connect('path', 'username', 'pword'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(guestlist); $Users_IP_address = $_SERVER["REMOTE_ADDR"] ; echo "<input type='hidden' name='ip' value="; echo $Users_IP_address; echo ">"; $first_name=mysql_query("SELECT 'fname' FROM tblMain; WHERE 'ip'=" . $Users_IP_address); // pseudocode section: // If $first_name !null{ // echo "Hello " . $first_name; // } // end pseudocode section: // something like that ?> more html code below. . . Thank you. |