Jump to content


New Members
  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About sdgsdghshhg

  • Rank
  1. Oh, as for point 1 - yes, that was a typo and the file should have been *.php. It is located outside the http document root, so can't be served by the webserver. Thanks again.
  2. Massive snip. Beautiful - thank you for this massive amount of useful stuff. Can you recommend a better book/course that would do what I need, i.e. basically show me the ropes of PHP/MySQL integration, and let me move on to building my own sites? Thanks again.
  3. Hi. I'm playing around with MySQL and PHP, using the O'Reilly book. I know that some of the stuff in here is out of date, most notably the mysql_connect and other stuff. But I had this book lying around and decided to go with that, and then update my knowledge once I have the basics. So I'm building a 'pets' database. The MySQL side is good, I can do that relatively easily and relatively fault-free. I can do the PHP script to run a SELECT and display all pets. Then I move onto the script on pages 233-234 of the O'Reilly book, and I run into a problem. The script is below. When I access this, I get: [Wed Nov 15 10:18:58 2017] [error] [client] PHP Parse error: syntax error, unexpected $end in /var/www/html/pets/insert_data.php on line 96 I have run a `grep` and a `wc` on the script, and all of my braces and parentheses are matched. Interestingly, using vim as my editor, is it just after the second 'echo <<<_END' that colour coding fails, so I guess the error is there? But I can't see it. Can someone help? Thank you. <?php // insert_data.php include('../../db2_credentials/pets.sql') ; $connection=mysql_connect($db_host,$db_username,$db_password) ; // cannot connect ? Exit if (!$connection) { die ("Could not connect to the database: <br />" . mysql_error()) ; } $db_select = mysql_select_db($db_database) ; if (!$db_select) { die ("Could not select the schema. Please check databse details!<br />" . mysql_error() ); } if (isset($_POST['animal_name']) && isset($_POST['animal_dob']) && isset($_POST['animal_species']) && isset($_POST['animal_colour']) && isset($_POST['animal_sex'])) { $animal_name = get_post('animal_name') ; $animal_dob = get_post('animal_dob') ; $animal_species = get_post('animal_species') ; $animal_colour = get_post('animal_colour') ; $animal_sex = get_post('animal_sex') ; if (isset($_POST['delete']) && $animal_name != "") { $query = "DELETE FROM animals WHERE animal_name = '$animal_name'" ; if (!mysql_query($query, $db_server)) echo "DELETE failed: $query<br />" . mysql_error() . "<br /><br />"; } else { $query="INSERT INTO animals VALUES" . "($animal_name,$animal_dob,$animal_species,$animal_colour,$animal_sex)" ; if (!mysql_query($query, $db_server)) echo "DELETE failed: $query<br />" . mysql_error() . "<br /><br />"; } } echo <<<_END <form action="insert_data.php" method="post"><pre> Name <input type="text" name="animal_name" /> Date of Birth <input type="text" name="animal_dob" /> Species <input type="text" name="animal_species" /> Colour <input type="text" name="animal_colour" /> Sex <input type="text" name="animal_sex" /> <input type="submit" value="ADD RECORD" /> </pre></form> _END; $query = "SELECT * FROM animals" ; $result = mysql_query($query) ; if (!$result) die ("Database access failed: " . mysql_error()); $rows=mysql_num_rows($result) ; for ($count = 0 ; $count < $rows ; ++$count ) { $row=mysql_fetch_row($result) ; echo <<<_END <pre> Animal ID $row[0] Name $row[1] Date of Brth $row[2] Species $row[3] Colour $row[4] Sex $row[5] </pre> <form action="insert_data.php" method="post"> <input type="hidden" name="delete" value="yes" /> <input type="submit" value="DELETE RECORD" /></form> _END;
  • 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.