-
Posts
2,134 -
Joined
-
Last visited
-
Days Won
42
Posts posted by benanamen
-
-
Seems to me that whatever your file setup is, $con is not accessible to the file you have the function in. And your still missing the $con parameter for the error call. To avoid a lengthy thread, PM your code files to me and I will review them.
-
$con is outside the scope of your function. The function does not know it exists. You need to pass $con to the function. I would suggest learning about variable scope. I would also highly recommend you turn on error reporting.
-
1
-
-
As to the first, is $con supposed to be $conn?
As to the second. You are missing the connection parameter.
-
1. Stop with the random use of curly braces. Just use them always.
2. Get rid of the redundant submit check. You should be checking the REQUEST METHOD anyways. Checking for submit can fail in certain cases.
3. Stop creating variables for nothing.
4. The errors should go in an errors array.
5. Your code gives a success message for submitting an empty form. That makes no sense.
6. There is nothing that stops the DB insert since you do nothing with the errors.
-
Op, tell us what the real problem is you are trying to solve with this rather than asking about your attempted solution to the problem. What is the high level overview of what you have going on?
-
The manual is always a good place to start.
-
1 hour ago, ginerjm said:
for sure you have to sanitize it to avoid damage to your database or whatever your script is doing with the data.
That's what prepared statements are for. Although, you would VALIDATE the data.
-
@gingerjm, it is part of PRG. Post, Redirect, Get
-
Lets just move on. Yeah, OP, I noticed something funny going on with the posts and timing of edits/deletes. It was something beyond us which made things confusing for both (all) of us.
-
It wasn't "baseless" until you deleted your post after I posted, thus derailing the continuity of the thread. Great job solving the problem yourself though. 😀
-
Your second post has absolutely nothing to do with your first post. You really should have created a new thread. A simple google search on using LIKE would have easily answered your question. I guess you didn't read the page I posted the link to.
-
-
I would encourage you to continue to learn. As you get better you will recognize that tutorials such as the one you followed was very poorly done.
-
11 minutes ago, ginerjm said:
BTW #2 - if you already have these data items in your database, why do you need to copy them to new tables?
Yeah, the question smells. OP tell us what the real problem is you are trying to solve instead of asking about your attempted solution to solving it.
-
I would suggest you take some time to get down on SOLID principles. Here are a couple links. (I didn't read these pages. There may be better links)
https://medium.com/prod-io/solid-principles-takeaways-ec0825a07247
-
There is much that could be said about this code, but to keep on point, you need to use Dependency Injection and pass an instance of the helper class to your user class just like you did with the PDO connection.
* The duplicate query should be one of the first clues of a problem with this class.
Quote// The start of going from procedural to OOP
This pretty much explains what I see here so the current state of the code makes sense for now. You should eventually end up with quite a bit of refactoring when you get it dialed in.
-
What have you tried besides posting this on every coding forum?
-
1
-
-
The first problem is that you are using variables in your query. You need to use Prepared Statements.
You have not shown us where $check1_res comes from.
-
Your right. It "doesn't work".
-
Truncate the table. It will also delete all the data.
TRUNCATE TABLE table_name;
TRUNCATE TABLE table_name;-
1
-
-
Allow me to direct you to the PHP Manual. It gives you an exact example of what you are asking.
https://www.php.net/manual/en/function.error-log.php
-
1
-
-
In HTML5, the "action" is not necessary at all when submitting to the same page. You can simple do like so...
<form method="post">
-
The one thing that hasn't been mentioned is WHY would YOU want to do this in the first place?
-
The last part could use some cleanup.
if (mysqli_num_rows($result)) { return $result; } return false;
Having an issue with a query that should be very easy...
in PHP Coding Help
Posted
How and where are you calling the function?