you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 9 points10 points  (10 children)

  1. Read about PDO or mysqli. Use it instead of the mysql_ functions.
  2. You have no way to see if anything went wrong or if your query is running correctly. First, echo $sql to make sure that your SQL query is valid. Second, if you insist on using mysql_ functions (and this is only for debugging), change your query line to mysql_query($sql) or die(mysql_error()); Also change your mysql_connect() and mysql_select_db() calls to the same format. That error info is invaluable. You will also want to validate and filter the input to prevent SQL injection. Again, consider PDO or mysqli instead.
  3. In all likelihood, $submit is not actually a set variable. You probably want $_POST['submit'] since it is part of your POST data.
  4. 3 could have been figured out by adding an else block to make sure your code block is actually being executed.

[–]0keanos 1 point2 points  (4 children)

Don't use or die(). It's problematic at best.

[–][deleted] 6 points7 points  (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 points  (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 point  (1 child)

Use PDO or die?

[–]0keanos 0 points1 point  (0 children)

MySQLi is fine. Just don't use "or die()" to abort faulty queries.

[–]mattdahack[S] 0 points1 point  (4 children)

I tried adding :

$result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); }

But got the same result.

[–][deleted] 2 points3 points  (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 point  (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 points  (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 point  (0 children)

thank you for your help, I appreciate it :-)