Jump to content

jcoones

Members
  • Posts

    25
  • Joined

  • Last visited

Everything posted by jcoones

  1. Easy to see that I'm new at php. Thank you very much for your reply. I tried your code and and while it does get and display the data pretty much similar to the way my code did, I have two questions. This is the display output that I get with your code using only the first two records in the text file for testing purposes. Array ( [0] => Array ( [0] => Also known as the English Coonhound or the Redtick Coonhound, this breed traces back to the earliest English Foxhounds brought to the southern United States in the mid-seventeenth century and crossed with local types adapted to the harsher climate and terrain. Today, these are particularly agile, fast and enduring hounds. They have an excellent voice, which they put to good use. The breed is kown for its kind temperament and can fit into family life if given a lot of exercise, but they are happiest when hunting. [1] => American English Coonhound [2] => medium-large [3] => 22-25 in. [4] => 40-65 lbs. [5] => ) [1] => Array ( [0] => The American Bulldog is a powerful and athletic breed that benefits from mental as well as physical challenges. The breed is relatively quiet when at rest and in the home, but requires a fairly high amount of exercise and plenty of diversions. These are powerful dogs that can make excellent companions as long as they are properly socialized, supervised and exercised. They have a strong pack instinct and will protect their families and property with vigor. There are two types of American Bulldog, the Standard and the Bully. The Bully is larger, heavier, and has a shorter muzzle. [1] => American Bulldog [2] => large [3] => 21-27 in. [4] => 60-125 lbs. [5] => ) ) So my questions are: 1) How do I get rid of the blank array element at the bottom of each record? 2) Without using variables, how do I insert the records into the MySQLi database? Thanks again.
  2. I have a text file that consists of 200 lines that are delimited with the # sign. Each five lines in the text file make up one record for a mysqli database. That means, of course, that the 200 lines in the text file make up 40 records. I am trying to find a way to read 5 lines of text at a time, (1 record), assign them to variables and INSERT INTO the database, until all 40 records in the text file have been read and inserted. I can get it to display each record on the screen using this code: $handle = fopen("testfile.txt", "rb"); $delimiter = "#"; while (!feof($handle) ) { for ($x = 1; $x < 5; $x++) { $line = fgets($handle); $data = explode($delimiter, $line); foreach($data as $v) { echo nl2br($v) . "\n\n"; } } } fclose($handle); but I can’t figure out how to assign them to variables to insert into the MySQLi database. Any help would be greatly appreciated. Thanks in advance.
  3. Thanks Psycho. I guess its not hard to tell that I am new to php. I replaced a closing curly brace after the 'else' that was missing in your code and gave it a try but now I'm getting a error saying: Parse error: syntax error, unexpected '"' in /home.... : eval()'d code on line 28. I have gone over the code several times but I cannot find any erroneous "" .
  4. Thanks cyberRobot, but frankly, looking at those two lines that says change this echo “<center>”; to this: echo "<center>"; look identical to me.
  5. Hi, I'm having a problem creating an HTML table in php. I used php code that I believed was the proper format but I guess it is not. I'm trying to pull data from a MySQL database and put the contents into a 3 cell table. There should be one cell in the first row and 2 cells side-by-side in the second row. The data is being displayed ok but just not in a table. Maybe someone can steer me in the right direction to create an html table in php. Here is the code tat I used: <?php echo “<center>”; echo “<table width="600" cellpadding="6">”; echo “<tr>”; echo ”<td>”; $dog = $_POST['breed']; $servername = "localhost"; $username = "myusername"; $password = "**************"; $dbname = "mydatabase"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM doginfo WHERE breed='$dog'"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $detail = $size = $row["detail"]; $breed = $row["breed"]; $size = $row["size"]; $height = $row["height"]; $weight = $row["weight"]; $life = $row["life"]; $affect = $row["affection"]; $playfull = $row["playfull"]; $friendlyd = $row["friendly_dogs"]; $friendlyst = $row["friendly_stranger"]; $train = $row["training"]; $health = $row["health"]; } } else { echo "0 results"; } $conn->close(); echo nl2br("$detail" . "\n\n"); echo “/td>”; echo “</tr>”; echo “<tr>”; echo “<td>”; .nl2br("Breed : " . "$breed" . "\n") .nl2br("Size : " . "$size" . "\n") .nl2br("Height : " . "$height" . "\n") .nl2br("Weight : " . "$weight" . "\n") .nl2br("Life Expectancy : " . "$life" . "\n\n") ); echo “/td>”; echo “<tr>”; echo “<tr>”; echo “<td>”; echo ( nl2br("Based on a scale of 1 to 5\n\n") .nl2br(" Affection : " . "$affect" . "\n") .nl2br("Playfull : " . "$playfull" . "\n") .nl2br("Friendly with other dogs : " . "$friendlyd" . "\n") .nl2br("Friendly with strangers : " . "$friendlyst" . "\n") .nl2br("Ease of training : " . "$train" . "\n") ); if($health == "n/a") { echo " "; } else { echo nl2br("Health : " ."$health" . "\n\n"); } echo “</td>”; echo “</tr>”; echo “</table>”; echo ”</center>”; ?> By the way,... I am also having a problem bolding a line of text in the data displayed. Thanks in advance.
  6. Thanks for all the help. Very much appreciated. I finally got it working as it should. Here's the code I changed to: // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM doginfo WHERE breed='$dog'"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo nl2br("Breed: " . $row["breed"] . "\n" . "Size: " . $row["size"] . "\n" . "Height: " . $row["height"] . "\n" . "Weight: " . "\n" . $row["weight"] . "\n" . "Life Expectancy: " . $row["life"] . "\n"); } } else { echo "0 results"; } $conn->close(); Thanks again for the help.
  7. I added the error checking from the example 1 that you suggested and I am getting just one error that says: Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/…. : eval()'d code on line 15 Invalid query: Thanks
  8. Thanks for the response. I changed all references of mysql to mysqli and changed the parameters from $result = mysqli_query($conn, $query); to $result = mysqli_query($query, $conn); and now I am getting two errors. Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/…. : eval()'d code on line 15 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/…. : eval()'d code on line 16 There must be something else amiss in my code.
  9. Hi, I'm fairly new to php and MySQL and I am getting the following error when trying to pull data from a MySQL database. Warning: mysql_query() expects parameter 1 to be string, resource given I have tried a few things in an attempt to correct the issue but I am really only guessing. Here is my code: // Create connection $conn = mysql_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysql_connect_error()); } $query = "SELECT * FROM doginfo WHERE breed='$dog'"; $result = mysql_query($conn, $query); if (mysql_num_rows($result) > 0) { // output data of each row while($row = mysql_fetch_assoc($result)) { echo nl2br("Breed: " . $row["breed"] . "\n" . "Size: " . $row["size"] . "\n" . "Height: " . $row["height"] . "\n" . "Weight: " . "\n" . $row["weight"] . "\n" . "Life Expectancy: " . $row["life"] . "\n"); } } else { echo "No results found!"; } mysql_close($conn); echo "</font>"; Any help appreciated. Thanks
  10. Thank you very much. I appreciate your help.
  11. Thank you very much, however, can you give me an example? I'm not up on MySQL. This is an excerpt from the .sql file used to set up all of the tables. This is the section of the .sql file that sets up the customfields table. -------------------------------------------------------------------- CREATE TABLE `customfields` ( `cust_id` int(11) NOT NULL auto_increment, `cust_adtype_id` int(11) NOT NULL default '0', `cust_field_type` varchar(40) NOT NULL default '', <----- This is what I need to change! `cust_order` int(11) NOT NULL default '0', `cust_title` varchar(20) NOT NULL default '', `cust_include_search` tinyint(1) NOT NULL default '0', `cust_include_search_results` tinyint(1) NOT NULL default '0', PRIMARY KEY (`cust_id`) ) TYPE=InnoDB; --------------------------------------------------------------------- How would I use the ALTERTABLE in this instance? Your help is very much appreciated.
  12. I have a table called 'custom fields'. In this table I have cust_id, cust_adtype, cust_fieldtype, cust_title. cust_fieldtype is a TEXTAREA with a value of VARCHAR(40). I want to change it to VARCHAR(100). Can someone tell my how to do that in mu cpanel? Thanks.
  13. Thanks for the help prime. I can see where that would work as long as I know that the form is using the fields Username:, Email:, and Phone:, Those just happen to be the fields that I used in my test script, but what I am trying to do is to create a generic form processor that will handle any form, regardless of how many fields it may have. In this case, I would not know the names of the fields being used in any particular form so I wouldn't know what names to assign them to. I don't kknow if I am explaining this clearly but,... lets say a specific form has 8 fields. Each field has a name and a value but I don't know what they are. How could I assign them? To get rid of the "Submit" when printing or emailing the form data, I guess I could use something like this: foreach($_POST as $field => $value){ //Print everything except the "Submit" button press. if ($value != "Submit"){ print <<<HERE $field : $value <br> HERE; } } But that is a bit of a kludge and I thought there was a better, more efficient way to do it. Thanks again for your help, it really is appreciated.
  14. It does work in php5. The problem for me was that it also pulled the $_COOKIE, $_SESSION, and me being new to php, I didn't realize this when I used $_REQUEST. Using the superglobal $_POST I get the Username, Email, Phone and Submit without the other baggage. Now I just got to figure out how to print everything but the "Submit".
  15. Thank you. That worked fine! I still get the "Submit" but I'm sure I can find a way around that. Thanks,... much appreciated.
  16. I, who like everyone else at one time or another, am just beginning to learn php. I find, at least for me, that the easiest way to learn is to write little scripts and learn from that. Having said that, I wrote a small html "contact us" form and a processor script to retrieve the information from the form. That worked fine, however, that was because I knew exactly what fields were in the form. I wanted to figure out if I could create a generic script to handle any form. That, of course, means that I would not necessarily know how many fields any given form might have. I found that php created an associative array for the form fields. The following is the simple html form code that I used for testing. --------------------------------------------------------- <html> <title>Form Processor Test</title> <form method="post" action="readform.php"> Username : <input type="text" name="username" /><br /> Email : <input type="text" name="email" /></br> Phone : <input type="text" name="phone" /><br /><br> <input type="submit" name="button" value="Submit" /> </form> </html> --------------------------------------------------------- And the following is the php code I tried. --------------------------------------------------------- <?php foreach($_REQUEST as $field => $value){ print <<<HERE $field : $value HERE; } ?> --------------------------------------------------------- When I run the script, what I get is the following: --------------------------------------------------------- username : Tom Jones email : tjones@gmail,com phone : 123 456-7890 button : Submit skinadmin : pyrolight skin : pyrolight style : Small SESS701061c2a9cae4f927bc79247ecce216 : 122bfceb8974640f48d2b4000d64dc0e --------------------------------------------------------- I get the data from the fields but I don't know what the other five lines of garbage is. Is it reading a cookie? How would I code it to just get whatever fields are in the form and not the other garbage? Any help appreciated. Thanks
  17. [!--quoteo(post=379782:date=Jun 3 2006, 09:44 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 3 2006, 09:44 PM) [snapback]379782[/snapback][/div][div class=\'quotemain\'][!--quotec--] You'll find everything you need - and up-to-date as well - right on PayPal's site. Check the Merchant account area and find out/download what you need to use IPN. Or, use something like a free account at Payloadz - [a href=\"http://www.payloadz.com\" target=\"_blank\"]http://www.payloadz.com[/a] - and avoid all the hassle. [/quote] I have a paypal account and I have the Paypal buttons on my site. They work fine! If you click on the "Buy Now" button it goes to my account at Paypal. Once you are there you can make the payment but what I need is some code on my site that will email a link to the product download area to the customer, but [b]ONLY[/b] if the payment has been confirmed. Some people use "echecks" and that takes a few days to clear so they should not get the download link emailed until confirmation is received from Paypal that the echeck has cleared. The code I am looking for would wait for confirmation from Paypal and if it is received, a link to the product download is emailed to the customer. If they pay by "echeck" then the link is not emailed until confirmation that the echeck cleared has been received.
  18. I am trying to set up a couple of products on my site. I have set up Paypal "Buy Now" buttons which work fine. Does anyone know where I might find some code that will only allow the product to be downloaded after confirmation from Paypal that the payment has been made? I'll appreciate any help provide.
  19. Not really! What I wanted to do was to have one image that would be displayed on every page of my site if a user's browser was set to 800x600 and another image that would be displayed if a user's browser was set to 1028x768. What I ended up doing was creating a php include file that had a small Javascript in it and I included that file on each of my site pages. A bit of a kludge but it works fine. [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]
  20. Anyone know how to determine a browser's screen resolution with php or can it only be done with Javascript? I want to set up an include file with some code that would say something like: if(screen resolution is 800x600){ echo "<img src=Images/thisImage.gif>"; } else { echo "<img src=Images/anotherImage.gif>"; } Thanks Please ignore this post. I figured it out! Thanks anyway. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
  21. Thanks a bunch. I'll try that. I had to use the <br />. The "\r\n" didn't do it. Thanks again, very much.
  22. I tried the code and it works great! The only problem now is that for some reason the new line, " \n", is not being recognized. the $message is all coming out on one line as opposed to placing each input on a separate line, one below the other. Makes for better readability. Any idea as to what might cause this? Thanks
  23. Thank you very much. I'll give that a shot. Thanks again.
  24. [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]The Explanation[!--colorc--][/span][!--/colorc--]: I have looked at a few tutorials on mailing form input to a particular email address but they all use examples of a form with a set number of fields and use the "name=" to get the field data. For example a simple form such as: <form action="process.php" meathod="POST"> Enter your First name: <input type="text" name="first"> Enter your Last name: <input type="text" name="last"> <input type="submit" value="Submit"> </form> Then using php to get the form input they would use something like: <?php $firsname = $_POST[first]; $lastname = $_POST[last]; ?> [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]The Question:[!--colorc--][/span][!--/colorc--] It seems to me that the above method of getting the form input is fine if you know how many fields are in the form and what the "name=" values are. But how would you create a mailer that could be used for a number of different forms with a different number of fields in each form? If using different forms with the same mailer, how would you code it so that the mailer would be able to get all of the form input without knowing how many fields there are or what the "name=" values are? I'm not sure if I am being clear with the question but I think you should be able to get the idea. Would you use an array in the form and then in the mailer use $_POST['array[]'] and a foreach to get all of the input or how would it be done? I know that there are mailers out there that can be used with almost ANY form and mail the input out but I don't know how it does it? Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.