Jump to content

AdmiralQ

Members
  • Posts

    17
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

AdmiralQ's Achievements

Member

Member (2/5)

0

Reputation

  1. AdmiralQ

    num_rows

    What do you mean “would I accept that from my students?” Who do you think you are talking to me like that? You aren’t my teacher! If you can’t answer without demeaning then don’t answer.
  2. AdmiralQ

    num_rows

    I’m aware I’m using the old mysql. That’s my point. I’m trying to update it. I’ve got a site with 1000+ files and most files have several hundred lines of code. I’ve looked through the documentation for help with syntax and format with this, but I do not understand the way they write it. I always have to google other people’s code to get a complete idea of syntax and format, but this one still eludes me. I just need a simple hand here for updating this one line of code.
  3. AdmiralQ

    num_rows

    I am updating from PHP 5 and MySQL 5 and have gotten the hang of basic queries for INSERT, UPDATE, SELECT, and DELETE. But I cannot seem to get num_rows for work. I’ve looked at several sites for examples, but I can’t seem to make it functional. Below is how I would have written a mysql_num_rows() in the past. I know that it’s been deprecated. I would appreciate it if somebody could show me the current re-write. I also know num_rows seems to be frowned upon but I’ve already got my work cut out for me on the upgrades I have to finish before Monday, Oct 21st, for my students so I’m just needing to understand the current structure. THANK YOU! $query = "SELECT * FROM ember_students WHERE teacher = '$uname'"; $result= $pdo->query($query); $num = mysql_num_rows($result); foreach($result AS $row){ print $row['lname'].", ".$row['fname']."<br>"; }
  4. Nevermind all that. As soon as I switched to YOUR open connection code the script worked. You had given me a sample connection code on another thread last week, but I had already found something that seemed to work. It was obviously seriously flawed. When I switched to yours this problem went away. THANK YOU!
  5. I'm getting the following error messages: Warning: Undefined variable $pdo in /home/jandrews/public_html/admin_authenticate.php on line 12 Fatal error: Uncaught Error: Call to a member function prepare() on null in /home/jandrews/public_html/admin_authenticate.php:12 Stack trace: #0 {main} thrown in /home/jandrews/public_html/admin_authenticate.php on line 12 That's the line with: $stmt = $pdo->prepare($query); <? session_start(); extract($_REQUEST); $fname = ""; $lname = ""; include 'r_open_link.php'; $query = "SELECT * FROM ember_features WHERE id = ?"; $stmt = $pdo->prepare($query); $stmt->execute([4]); $row = $stmt->fetch(); // Testing accurate dB data readout print "<br><br>"; print "First name: ".$row['fname']."<br>"; print "Last name: ".$row['lname']."<br>"; ?> I'm afraid being used to PHP 5 I also suck at understanding defining variables. When I added $pdo = ""; after $lname = ""; the undefined variable error went away but not the other one.
  6. I got that dB open link code from a video on YouTube. I'll make the modifications you mentioned. I'm curious, do you have a preference between the non-prepared and the prepared, because I can follow the logical steps of the unprepared, but the prepared method is bit greek to me. I suspect you're going to tell me the prepared method is better and more secure (of course, because it's the more confusing one to me) so I just need to make myself okay with that. I think I can put it together. It's just so different from what I'm use to. THANK YOU for your response!
  7. Greetings. So I'm coming from the last 12 years using MySQL 5. I'm rewriting my site from scratch and have updated to PHP 8 and MySQL 8. If I could get a couple of examples to query a dB for a single row using PDO and then again using mysqli I would greatly appreciate it. Before now I would have written it as such: $query = "SELECT * FROM ember_features WHERE id = '4'"; $result= mysql_query($query) or die("Could not perform query: ".mysql_error()); $row = mysql_fetch_array(result); I have already successfully opened a link to the dB using: $db_host = "localhost"; $db_name = "jandrews_emberedutech"; $db_username = "********"; $db_pword = "********"; $dsn = "mysql:host=$db_host;dbname=$db_name"; try { $db_connection = new PDO($dsn, $db_username, $db_pword); $db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); //echo "Connection successful<br>"; } catch (PDOException $error){ echo "Error: ".$error->getMessage()."<br>"; echo "Code: ".$error->getCode()."<br>"; Die("Oops. Something went wrong in the dB."); } So I was hoping to get two working examples from this simple task that I could take and modify for my purposes ... one for the PDO method and the other for the mysqli method. THANK YOU!
  8. Yes, so I understand the error (for whatever reason being HTTP 500) was the result of using antiquated syntax, and that I’m also going to have to re-learn how to interface with a dB using a new syntax. The PDO method mentioned early on got me watching some videos on that which very closely mimic the PDO connection code here. I’ve got quite a bit more PDO videos and research to do in order to rebuild the site, but thank all of you for your patience and input.
  9. I checked the .ini file and both of these settings were set already as default so the http 500 error page seems to be displayed despite those settings. And yes, I created a php page to verify PHP functionality and put the phpinfo() in it to get the configuration display. Your statement that "ALL of the code dealing with data values being put directly into the sql query statements MUST be updated" is very helpful to me as it helps me fundamentally understand I'm just going to have to approach dB queries from different angle. So I guess I have some PDO syntax to learn. I do not mean to sound ungrateful. I've just spent the last 12 years writing code for a massive website which I use to manage and prepare resources for my students, and which they use to access those resources and learn. This website is over 1,000 files large with many files containing several hundred lines of code and some over 1,000 ... so you can see why I've been reluctant to update my PHP and MySQL systems. Doing so is relegating ALL of my code, my tools, and my resources to the ash heap of history. This 2008 Mercedes Benz I've been using (metaphor for my old server and site) has proven to be a POWERFUL tool in my class, but it seems to upgrade to the new 2024 Mercedes Benz is going to take a lot of learning, patience and most of all time. So, as I said up above, I guess I have some PDO syntax to learn.
  10. Okay, I changed the mysql statements to mysqli and received the same message, and yes my old site has been running with PHP 5 for more than a decade, and I’m starting a new server obviously requiring current syntax. So could somebody provide me with current syntax for establishing an open connection? And also, I remember my friend (who set up my last dB for me) having to make some settings changes to make sure that the dB was accessible from everywhere. I tried to read up on this and found that I needed to add an access host as % to allow my students to login and access the dB from anywhere. This is not what I do for a living. I am a Spanish teacher and I use my admittedly limited knowledge to complement my classroom resources. I’m not a mechanic who doesn’t know how the car runs. I’m a teacher who doesn’t know how it runs, so please forgive the lack of knowledge and experience. I’m afraid I don’t know what $pdo is either. Previously it was just a simple process of opening a link to the dB and then sending queries when needed. If that remains the same then I suppose that’s what I need mostly, however, my question about are there any modifications to a dB once it’s first activated that need to be done besides creating the necessary user data.
  11. Okay, let’s start with I know nothing about setting up a MySQL dB. I have used them for years but with a friend having helped me set up my last one literally more than a decade ago. I’ve purchased a new VPS and need the authentication script which I’ve used on my other site to function. Here is the old site’s script: <? $link = mysql_connect("localhost","xxxxxxxx","yyyyyyyy") or die("Could not connect: ".mysql_error()); mysql_select_db("zzzzzzzz")or die("Could not select database: ".mysql_error()); date_default_timezone_set('America/Winnipeg'); ?> x is the username, y is the password, and z is the dB name. This open dB link script works perfectly on my old site. Here is the script for the new site: $link = mysql_connect("localhost","xxxxxxxx","yyyyyyyy") or die("Could not connect: ".mysql_error()); mysql_select_db("zzzzzzzz")or die("Could not select database: ".mysql_error()); date_default_timezone_set('America/Winnipeg'); print "Test Alpha<br>"; As you can see they are practically identical. I’ve got the Test Alpha part in there just to help me verify page load, but the result on Chrome is a page which tells me: This page isn’t working. Emberedutech.com is currently unable to handle this request. HTTP ERROR 500. Other test pages to verify correct nameserver setting work, for example emberedutech.com/test_session1.php. I seem to be at the last step of setting up this website, but I am inexperienced (to say the least) with setting up dB’s. Please help.
  12. I really appreciate all the input here. Let me try to answer as much as I can. So, the server is a VPN which I rent from GoDaddy. I run the WHM and the cPanel, though "run" is probably not the right word. I have little experience with that aspect. So, I have root access. The tmp folder in the root directory does have it's permissions set up properly ... 0755. I changed them to 0777 to see if that would correct the issue and it hasn't. I also attempted to use session_save_path to another folder which I titled "sessions" in my cPanel directory. It ran exactly as it had before. It used the new folder but had the same intermittent issues as had the other folder. If I just sit there and try time and time again to login I get a success rate of about 1 in every 4 or 5 attempts. Each failure is met with the same message that it did not have permission to write to the sessions file. I have a friend helping me who has more experience than I but he is perplexed too. We DID see the session file being written each time whether there was failure or success, but the failure sessions variables contained zero bytes ... were completely empty, whereas the successful ones contained the data you would expect them to have. So in each case it appears the session variable was CREATED, but then the system was denied access to WRITE to it. I have found several other instances online with problems matching this exact description but none of their stated solutions have worked. I have students walk into my classroom in 18 hours. Also, upon further testing I don't believe there's a relationship (as I previously suspected) between the http call and the https one. And, yes, I'm sending sessions_start() before any other coding. The headers to these files are contained in the "include 'r_declaration.php';" statement, and the "include 'r_open_link.php';" is a call to open a link to the dB. And the if/else arguments render the same result because I use to send mobile devices to another page. I haven't deleted the code as I plan on re-implementing this at some point. I just don't get it.
  13. Still getting session errors!
  14. All of the advice above is valuable, and I do plan on upgrading my PHP. I am a much better programmer now than when I started this project 11 years ago. HOWEVER ... Another variable I've noticed has come into play here. I've been getting server generated emails saying "Notification The service "ftpd" appears to be down." If there is intermittent failure of this process could that be causing the session variables not to get written in the tmp folder? Also, I noticed a change in behavior between http calls and https calls. Once I forced http instead of the browser wanting to use https I no longer had the session variable problem ... even if I began switching between the two protocols (http / https). Now I'm really confused!!! AAAUUUGGGHHHH! Below is a simple login script that I wrote to test session function. It worked with http, but when I put in https it gave the error messages without even submitting the form. But now, after having used both https and http it functions either way. It just feels like there's a monkey with a wrench living in my server!!! The kicker is that RIGHT NOW it's all working properly, but 1) I haven't done anything, and 2) how long will it continue to do so since I haven't "fixed" anything, and 3) what's up with that "ftpd" failure message?!?!? and is that ultimately the cause of all of this!!! <? session_start(); extract($_REQUEST); ?> <body bgcolor="000000" style="color: #ffffff;"> <p>Innovative Education Works</p> <form action="index_test2.php" method="post"> Username: <input type="text" name="uname" size="20"><br> Password: <input type="text" name="pword" size="15"><br> <input type="submit"> </form> </body>
  15. Let me start by saying ... I suck. I am a high school Spanish teacher who manages his own WHM, cPanel, and site. I use PHP extensively on my site to create tools for my students. Nothing any one of you would call advanced coding, but I can do some really cool stuff with some really basic PHP and MySQL dB access. All that being said, let's go back to the first thing I said ... I suck. And here's why. I have not upgraded my PHP since version 5.4, and I have long since disabled automatic upgrades. My website is somewhere around 1,100 files which I've been building for the past 11 years and I have a great fear of upgrades to PHP and the truncating of old PHP rendering my site disabled. Imagine the task of going through 1,100 files many of which are several hundred lines of code long and re-coding truncated old PHP code, and then debugging the new code. I LOVE programming in PHP but I fear I'm about to reach a point where because of the age of my code that it won't work anymore. I have built the last ten years of my career as an adaptive and improvisational teacher on this code and website. So, my question is how real is my fear that if I upgrade to PHP 8 that I will encounter problems? You see my code is so old that I'm not even using the new MySQL protocols like "mysqli_query()." I still use "mysql_query()." I understand that there are reasons to start using the new format. I've just got a website full of code whose format is 11 years out of date.
×
×
  • 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.