Hello.

I am beginning to re-develop a small database using PHP/MyQL; I have already sucessfully done this a year ago but no longer have access to the machine, code or credentials. It worked great! But now, I'm rebuilding it.

The test site (PHP) seems to be fine. I see no problems with the MySQL on the server.

The problem seems to be the connection between the two systems.

Honestly, I always have trouble with the smaller things such as this problem.

I am submitting data via the site, but the tables are still empty.

I'm confused at this point.

It may have something to do with this snippet:

<?php
if(isset($_POST['add']))
{
$dbhost = sql2**.********.com;
$dbuser = b8_14160***;
$dbpass = c*******;
$port = 3306;
$conn = mysql_connect($dbhost, $dbuser, $dbpass, $port);
if(! $conn )
.
.
.

Any help, hint or point in the proper direction would be greatly appreciated

Thank you in advance!
Matthew

Dani AI

Generated

Brief diagnostic and practical next steps for the symptom "form accepts input but tables stay empty."

As observed, missing quotes on host/user/password assignments and missing error output are common culprits. Another frequent, quiet failure in older code is misuse of mysql_connect parameters: passing a numeric port as the fourth argument will not do what was intended (that parameter is the boolean new_link). That explains why a script can appear to run but actually never establish the expected DB connection or select the right database. Since the old mysql extension is deprecated and removed in recent PHP versions, migrating to mysqli or PDO both fixes the port/argument confusion and provides safer APIs.

Checklist to narrow the problem quickly

  • Enable full PHP error reporting and display/log errors to catch connection/query failures.
  • Inspect submitted data with a debug dump (for example, a var_dump of $_POST) to confirm values arrive.
  • Confirm the HTML form uses method="post" and that the code checks the same submit identifier (or check REQUEST_METHOD instead of relying on a button name).
  • Verify connection parameters and how the port is supplied: with the legacy mysql driver the host may need "host:port"; with mysqli the port is a separate argument.
  • Ensure the correct database is selected and the DB user has INSERT privileges on that database and from that host.
  • Capture and log the DB API’s error string after connect and after query execution; also check affected rows or run the same SQL directly in phpMyAdmin to validate it.

Example: mysqli + prepared insert (safe, accepts port argument)

<?php
$mysqli = new mysqli('sql.example.com', 'db_user', 'db_pass', 'dbname', 3306);
if ($mysqli->connect_errno) { error_log('DB connect: '.$mysqli->connect_error); exit; }

$stmt = $mysqli->prepare('INSERT INTO mytable (col1, col2) VALUES (?, ?)');
$stmt->bind_param('ss', $val1, $val2);
$stmt->execute();
if ($stmt->affected_rows === 0) { error_log('Insert failed: '.$stmt->error); }
$stmt->close();
$mysqli->close();
?>

Final note: Given that the original setup once worked (per ), focus first on credentials, host/port format and remote-host permissions. Migrating to mysqli or PDO will avoid subtle parameter mistakes and improve error handling going forward.

Recommended Answers

All 2 Replies

The variable values, in this case, must be strings, so surround them with quotes:

$dbhost = "sql.domain.tld";
$dbuser = "username";
$dbpass = "password";

The port value can be submitted as integer, so you can omit the quotes. Anyhow, by adding mysql_error() you should be able to see the error.

Since you're rewriting the code I suggest you to switch to PDO or MySQLi libraries, because the one you're currently using is going to be removed from PHP, so check:

Thank you!

Still working on it...

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.