PHP - Help! Can't Get The Data Links To Display But, No Errors Being Returned
Hello all,
I'm writing a page with a simple database with a table called recipes in it with a series of recipes (go figure). I want to display a list of the recipe titles in ascending alphabetical order with each title linked to another page that displays all of the information about the recipe. I can't seem to get anything to display though (not even the titles) but I'm not getting any errors returned either. It seems as if there is nothing in the table to display (even though there are 40 records there). Any help would be greatly appreciated. Here is the code I have so far: Code: [Select] <?php $dbhost = 'localhost'; $dbuser = '*****'; $dbpass = '*****'; $dbname = '*******'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database'); mysql_select_db($dbname) or die('Error selecting the database'); // select data from db to use $result = mysql_query("SELECT * FROM recipes ORDER BY title ASC LIMIT 0,50") or die('mysql_error()'.'Error: ' .mysql_errno() ); //display the data while($row = mysql_fetch_array($result)); { echo"<b><center>Healthy Lifestyle Gourmet Recipes</center></b><br /><br />"; echo "<span class=\"recipelink\"><a href=\"reciperesults.php?id=".$row['id']."\" target=\"_blank\">".$row['title']."</a></span><br/>\n"; } mysql_close(); ?> I starred out the connection variables but, they are all correct in my code (I'm not getting the "or die" errors) Similar TutorialsI'm pulling data from an xml file and I'm getting a lot of duplicates. How can I remove the duplicates from the query? Code: [Select] foreach($xml->category->subcategory as $category){ echo $category[id]; }//end foreach I am looking to accomplish the following but have been hitting a brick wall: * User enters a single keyword into a text field, and conducts a search keyword search. * The results are pulled from the campusbooks.com API(API docs attached) * result are then output in <div> class and includes all the book details and its corresponding url./img etc I'm trying to simplify this process but I continue to receive syntax errors. A step by step practical explanation would do me justice! Hello,
This is confusing me! - this code is finding 2 rows of data ($nrows is 2), but I'm only getting 1 row of data returned. On the second while loop I'm getting the following error message:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/website.com/test.php on line 26
$query ="SELECT * FROM Accounts WHERE (jaaLatitude = '' OR jaaLongitude = '')"; $result=mysql_query($query) or die ("Connection to database table failed." . mysql_error()); $nrows=mysql_num_rows($result); $i = 0; if ($nrows > 0) { while($record = mysql_fetch_array($result, MYSQL_BOTH)) { $jaaIndex = $record[jaaIndex]; $jaaEmail = $record[jaaEmail]; $jaaLocation = $record[jaaLocation]; $jaaLongitude = $record[jaaLongitude]; $jaaLatitude = $record[jaaLatitude]; echo "<br>test jaaEmail is $jaaEmail<br>"; $i = $i + 1; } }As I say the first while loop is working, so I don't see what can be wrong with the qurery (it's not failing). Thanks for your help, S I'm sure this is a simple question, and I'm not a total newbie, but I keep drawing a blank. In accordance with existing specifications, a client has created a PHP page on their web server which responds to a query by returning a small block of XML. I need to use that XML, and I have no problem doing that using XMLReader->open(clientURL). I can call the client's PHP page and get XML back that I can parse and everything is wonderful. Except for one thing: I need to send a product ID when I call the client's PHP page, and I need to send it using the POST method. I guess that means my clean and neat one-step process is going to have to become a two-step process, and I'm going to have to use some other means besides XMLReader->open() to retrieve the XML. Can sombody recommend the best way to do this? I need to send POST data first to get the correct XML response, and then I need to capture the XML in a way that allows me to parse it. Hello, I have been developing a website that needs to display products online, I was originally going to hand-write the PHP code but I thought it would be more beneficial to make it database orientated as new products can easily be added and a search function becomes possible. I have it working so far so good, but the last part I can't seem to get working. I have it so all the products that have the desired category are displayed, but I want a more detailed analysis of the product to appear when the image is clicked, which at the moment, displays a blank page. http://www.webwib.co...?p=floorpuzzles - this is the hand coded version that demonstrates how I want it to work. http://www.webwib.co...hp?floorpuzzles - this is the db version so far, it works how it is intended to apart from the last stage, which returns as a blank page rather than a dedicated page for the selected product. Here is my code, the third segment beginning with "if(isset($_GET['$ID'])){", is my attempt at the final stage. <?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); if(isset($_GET['floorpuzzles'])){ echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID#productspage\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['anothercategory'])){ $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . AnotherCategory . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<h1>Our Floor Puzzles</h1>"; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID0#productspage\"><img src=\"images/products/catalogue//$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['$ID'])){ $sql="SELECT ID, Name, Tags, Description, Peices, Size, Barcode, Category FROM products WHERE ID LIKE '%" . $ID . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode $Barcode</p>"; echo "</div>"; } } include("footer.php"); ?>Thank you in advance for any assistance given. I have a fairly complicated Q&A Form with 10 Inputs. If there is a data entry error, then I re-load the Form display an error-message beneath the corresponding field. No problems there. Normally, if there was a more serious error (e.g. INSERT failed), then I would re-direct to a new page and display the error (or success) message there. No problem again. But here is where I am confused... Because my code iterates through each of the 10 Inputs on my Q&A Form, there could conceivably be an error on each loop. If I had two serious errors (e.g. INSERT error and UPDATE error), then how should I handle displaying the error?! For those types of errors, I would usually re-direct, however there would usually be only one error to display, e.g. Quote Your profile answers could not be added due to a System Error. Should I display every error that might occur for every one of the 10 Input fields, or does it make sense to just display one error, with the understanding that if one thing fails then everything does. Hope that makes sense?! Thanks, Debbie Ok I'm setting the error. I debugged my code and it's catching the phrase in the set_error() function. But it's returning NULL when I try to display it from the display_error() function. These functions are in the form class. I create a new instance of it on the register.php and I'm trying to grab the values. Here is my Form class (only showing the part you need to see): Code: [Select] class Form { private $error; public function set_error($errmsg){ $this->error = $errmsg; return; } public function display_error() { $error = "<p style='color:red;'>".$this->error."</p>"; return $error; } } Then here is my register process: Code: [Select] if(isset($_POST['submit'])) { if(isset($_POST['name']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['password2']) && isset($_POST['email']) && isset($_POST['email2']) && isset($_POST['dob']) && isset($_POST['gender']) && isset($_POST['security'])) { if ($user->register_user($_POST['name'], $_POST['username'], $_POST['password'], $_POST['password2'], $_POST['email'], $_POST['email2'], $_POST['dob'], $_POST['gender'], $_POST['security'])) { $message = "User has been registered successfully."; } else { $message = $form->display_error(); } } else { $message = "Please fill out all parts of the form!"; } } It display the $message just fine when I call isset($message), but it won't display it when I assign it the form->display_error() value because it returns NULL. Thank you! I have a Q&A Form that consists of 10 Questions with input boxes for 10 Answers. (Each Answer is stored in its own record in the "answer" table.) When the Form is submitted, I loop through an answerArray and decide what to do with each Form Field. For example, if there is a new Answer, then I create a new record by doing an INSERT, but if the Answer is a change, then I do an UPDATE on an existing record. Following my previous coding style, I assign a Results Code for *every* possible thing that can happen in *every* code branch, e.g. Code: [Select] $_SESSION['resultsCode'] = 'ANSWERS_NO_CHANGES_2138'; $_SESSION['resultsCode'] = 'ANSWERS_UPDATE_SUCCEEDED_2139'; $_SESSION['resultsCode'] = 'ANSWERS_UPDATE_FAILED_2140'; $_SESSION['resultsCode'] = 'ANSWERS_INSERT_SUCCEEDED_2141'; $_SESSION['resultsCode'] = 'ANSWERS_INSERT_FAILED_2142'; The problem is that - as my code currently stands - I only end up displaying a resultsCode for the LAST QUESTION, because the first 9 are overwritten?! Should I keep my current structure, and quit on an Errors, and display a page with that error (e.g. Update Failed), and then just comment out the Succeed messages? Or do I get fancy and store each Success or Error in an array and display the outcome for all 10 Questions after the Form is processed? In the past all of this was easy, because ONE FORM equated to ONE RECORD, so Error Messages were easier to display. But here, I have ONE FORM and up to 10 RECORDS?! Hope this is making sense? Thanks, Debbie Hi, i'm a PHP newbie and am working on a contact form which is below. I've just included one field (email) to make things shorter. In practice this works okay but when the page is first displayed it shows the "No Email was entered" error. I know that I need to include something like "if (isset($_POST['submit'])) is true then process the error checking otherwise display the form however I can't seem to find where to put it and spent all weekend on this now, little help? Once i've got this sorted i'll add the other fields and javascript error checking as well. Many thanks Ryan <?php // shortform.php $email = ""; $to = 'myemail@address.co.uk'; $subject = 'Contact form email'; $message = 'please work!'; if (isset($_POST['email'])) $email = fix_string($_POST['email']); $fail = validate_email($email); echo "<html><head><title>Shortform</title>"; if ($fail =="") { echo "</head><body>$email successfully validated: .</body></html>"; mail($to, $subject, $message, "From: $email"); exit; } echo <<<_END <table class="contactform" border="0" cellpadding="2" cellspacing="5" bgcolor="#eeeeee"> <th colspan="2" align="center">contactform</th> <tr><td colspan="2">Sorry, the following errors were found<br /> in your form: <p><font color=red size=1><i>$fail</i></font></p> </td></tr> <form method="post" action="shortform.php" onSubmit="return validate(this)"> <tr><td>Email</td><td><input type="text" maxlength="64" name="email" value="$email" /></td> </tr><tr><td colspan="2" align="center"> <input type="submit" value="Submit" /></td> </tr></form></table> _END; function validate_email($field) { if ($field == "") return "No Email was entered<br />"; else if (!((strpos($field, ".") > 0) && (strpos($field, "@") > 0)) || preg_match("/[^a-zA-Z0-9.@_-]/", $field)) return "The Email address is invalid<br />"; return ""; } function fix_string($string) { if (get_magic_quotes_gpc()) $string = stripslashes($string); return htmlentities ($string); } ?> So I have been working on my website for a while which all is php&mysql based, now working on the social networking part building in similar functions like Facebook has. I encountered a difficulty with getting information back from a link. I've checked several sources how it is possible, with title 'Facebook Like URL data Extract Using jQuery PHP and Ajax' was the most popular answer, I get the scripts but all of these scripts work with html links only. My site all with php extensions and copy&paste my site links into these demos do not return anything . I checked the code and all of them using file_get_contents(), parsing through the html file so if i pass 'filename.php' it returns nothing supposing that php has not processed yet and the function gets the content of the php script with no data of course. So my question is that how it is possible to extract data from a link with php extension (on Facebook it works) or how to get php file executed for file_get_contents() to get back the html?
here is the link with code&demo iamusing: http://www.sanwebe.c...-php-and-jquery
thanks in advance.
SET UP: Windows vista # XAMPP 1.7.3, # Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l # MySQL 5.1.41 + PBXT engine # PHP 5.3.1 # phpMyAdmin Error message: 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 ') VALUES ('qwerty','uiop','asd')' at line 2 I'm trying to get this multi page order form to insert information into two tables via a session. But it comes up with the above error message. This script worked perfectly with one table but as soon as I coded he information to go into two tables it screwed up. Is it the sprint <?php //let's start our session, so we have access to stored data session_start(); session_register('membership_type'); session_register('terms_and_conditions'); include 'db.inc.php'; $db = mysql_connect('localhost', 'root', '') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('ourgallery', $db) or die(mysql_error($db)); //let's create the query $query = sprintf("INSERT INTO subscriptions ( name, email_address, membership_type,) VALUES ('%s','%s','%s')", mysql_real_escape_string($_SESSION['name']), mysql_real_escape_string($_SESSION['email_address']), mysql_real_escape_string($_SESSION['membership_type'])); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); $query = sprintf("INSERT INTO site_user_info ( terms_and_conditions, name_on_card, credit_card_number, credit_card_expiration_data) VALUES ('%s','%s','%s','%s')", mysql_real_escape_string($_SESSION['terms_and_conditions']), mysql_real_escape_string($_POST['name_on_card']), mysql_real_escape_string($_POST['credit_card_number']), mysql_real_escape_string($_POST['credit_card_expiration_data'])); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); echo '$result'; ?> I'm trying to insert into this database: <?php require 'db.inc.php'; $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect. Check your connection parameters.'); mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); $query = 'CREATE TABLE IF NOT EXISTS subscriptions ( name VARCHAR(50) NOT NULL, email_address VARCHAR(50), membership_type VARCHAR(50), PRIMARY KEY (name) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); // create the user information table $query = 'CREATE TABLE IF NOT EXISTS site_user_info ( name VARCHAR(50) NOT NULL, terms_and_conditions VARCHAR(50) NOT NULL, name_on_card VARCHAR(50), credit_card_number VARCHAR(50), credit_card_expiration_data VARCHAR(50), FOREIGN KEY (name) REFERENCES subscriptions(name) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); echo 'Success!'; ?> What am I doing wrong? is there a code spell checker ? Also should I use the mysql_real_escape_string() on the user input as they become sessions variables or is it okay to wait and clean the input as it gets inserted in the table? Thanks for your help. I've got a basic form setup on my site that requires the user to fill out the required fields. When one of the fields isn't filled out, the error message for that specific input area is displayed, etc. However, all the information from the form that the user filled out is removed.. I want the user to be able to fill out the form, hit submit, and if any errors, show the specific error but also keep the input boxes populated with the data the user filled out so he/she does not have to re type everything. if(!empty($_POST['submitFeature'])) { // set variables $featurename = mysql_real_escape_string($_POST['featurename']); $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $email2 = mysql_real_escape_string($_POST['email2']); $age = mysql_real_escape_string($_POST['age']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $src = $_FILES['featureupload']['tmp_name']; $featuresize = $_FILES['featureupload']['size']; $limitsize = 3000000; if(!empty($featurename) && !empty($name) && !empty($email) && !empty($email2) && !empty($city) && !empty($state) && ($email == $email2) && !empty($_FILES['featureupload']['tmp_name']) && ($featuresize < $limitsize)) { // IF ALL IS CORRECT, SUBMIT INFO } else { print ' <ul class="errorlist"> <li class="alert">Please fill out the required fields.</li> '; if (empty($name)) { echo ' <li>* Full Name</li>' . "\n"; $errorname = 'TRUE'; } if (empty($email)) { echo ' <li>* Email</li>' . "\n"; $erroremail = 'TRUE'; } print ' </ul> '; } // 1 - B. END REQUIRED FIELDS ERROR CODES } ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <div style="float: left;"> <span class="copy-answer">Your Information</span> <div class="formSec"><label for="name" class="required">Full Name: <?php if(isset($errorname)){echo '<span class="error">*<span>';}?></label> <input type="text" name="name" id="name" value="" maxlength="25" /></div> <div class="formSec"><label for="email" class="required">Email: <?php if(isset($erroremail)){echo '<span class="error">*<span>';}?></label> <input type="text" name="email" id="email" value="" /></div> <input class="submit" type="submit" name="submitFeature" value="Submit Your Feature" /> </form> Hello, I'm want to manually configure what URL's can display a frame, in which I'm using this: $frame = 1; I basically need a code in which I can define what links display the frame, otherwise, the below code shows: $frame = 0; All my links follow the following format: http://site.com/link http://site.com/link2 Thanks! PS: I've provided an example of code to help you understand, however, i'm unsure how to allow multiple prefix's and include 'else': $link ='index.php?link'; if (isset($_GET['link'])) $frame = 1; } else { $frame = 0; No echo required, it's a config.php file. Hello, I've been trying this for hours now, looking at different examples and trying to change them to work for me, but with no luck... This is what I am trying to do: I have a simple form with: - 1 input field, where I can enter a number - 1 Submit Button When I enter a number into the field and click submit, I want that number to be send to the php file that is in the ajax call, then the script will take that number and run a bunch of queries and then return a new number. I want that new number to be used to call the php script via ajax again, until no number is returned, or something else is returned like the word "done" or something like that, at which point is simply makes an alert or populated a div with a message... The point is, that depending on the number entered it could take up to an hour to complete ALL the queries, so I want the script that is called to only run a fixed amount of queries at a time and then return the number it is currently at (+1), so that it can continue with the next number when it is called again. I would like to use jquery, but could also be any other way, as long as I get this to work. I already have the php script completed that needs to be called by the ajax, it returns a single number when being called. Thank you, vb I am trying to display certain MySQL data based off of what link is clicked. For example.. I want to display all the entries from 2009 when a link for 2009 is clicked; maybe like.. <a href="http://website.com/page?yr=09">2009</a> But I am having trouble doing so.. any help would be great! P.S. The years are in my database with only the last two numbers.. 10, 09, 08, etc. $result = mysql_query("select setlist_id, month, day, year, name, venue, location, label1, set1, set2, set3, encore, notes, photos, recording, poster from $database_table order by setlist_id DESC, year, month, day",$db) or die_now("Could not select setlists"); while($row = mysql_fetch_array($result)) { $the_id = $row["setlist_id"]; $the_month = $row["month"]; $the_day = $row["day"]; $the_year = $row["year"]; $the_name = $row["name"]; $the_venue = $row["venue"]; $the_location = $row["location"]; $the_label1 = $row["label1"]; $the_set1 = $row["set1"]; $the_set2 = $row["set2"]; $the_set3 = $row["set3"]; $the_encore = $row["encore"]; $the_notes = $row["notes"]; $the_photos = $row["photos"]; $the_recording = $row["recording"]; $the_poster = $row["poster"]; echo("<div class='date' id='date' tabindex='0'>" . "$the_month" . "." . "$the_day" . "." . "$the_year" . " - "); echo ($the_name != '') ? "" . "$the_name" . " - " : ''; echo("" . "$the_venue" . " - " . "$the_location" . "</div>"); echo("<div class='set'>" . "$the_label1" . ":<br /></div><div class='list'>" . "$the_set1" . "<br /></div>"); echo ($the_set2 != '') ? "<div class='set'>Set Two:<br /></div><div class='list'>" . "$the_set2" . "<br /></div>" : ''; echo ($the_set3 != '') ? "<div class='set'>Set Three:<br /></div><div class='list'>" . "$the_set3" . "<br /></div>" : ''; echo ($the_encore != '') ? "<div class='set'>Enco <br /></div><div class='list'>" . "$the_encore" . "<br /></sdiv>" : ''; echo("<div class='line'></div>"); echo nl2br("<div class='notes'>" . "$the_notes" . "</div>"); } When I replace the $result line with... $result = mysql_query("SELECT * FROM `$database_table` WHERE `year` = '09' order by setlist_id DESC, year, month, day",$db) or die_now("Could not select shows");... I get all the results from just 2009, which is what I want, but I want the results to depend on what link has been clicked. I hope I am making sense. Hi guys, I am using a search form that's supposed to pull data out of database and display them. I managed to to do that using the following: while($rows = mysql_fetch_assoc($result)) { echo "-Title: " . $rows['title'] . "<br/>" . "-Author: " . $rows['author'] . "<br />"; Displays something like this: -Title: Young One -Author: Edwards Bonnie. ---------------------------------- I have links related to each book in a folder and I want to make the title clickable and each title should take me to the corresponding book page. I know that I have to do something like <a href=\"...........\">$rows['title']</a>", but as far as I know all titles will take me to one page using that! please help and thank you. Hello, Im getting some data from a database. Im showing them in a php page. well its like this... Its a song and lyric site. Im displaying the whole song titles and lyrics when a user search. there's separate page to list all the songs available. Which displays all the TITLES of the songs. How can I make those Titles LINKS to view the lyrics when clicked?? A tutorial regarding a thing like this would be much helpful.. Thanks... Hi all. The following is a function to get and display data. However, I've hit a wall in my progress. It's only printing out one field. I need to have it print out every retrieved field. Any help is appreciated. function get_data($table_name){ $result=mysql_query("SELECT * FROM $table_name"); $num=mysql_num_rows($result); $i=0; while($i < $num){ $fields=mysql_fetch_field($result,$i); $display_fields=mysql_result($result,$i,$fields->name); echo $display_fields; $i++; }; }; I realized that (I think) I need the $display_fields var to be concatenated with the $i variable so there's a unique var name for each field retrieved from the mysql_fetch_field line. Any ideas? Hello. What I have created is a menu with links. The links will display content on the page from a database. I have the links with id displayed, but nothing is displayed when the link is clicks. I have seen isset() and $_GET used but not a form and I don't know how to change the code to allow the display of data using ID. My site is local, and I am using XAMPP. The database connections work. This is my code: // query $query = "SELECT * FROM topmenu ORDER BY id ASC"; $row = $PDO->query($query); .... <table class="topmenu"> <tr> <td> <h1 class="siteName">site title</h1> </td> <?php foreach($row as $data) { ?> <td><a href="index.php?id=<?php echo $data['id']; ?>"> <?php echo $data['menuheader']; ?> </a></td> <?php } ?> </tr> </table> As a beginner, I would appreciate any help, no criticism of my code please! Also, is there a way of hiding the id in the url? Thanks in advance. |