-
Posts
2,134 -
Joined
-
Last visited
-
Days Won
42
Posts posted by benanamen
-
-
Still seems there would be a better way.
Where is the data coming from?
-
-
Your methods are just ridiculous. Stop creating a bunch of variables for nothing. The whole Class_info.php need to be thrown in the trash. It is just a container for a bunch of variables for nothing.
You have an HTML5 document yet you are using XHTML tags.
-
More so for not giving the code and making me do the work :-)
I have a lot of respect for @requinix for that approach.
-
Thumbs up to you @dudleylearning. It says a lot about you as a coder. Many posters just want someone to spit some code out to them and don't care if it is correct as long as it 'works'.
-
Now you need to update your code to use prepared statements. You NEVER EVER send user supplied data directly to the database. Your code is vulnerable to an SQL Injection Attack.
-
What you are looking for is called "Auto Complete". It is the same thing google does. It uses AJAX. Google is your friend. I easily found numerous examples. There is no need split the data unless you want to get results by category like @Barand said. The only thing with categories is a medicine can fall into numerous categories. If you do not have that all mapped the user may have trouble drilling down to a specific medicine. A single autocomplete is best if they already know the name of the medicine. You may actually want both options, one if you know the name, the chained select if you are trying to find a type of medicine.
https://www.google.com/search?q=php+autocomplete+dropdown+from+database
-
You have name set to not allow nulls and there is no default value set for that column. In your query you do nothing with the name column. As you have it, you can think of 'name' as a required field.
-
The code will be controlling the HTML display in a page.
No it won't. To answer your question, yes, there is a problem with the way you wrote it.
-
The php statement is inside a Wordpress post.
And there's your "problem". Wordpress is not going to run code in a post. That would be a MAJOR security problem if it did.
-
I personally am not comfortable running an encoded app from a source with no reputation of trustworthiness. There could be anything in that code.
The app does look interesting though.
-
1
-
-
@requinix, nice job with the trial and error approach with the OP. That is my prefered method of teaching rather than spoon feeding answers. He will learn better this way IMHO.
-
1
-
-
You have all kinds of problems.
1. Stop using Dream Weaver and use a proper IDE
2. Stop needlessly mixing all your html with php
3. Learn how to properly use heredoc
4. Don't post code with all the line numbers. Our own proper IDE's will give us the line numbers if we need it.
5. Basically your Php processing should be at the top of the page and the HTML at the bottom, although you should be at least separating the HTML from the page with an include or ideally use a proper template engine like TWIG.
6. You can't be mixing quote types.
7. Your missing brackets
8. Your missing parenthesis
9. Your missing quotes.
If you used a proper ide you would have seen all those careless mistakes. The code is full of it from top to bottom.
-
I've read your post a couple of times, and I'm still not sure what exactly you're asking for.
Same here.
I use router pages with includes, and using $_GET as the switch, but that seems to be getting cluttered and not very good.
Are you talking about something like this? https://forums.phpfreaks.com/topic/302370-router-any-issues-comments/
-
I agree with @Barand on the single table. Whenever I see UNION being used on a forum the DB design is always not properly normalized.
-
Another version
<?php $i = 1; while ($i <= 5) { echo str_pad('', $i, '*') . '<br>'; $i++; } ?>
-
<?php
for ($i = 1; $i <= 5; $i++)
{
for ($j = 1; $j <= $i; $j++)
{
echo "*";
}
echo "<br />";
}
?> -
You don't need all that flag stuff and a "working solution" doesn't make it right. Of course you will want to use htmlentities on the output.
It also looks like you should be using a WHERE clause since you are only looking for a particular result that matches $_GET.
<?php $sql = "SELECT column_name FROM table"; $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(); if ($result) { foreach ($result as $row) { echo "{$row['column_name']}<br>"; } } else { echo 'No Results'; } ?>
-
Yes. I already found my mistake. Thanks for trying to help
I made same radio names and added if ($_GET['1'] == (radio value)) and its all perfect
That is still wrong. $_GET can have numerous parameters. You are missing a name such as id=1. In your case it is name=1. You should probably be using POST instead of GET.
<?php if (isset($_GET['name'])) { if ($_GET['name'] == 1) { //do something } if ($_GET['name'] == 2) { //do something } if ($_GET['name'] == 3) { //do something } } ?>
-
You are not doing any checks to see if the form has been submitted so the entire code runs before you doing anything. Look up and learn about isset.
There are other problems I am sure others will tell you about.
-
In a nutshell, using tables for page layout went out in the 90's. This is almost 2017, use CSS like you're supposed to.
-
Ok, So it is a Mysql Keyword. Nevermind on the back ticks OP. name is still not a good column name anyways. What kind of name is name? Who knows? It is not descriptive enough. Thanks @Barand. I missed the line "Reserved keywords are marked with ®. ".
Per the manual:
Nonreserved keywords are permitted as identifiers without quoting. Reserved words are permitted as identifiers if you quote them as described in Section 9.2, “Schema Object Names”:
-
FYI: name is a mysql reserved word. If you're going to stick with bad column naming using reserved words you need to use backticks. You should be using something better like first_name, last_name.
`name`
-
Either put your form in the page as html or include it into the processing page to separate the html from code or use a proper template engine like TWIG. Don't mess with that form in a function mess. That is noob 101.
INSERT ON DUPLICATE KEY UPDATE with Composite key
in MySQL Help
Posted
What is it that you are actually working on, meaning, the overall task, not your attempted solution to it?