-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Community Answers
-
ginerjm's post in Muti if statements was marked as the answer
Do you mean:
if ($row['extension'] == "mp4" || $row['extension'] == "xxx" || $row['extension'] == "aaa") { // show this file } elseif ($row['extension'] == "jpg" || $row['extension'] == "jpeg" || $row['extension'] == "txt") { // show this file instead }
-
ginerjm's post in trying to insert multple form data into msyql database was marked as the answer
While you have 2 very reliable responses to answer your question, I see no problem with the way you have designed your page. I think the problem you are having is you are not reading the input delivered to your script properly.
You probably have a loop that is simply trying to check if an input is present rather than if it is empty, ie, not entered. As we all know your $_POST array is going to have all of the text inputs present (which you really should be designating) even if the user did not put something into them. So - in your processing logic, look for a value in your loop and not just whether isset() is true. It's always true (unless it's a checkbox or a radio) so that is not a good test. Check if it has something in it instead. Choose the key field that indicates whether the user is posting something to that data row and rely on your testing of that item. If it is empty then do a continue and move on to the next row.
Just my $.02.
-
ginerjm's post in Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; was marked as the answer
You have an extra , right before the ) as the error message is telling you.
In the future when posting code that includes an error message with a line number it would be always helpful to point out that line when you show the code.
-
ginerjm's post in how to updat 2 tables in one database within one form? was marked as the answer
You will have to write a separate query to update the other table. Be sure to check the first query is successful before doing the second one.
And read up on how to do a prepared query since you are inserting user-generated data into your table which could corrupt your database.
And - BTW - you would be better off if you learned to use the PDO interface instead of MySqlI. If you have access to it.
-
ginerjm's post in How to show multiple records with the same name on the same page? was marked as the answer
Here is my much-abbreviated copy of your code. Let's see what you get from it without all of the css and the needless fetchall.
$sql = "SELECT a.question, b.choice FROM questions a, quiz_options b where a.qid = b.qid"; if (!$results = $pdo->query($sql)) { echo "Could not run query: $sql"; exit(); } $last_q = 'x'; while ($row = $qresults->fetch()) { if ($last_q <> $row['question']) { echo $row['question']; } $last_q = $row['question']; echo $row['choice'] . '<br>'; } I'm trying to give you something that displays the data just to be sure that your query is providing what you think it is.
-
ginerjm's post in How to display the entire table? was marked as the answer
If the answer is clear to you in the code - Why are we still on this topic? I have no idea what you have written that makes you happy since you are not sharing anything here. So why don't you just mark this as solved and end this topic?
-
ginerjm's post in Using 2 databases in one loop was marked as the answer
One does not need to make 2 connections. Simply add the dbname to the tablename in your one query.
"select a.fld1, b.fld1,a.host, a.child, a...., b..., b... from db1.tablea a, db2.tableb b where a.key = b.key
-
ginerjm's post in Undefined array key at curl POST method was marked as the answer
What is the second line above supposed to be doing for you? It is not a usable statement. If you had error checking enabled you would probably get a message. Add this to the start of your script, right after the session_start:
error_reporting(E_ALL);
ini_set('display_errors', '1');
-
ginerjm's post in Need Help in order to dump Excel Sheet Record into MYSQL from one sheet to three Tables. was marked as the answer
Obviously this data needs to be normalized in order to build a database. You have all different data arrangements in a single sheet and probably multiple of those sheets in your workbook. Sounds like more of a manual effort to break this down into several csv files that you can then easily import into a properly structured set of table in your new db.
-
ginerjm's post in PHP filename in sub-directory not allowed to be number w include was marked as the answer
Basically it's telling you that there rules to filenaming.
What's wrong with naming them 'page1.php' and 'page2.php'? Too hard to program?
-
ginerjm's post in How do I retain the content entered into textarea after submitting, so that I can continue to add content? was marked as the answer
How long do you want this 'session' to go on for? You are setting up for a post session to send the input to your script and then you apparently send the screen to be re-displayed, but after doing what? Are you planning on saving the input in a table or in a text file? Plus your current code seems out of order since you are displaying the form before you have retrieved the "name" contents so it won't be displayed, if it even executes.
PS - don't use 'name' as your name field. Give the text are an actual name - not what is possibl a reserved word.
Question - what are all of the BLB lines about?
And your statement about "it is a simple thing to do". Where did you learn that to be true? Obviously it is not since you're here, no?
Let's start with a decision on my first question. Where are you keeping this data to be re-used?
-
ginerjm's post in some help using glob and foreach loop was marked as the answer
Don't know why the printf is needed. Here is how I would tackle it, no testing of course. I'll leave that to you.
$files = glob("images/*.{jpg,png,gif,svg,jpeg,bmp,webp}", GLOB_BRACE); $cnt = count($files); $i = 0; foreach ($files as $filename) { $i++; echo " <div class='mySlides fade'> <div class='numbertext'>$i / $cnt</div> <img src='$filename' style='width:100%;'> </div> "; } Not sure what $filename actually contains but you can easily append anything needed to the src= attribute clause if it's not already there
-
ginerjm's post in Leon's PHP/MySQL project Q/A thread was marked as the answer
You have $pdo and $PDO. What do you think?
-
ginerjm's post in Return vs Echo was marked as the answer
An echo is an 'output' statement which is why you actually see something. A return is not. It is simply a method to pass a value back to another that is waiting to receive it.
-
ginerjm's post in Simple SQL select query not pulling any data was marked as the answer
Try dropping the quotes on the args in the query. The PDO prepare will correct what is necessary
And what are you outputting when there are rows? It looks like a string of the word 'this' repeatedly.
-
ginerjm's post in Getting error on php contact form was marked as the answer
The above line makes an array having one element (0) whose value is 'nospam'.
What are you planning to do with that array? I don't see it referenced but it still seems like a funny thing to be doing. You are doing a check for the entry in this field but not with the array you have created. Perhaps you simply want to create it near the top of your script as a simple static variable and not an array?
and then maybe you want to change this
if ($post['secretcode'] != 'nospam')
To be
if ($post['secretcode'] != $secretcode)
BTW - You seem to be doing this thing with your own version of the $_POST array for no good reason. Is this something you read about somewhere that is supposed to be of help to your algorithm? Why not just use $_POST? It's a global array that you control and is accessible from your entire script.
-
ginerjm's post in PHP Parenthesis? - totally new at this was marked as the answer
As I said first thing -- the style of this code is not allowed at all. It has to be re-written. These new lines are not the same as the one you have the error on. They do not follow the same format as the bad one.
I have no idea what the app is supposed to do for you but it is written rather tediously and I would have definitely found another way to do this that the mind-numbing way that the original code chose. I'm guessing that he/she too was a noob when writing it.
Try this:
$coronavirus_notice_banner_color = @$_POST['action']=='save_coronavirus_notice_plugin' ? $coronavirus_notice_banner_color : (get_option('coronavirus_notice_banner_color') ? esc_html(get_option('coronavirus_notice_banner_color')) : '#CC0000'); And I really don't like the use of the @ in this code. It is not a good practice.
-
ginerjm's post in Why setted cookie variable needed twice click to hyperlink? was marked as the answer
Not sure what "setted" means but when you do set a cookie in your current script, it is not available until you refresh the page you are on. Cookies are loaded when the server sends a page to the client. Does that help?
-
ginerjm's post in Delete data error was marked as the answer
I believe that your JS should be in the admindashboard script not the delete script.
<script type='text/javascript'> function confirmDelete() { if (confirm('Are you sure you want to delete this record?')) return true; else return false; } Use the above function like this:
<input type="submit" name="search_by_roll_no_for_delete" onclick='return confirmDelete()' value="Delete"> You can use shorter names for your fields. Saves on typing
-
ginerjm's post in md5sums wrong on downloaded files was marked as the answer
And as Kicken has already asked you - where is the part concerning your posted topic title? Can not see the fact that there is nothing related to anything 'md5 ish' in this code?
PS - suggestion. Do your includes at the top of any script so that you know right away what the script has to work with. Dont bury your requires inside functions. It's kind of like burying a function inside a function. Calling one is ok - including one is not a good practice.
-
ginerjm's post in Wrong md5sums when downloading from web host was marked as the answer
Well if it is EXACTLY as copied then I don't know what it is doing. If you are trying to ask "is $ext equal to .deb" then you are not doing that. Try 2 equal signs...
As for your concern about the md5sums - since there is no code present showing us what is or is not happening, we can't help you.
-
ginerjm's post in Simple PHP Include Question - I think my host changed something was marked as the answer
What is the name of the file you are executing? If it is showing raw php code you are not running a php file and make sure that if you are that the opening tag is a full php tag as in: <?php
-
ginerjm's post in Deciding which page to load was marked as the answer
Follow-up
If the class you posted is EXACTLY the same as what you are executing I think you either botched the html that references it or you messed up the css portion of your script. I pasted it into my script (that I gave you) and the submit tags show up nicely formatted.
-
ginerjm's post in form input read only for multiple fields was marked as the answer
A little cleaned up version of your code and my notes on it.
echo "<form method='POST'>"; foreach ($assetx as $key => $value) { echo "<label>" . ucfirst($key) . " "; $ro = ($key === 'id') ? 'readonly' : ''; echo "<input type='text' name='$key' id='$key' value='$value' $ro>" echo '</label><br>'; } echo "<input type='submit' name='submit' value='Submit'>"; echo '</form>'; 1. One doesn't have to keep going into and out of php mode. It especially makes it easier to comprehend if one doesn't.
2. I can't find any mention of an 'escape' function in my php manual. Can you explain what you are trying to do with your use of it?
3 Your foreach is processing an array I assume. If that is so, how do you expect to have 2 keys having the same value of 'id' ?
-
ginerjm's post in Uploading Image with PHP from non-root folder was marked as the answer
Root to the rest of us is a specific term that is related to the domain or the html web root. So I am assuming that your root myprojects folder is under the true html root folder. So if you want your php commands to locate the folder you want you need to probably specify $_SERVER['DOCUMENT_ROOT'] as I mentioned along with the /MyProjects/../...... path to your desired folders.
$_SERVER['DOCUMENT_ROOT'] . '/MyProjects' would position in what you are calling root. If you other folders are beneath that then add them to it with a leading backslash of course.
Hope this is what you are looking for.