FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > PHP, Perl, Python and/or MySQL
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-14-2019, 01:08 PM   Postid: 187404
chernove
Site Owner
 
chernove's Avatar

Forum Notability:
65 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2002
Location: NYC
Posts: 162
Another Script Issue

Still working to update my scripts for the latest PHP version.
I have a table of musical material which is updated monthly with fields such as id, year, month, complast [this one indicates the composer's last name], title [name of musical piece], etc.

I want the script to check to see if the "order by" has already been determined (i.e., via the URL; for example: website.com/webpage.php?order=year ASC,month ASC), and if it has not, then to set it. This has always worked in my previous coding, but now that I've tried to update the code to conform to mysqli, it is kicking back that $order is an undefined variable on, let's say, line 50. I actually understand the guts of why this is, but I am not 100% sure how to avoid it (i.e., how to pre-set "order by" only to have it possibly be overridden). FYI, there are various links on the page so that the visitor can change the "order by;" this is the whole point, of course.

Here is the relevant code (as ever, if you need more, just ask):

PHP Code:
<?php

50 
if ($order=="") {
  
$order="year DESC,month DESC";
}    
    
 
$current mysqli_query($con"SELECT * FROM therelevanttable WHERE status LIKE 'archive' order by $order");
Obviously, I've put the "50" in here just to be superclear where line "50" is; it's not actually IN my code.

Thoughts?

Last edited by chernove : 10-14-2019 at 01:29 PM.
chernove is offline   Reply With Quote
Old 10-14-2019, 01:31 PM   Postid: 187405
chernove
Site Owner
 
chernove's Avatar

Forum Notability:
65 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2002
Location: NYC
Posts: 162
Re: Another Script Issue

Putting

$order = ($_GET["order"]);

on line 49 will get it to work correctly, but it runs clean only if the URL actually has the variable (in other words, it will work in any case, but if the URL is website.com/webpage.php and not, at least, website.com/webpage.php?order= there will still be an "undefined index," though the page will actually work perfectly despite the error).

Last edited by chernove : 10-14-2019 at 01:48 PM. Reason: Updated information
chernove is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:25 AM.


Running on vBulletin®
Copyright © 2000 - 2019, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2019 FutureQuest, Inc.
FutureQuest, Inc.