I've just started php and mysql.trying this code to check if mysql account is correct or not.

<?php
    $usr=$_POST['username'];
    $psw=$_POST['passwd'];

echo ' body tag, other things and a message: Logging in! '; echo $usr;

$connection = myqsl_connect('localhost',$usr,$psw);
if (!$connection){
    die('<p>Stopped : ' . mysql_error());
    echo '<br /><a href="index.html">Retry</a></p>';
}
else echo '<p>Logged on!<br /><a href="something.php">Continue</a></p>';
//planning to add mysql_close($connection) here
?>

page has nothing else but the endings of tags started in first "echo" and some <head></head> configuraiton. code is between </head> and </body> tags. (it includes the <body> tag in an "echo"). this writes no output from the if - else statement; but rest of the html and css is shown. post variables can be seen when I write them to page with echo. please help. thx.

Dani AI

Generated

As spotted, the most likely immediate cause is a typo in the connection call. An undefined-function fatal error will stop the script immediately; with PHP error display turned off that looks like "nothing happened" even though earlier echoes (which ran before the error) still appear. Also note that die()/exit() halts execution, so any echo placed after a die() call will never run.

Common, quick checks and fixes:

  • Turn on full error reporting while debugging so the actual error is visible.
  • Verify the connection function name and PHP version (ext/mysql was deprecated and removed in newer PHP; migrate to mysqli or PDO).
  • Avoid printing credentials. Check isset($_POST['...']) before using them.
  • Inspect the webserver/PHP error log if no on-page errors appear.

Enable errors (development only):

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

Example of a safe modern connection pattern (procedural mysqli shown; adapt to PDO if preferred):

<?php
$conn = mysqli_connect('localhost', $user, $pass, 'dbname');
if (! $conn) {
    echo 'Connect error: ' . mysqli_connect_error();
    exit;
}
echo 'Logged on.';

References and migration notes:

Final notes tied to the thread: had visible echoes before the connection line, which fits the "fatal error halts script" behavior. After fixing the typo and enabling errors, adjust the flow so the retry message is printed before calling exit() or print it as part of the error output.

Recommended Answers

All 2 Replies

I believe in line 7, u mean mysql_connect.... right!

excuse me for that:) I was too tired, learning css, html, php and mysql alltogether... i've skipped that..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.