Jump to content

jcoones

Members
  • Posts

    25
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

jcoones's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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".
×
×
  • 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.