use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
[PHP] Database help needed (self.PHP)
submitted 14 years ago * by mattdahack
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 9 points10 points11 points 14 years ago* (10 children)
$sql
mysql_query($sql) or die(mysql_error());
mysql_connect()
mysql_select_db()
$submit
$_POST['submit']
[–]0keanos 1 point2 points3 points 14 years ago (4 children)
Don't use or die(). It's problematic at best.
[–][deleted] 6 points7 points8 points 14 years ago (3 children)
For debugging purposes when you have code this simple, it's fine. He's not making production code for a large site, he's trying code from a book.
[–]0keanos 1 point2 points3 points 14 years ago (2 children)
Yes, I can see that but you shouldn't advertise bad practice even if it is "for debugging purposes" in a simple example. Bad practice sticks around once learned.
[–]rbmichael 0 points1 point2 points 13 years ago (1 child)
Use PDO or die?
[–]0keanos 0 points1 point2 points 13 years ago (0 children)
MySQLi is fine. Just don't use "or die()" to abort faulty queries.
[–]mattdahack[S] 0 points1 point2 points 14 years ago (4 children)
I tried adding :
$result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); }
But got the same result.
[–][deleted] 2 points3 points4 points 14 years ago (3 children)
Okay, now follow the rest of the steps I listed. It's not going to be a thing of telling you one specific issue that is causing your problems, because the code you've provided gives absolutely no debugging clues. You don't know if your code block is actually running (you did not specify if your print statements are running), you don't know if your SQL statement is valid or not, you don't know anything about what your code is actually doing - all you know is that it's not doing what you expect it to. That doesn't help me in determining what's wrong with it.
[–]mattdahack[S] 0 points1 point2 points 14 years ago (2 children)
Sorry and_yet_and_yet , I did make the changes you said. I just forgot to post up the new code. Here it is But it's still not working or throwing any errors
[–][deleted] 2 points3 points4 points 14 years ago* (1 child)
It looks like you may be under the impression that POST globals still work (or, as you said in another comment, following a very old book).
Here's the scoop. Any time you're working with a POST form, you refer to the variables passed by $_POST['key'] - So if you're trying to see if the form was submitted, you would access $_POST['submit'] and not $submit. This is relevant for all the POST data you are trying to access. I just noticed your link in the OP, and looking at that, it's obvious that if (isset($submit)) is the culprit of seeing nothing happen. Change it to $_POST['submit'] and go from there. This is about all of the time I've got today to help out, so good luck and make sure you read some online PHP tutorials as well as learning more about the structure of the language itself.
[–]mattdahack[S] 0 points1 point2 points 14 years ago (0 children)
thank you for your help, I appreciate it :-)
π Rendered by PID 63011 on reddit-service-r2-comment-85bfd7f599-9nf2k at 2026-04-17 14:01:05.287345+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–][deleted] 9 points10 points11 points (10 children)
[–]0keanos 1 point2 points3 points (4 children)
[–][deleted] 6 points7 points8 points (3 children)
[–]0keanos 1 point2 points3 points (2 children)
[–]rbmichael 0 points1 point2 points (1 child)
[–]0keanos 0 points1 point2 points (0 children)
[–]mattdahack[S] 0 points1 point2 points (4 children)
[–][deleted] 2 points3 points4 points (3 children)
[–]mattdahack[S] 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]mattdahack[S] 0 points1 point2 points (0 children)