Jump to content

ZandarGlass

Members
  • Posts

    12
  • Joined

  • Last visited

ZandarGlass's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the response Barand. I took them out, I still get nothing. New code below. <?php require_once('/includes/conn.inc.php'); $conn = dbConnect('read'); $stmt = $conn->stmt_init(); // Create a prepared statement if($stmt->prepare("SELECT name FROM comments WHERE approved = ?")) { // Bind your variable to replace the ? $stmt->bind_param('s', $approved); // Set your variable $approved = "Y"; // Execute query $stmt->execute(); // Bind your result columns to variables $stmt->bind_result($name); // Fetch the result of the query while($stmt->fetch()) { echo $name . ' - ' . "found"; // John Doe - Unknown... } // Close statement object $stmt->close(); } ?>
  2. I'm learning how to use PHP and prepared statements with mysqli/php and can't seem to get this code to output data. I get no error messages, just nothing output. This is the complete code, it's rather simple, created from an example I found online. <!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> <title>Untitled</title> </head> <body> <?php require_once('/includes/conn.inc.php'); $conn = dbConnect('read'); $stmt = $conn->stmt_init(); // Create a prepared statement if($stmt->prepare("SELECT 'name' FROM comments WHERE 'approved' = ?")) { // Bind your variable to replace the ? $stmt->bind_param('s', $approved); // Set your variable $approved = "Y"; // Execute query $stmt->execute(); // Bind your result columns to variables $stmt->bind_result($name); // Fetch the result of the query while($stmt->fetch()) { echo $name . ' - ' . "found"; // John Doe - Unknown... } // Close statement object $stmt->close(); } ?> </body> </html>
  3. My apologies if I've placed this in the wrong section. It concerns a basic connection to n SQL database, and doing a simple count of the records. I'm learning from DAVID POWERS PHPSOLOUTIONS book. Examples in his book show connecting to the local db differently than my host wants me to connect, and I believe therin lies the issue. If I can figure out the method or problem I'm having, I'll be very thankful. I'm just connecting to a database, running one query, and counting records. The code that I altered, and I am trying to use, looks like this: <?php //Sample Database Connection Syntax for PHP and MySQL. include ('/includes/imageconn.inc.php'); include ('/includes/imagetableconn.inc.php'); mysql_select_db($dbname); # Check If Record Exists $sql = "SELECT * FROM $usertable"; $result = $conn->query($sql) or die(mysqli_error()); $numrows = $result->num_rows; ?> <html> <head> <title>PHP Test</title> </head> <body> <?php echo $numrows; ?> </body> </html> ----------------------------------------------------------------------- My imageconn.inc.php file holds a set of variables needed for the connection. I have verified it works (online, where I want), using other simple pages I made. This is the imagetableconn.inc.php file. It contains one line of code (which also works in the test file the host sent me). $conn = mysql_connect($hostname, $username, $password) or die ('Error connecting to mysql'); ------------------------------------------------------------------------- I'm pretty sure the problem lies in this line (which is from the BOOK, which I can't figure out how to modify for my online needs): $result = $conn->query($sql) or die(mysqli_error()); My error message: Fatal error: Call to a member function query() on a non-object in D:\Hosting\4641474\html\testimagedb1.php on line 12
  4. Thanks! I found the issue. When I made the last backup from my remote server I inadvertently included the .htaccess file. I removed that from my local folder and now it works fine. Now, on to the next problem ... for tomorrow!! Thanks a ton! I reviewed the error.log and it mentioned the .htacess file, which didn't make any sense to me to be in my local copy I've been using for learning. I opened the .htaccess file and took a look and recalled the garbage I'd stuck in there, removed it, and everything is ok. Thanks!
  5. Through more testing I have found that if I place a file (helloworld.php, etc.) in the root it works. But any folder under the root fails. This works: http://localhost/hello.php This does not work: http://localhost/webd/hello.php Sorry for being so confusing.
  6. My apologies if this is in the wrong section - I didn't see anything dedicated to xampp, or my noob question anyway. I've installed XAMPP in c:/xampp, and wrote a very simple php file that just displays a line of text. I can't seem to get this file to display in /localhost/ environment. When I run it on my remote host, it runs fine, but I want to use my localhost location, of course. These are the folder structures: C:/xammp/htdocs/webd/error.php I'm loading the file in IE10 using: http://localhost/webd/error.php I get the following: Server error! The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script. If you think this is a server error, please contact the webmaster. Error 500 localhost Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.19 I verified my Apache module is turned on and running in the XAMPP control panel (v3.2.1). I can't get any php page to run on my localhost so whatever I'm doing it's global, I figure I installed xammp incorrectly or I'm not loading the file right. I tried using variations like http://localhost/htdocs/webd/error.php, and even tried changing the filename to an html extension and tested it by opening it using C:/xampp/htdocs/webd/error.html and the file displays, so it's there, and I don't have some weird folder issue (as far as I can tell). I'm pretty sure this is a basic issue, something that I'm doing or did that was dumb or I'm just being dense for some reason. Any help out there?
  7. Ch0cu3r DUDE you nailed it. I kept wondering why other code was working and this one failed - all I could think of was some core function was missing. I kept looking at it and didn't notice the ".." until you called it out!!! Thanks a ton. (yes that is the book) BARAN Thanks to you too! Every time I look for answers for one question I learn more - so none of that went to waste! It all sent me looking and learning other methods. I really appreciate getting such expert advice from both of you guys! I'm sure I'll be back asking more questions as the examples get more complex - but you dam sure bet I'll be looking for an errant path a little closer. So far I've been able to troubleshoot my own errors but THIS one - I just could NOT get over the hump. Thanks again guys!!!! You have been so much help!
  8. If I'm understanding correctly, then something like this: <?php // set the maximum upload size in bytes $max = 51200; if (isset($_POST['upload'])) { // define the path to the upload folder $destination = '/Hosting/myacount/html/mydir/tst/'; require_once('../classes/Ps2/Upload.php'); require_once('.;C:\php5\pear'); try { $upload = new Ps2_Upload($destination); $upload->move(); $result = $upload->getMessages(); } catch (Exception $e) { echo $e->getMessage(); } } ?> I'm not sure I understand the syntax. Sorry for the difficulty, I really do appreciate the help! I've also been reading about include_path, and wonder if this is what you are referring to, as in this example I found at php.net <?php $path = '/usr/lib/pear'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); ?> where '/usr/lib/pear' would be changed to the location of the folder on my server. In that case, maybe something like: <?php $path = '/php5/pear''; set_include_path(get_include_path() . PATH_SEPARATOR . $path); // set the maximum upload size in bytes $max = 51200; if (isset($_POST['upload'])) { // define the path to the upload folder $destination = '/Hosting/myacount/html/mydir/tst/'; require_once('../classes/Ps2/Upload.php'); try { $upload = new Ps2_Upload($destination); $upload->move(); $result = $upload->getMessages(); } catch (Exception $e) { echo $e->getMessage(); } } ?> I'm not sure if I have access to php.ini on my host server (windows host). Thanks again for any help you can provide.
  9. Thanks for the response. So if I understand correctly, I have to have upload.php in the same folder as the file that is calling it (which is called upload_file.php)? Isn't there a way to right some kind of include path statement in upload_file.php that tells it that upload.php is in one folder, and the "core php" file is in C:/php5/pear? Or do you mean those all have to be in the same folder? I'm not sure if I have access to place both upload_file.php and upload.php in the c:/php5/pear folder (or any of my files). Sorry to sound dense.
  10. After some thought I figured I'd answer the inevitable question, heres the code behind the file I'm using. I can include the file in the Ps2 directory (Upload.php) if this also helps. I changed some details in the path so my account and the folder aren't appearing. <?php // set the maximum upload size in bytes $max = 51200; if (isset($_POST['upload'])) { // define the path to the upload folder $destination = '/Hosting/myacount/html/mydir/tst/'; require_once('../classes/Ps2/Upload.php'); try { $upload = new Ps2_Upload($destination); $upload->move(); $result = $upload->getMessages(); } catch (Exception $e) { echo $e->getMessage(); } } ?> <!DOCTYPE HTML> <html> <head> <meta charset=utf-8"> <title>Upload File</title> </head> <body> <?php if (isset($result)) { echo '<ul>'; foreach ($result as $message) { echo "<li>$message</li>"; } echo '</ul>'; } ?> <form action="" method="post" enctype="multipart/form-data" id="uploadImage"> <p> <label for="image">Upload image:</label> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>"> <input type="file" name="image" id="image"> </p> <p> <input type="submit" name="upload" id="upload" value="Upload"> </p> </form> </body> </html>
  11. Hi all. I'm teaching myself PHP and of course I have a stumbling block. I wrote a simple upload file, and it worked fine (so permissions don't seem to be my issue), then I added some other code to it to create a PHP class (using PHP SOLUTIONS by DAVID POWERS). But the code fails now. I'm pretty sure it can't find a path to necessary php core functions. The error message I get is: Fatal error: require_once() [function.require]: Failed opening required '../classes/Ps2/Upload.php' (include_path='.;C:\php5\pear') in D:\Hosting\myaccount\html\mydirectory\Upload_file.php on line 7 And indeed, when I use a phpinfo code to glean information, it tells me the include path I must is: .;C:\php5\pear It all makes perfect sense. However, I can't seem to write an include statement that addresses the issue. I want to put it in the same document (my upload_file.php), but if that isn't necessary I want to put it anywhere else that would work. Any help? Either this is very simple or I have an issue of some kind at the server? I can post the entire code if you like. Whatever helps.
×
×
  • 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.