0

I have another script that I can't figure out what is wrong with it. I attempted to use the

error_reporting(E_ALL);

to report the errors, but it doesn't report anything. Anyway, here is the code I'm having trouble with.

<?php
error_reporting(E_ALL);
$username = $_POST['user'];
$email = $_POST['email'];
$password = md5($_POST['pass']);
$currname = $_COOKIE['ZBrownTechnologyCorporationBeta'];

$con = mysql_connect("HOST", "USER", "PASS");
if (!$con) {
  die('Unable to connect: '.mysql_error());
}

mysql_select_database("zach_blogin", $con);

if(empty($password)) {
  $nothing = "nothing";
} else {
  mysql_query("UPDATE members SET password = '$password' WHERE username = '$currname'");
}


mysql_query("UPDATE members SET Email = '$email' WHERE username = '$currname'");

if($username==$currname) {
  $nothing = "nothing";
} else {
  $query = ("SELECT username from members WHERE username = '$username'");
  $result = mysql_query($query);
  if (!$result) {
    header("Location: " . $_SERVER['HTTP_HOST'] . "/public_html/Beta/account.php?invalid");
    exit;
  }
}
mysql_query("UPDATE members SET username = '$username' WHERE username = '$currname'");
header("Location: ". $_SERVER['HTTP_HOST'] . "/public_html/Beta/main_login.php?update");
?>

I have looked over this code for a while now. Can't seem to get the error reporting to work, so here I am again. Thanks to everyone who has helped, and who will help!


By Request of @Klinky:

When attempting to use this page (named myinfo.php ) in Opera, it displays the default message indicating that it is not able to find the page and/or the server. In Internet Explorer 8, it displays a 500 Internal Server Error.

Here are the server specs: OS: Linux HTTP: Apache v2.0.63 PHP: 5.3.3 MySQL: 5.0.91-community


I looked in the logs, and this is the error message:

[Sat Sep 25 21:34:08 2010] [error] [client 68.52.52.190] PHP Fatal error:  Call to undefined function mysql_select_database() in /home/zach/public_html/Beta/myinfo.php on line 12, referer: http://zbrowntechnology.com/Beta/account.php

The only thing is, the database I tried to select does exist!

4
  • you also need to call ini_set('display_errors', 1); if you want errors output directly... otherwise they are only logged in whatever your error log is... usually the webserver error__log by default. Or you could jsut trun them on in the php.ini, but i wouldnt recommend that. Also your mysel function isnt going to throw an error directly... youd have to use mysql_error() to get a look at those. Commented Sep 26, 2010 at 3:22
  • Kinda like the sad face and PHP in one sentence. Looks like me coding in PHP. Commented Sep 26, 2010 at 3:31
  • I tried adding [code]init_set('display_errors', 1);[/code] but the errors are still not being displayed. Any ideas? Commented Sep 26, 2010 at 3:32
  • What is wrong? You've provided code, no errors, and what? What leads you to believe it's not working? Please provide more detail than it's a PHP code error and it's not working. Commented Sep 26, 2010 at 3:33

3 Answers 3

6

All your UPDATE queries are missing table name:

UPDATE TABLE_NAME SET .....
          ^^^^^
         missing

I would suggest, every time you call mysql_query() check its return value. If its false, the query execution failed and you can get the cause of failure by calling mysql_error()

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

More errors:

You need to enclose strings in single quotes in a query:

mysql_query("UPDATE members SET password = '$password'....
                                           ^         ^
                                             missing

Do it everywhere you are using a string in the query.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you, I fixed that... but it still doesn't work. Any more ideas? (I fixed the error in the snippet above as well. )
but it still doesn't work - What exactly doesn't work? Are you getting any error? Did you check the return value of all calls to mysql_query? as suggested in the answer?
I've updated my answer: you need to enclose string in single quotes. You'd have caught this error if you would have followed by previous suggestion of using mysql_error() :)
@codaddict Thanks again. Fixed that but I'm still have trouble. What I mean by "it doesn't work" is that when navigating to the page after submitting the form, it displays the old 404 Error, that the page cannot be found. I am using the browser Opera, think that is why the errors aren't being displayed?
@Zackhary: I'm happy that you finally told us the error :) Make sure you are using right URL (check for typos in the script name).
|
4

There is no builtin function name mysql_select_database. I guess you meant mysql_select_db

Change

mysql_select_database("zach_blogin", $con);

to

mysql_select_db("zach_blogin", $con);

1 Comment

@Zachary - I suggest you start using a real IDE like NetBeans. You could have saved yourself a lot of trouble here. Any modern IDE would have flagged that error as soon as you entered it.
0

Try setting the full URL for snippet:

header("Location: account.php?invalid");

HTTP spec says you should use the full url when doing a redirect. Though many browsers support a relative path. Try:

header('Location: ' . $_SERVER['HTTP_HOST'] . '/project-path/account.php?invalid');

REPLACE /project-path/ with the full path to where your .php files are.

6 Comments

A 404 error would suggest the server cannot find the file you're redirecting to or you're trying to run, so I'd check server logs and see if it's more detailed about what it cannot find.
Last time it did this, it was because it was missing a semi colon. ;-)
Something like that would usually cause something like a 500 Internal Server Error rather than a 404 File Not Found Error. Or you'd get the error displayed by PHP. I do not see any syntax errors in your code, so I don't think it's a semicolon missing.
URLs are case sensitive. Check that the case displayed in the address bar matches the actual name of the files and directories containing your script.
Wierd. It displays a 404 in Opera, but IE does display a 500. Does that change anything?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.