0

I have just deployed my database to a remote server but unfortunately I cannot seem to be able to insert new records. PLEASE NOTE, that this was not the case as I was able (and still are) to insert and Delete records on my local server (WAMP).

Each time I try inserting a new record entry, I get a `Could not Add New record. No database selected.** It is also worth noting that the table entries that I had made before exporting the sql file are still visible in the remote database tables.

I have checked through the database config file and made sure that the respective database is chosen. Please, kindly assist as i have tried all.

Here is the code that i am working with:

connect.php

<?php 
$hostname_connect = "localhost";
$database_connect = "dan_license";
$username_connect = "dan";
$password_connect = "anfield";
$connect = mysql_pconnect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

license_processer.php

<?php require_once('Connections/connect.php'); ?>
<?php 

    $value1 = $_POST['license_type'];
    $value2 = $_POST['license_date'];
    $value3 = $_POST['license_expiry'];
    $value4 = $_POST['license_cost'];

    $result = mysql_query("INSERT INTO license (license_type, license_date, license_expiry, license_cost) VALUES ('$value1', '$value2', '$value3', '$value4')");


?>
<?php include('includes/form_body.php'); ?>

form_body.php

<?php
    if(!$result){  
    die('Could not Add New record: ' . mysql_error());
    }
    else{ 
    echo "<h2>Success. New Record added!</h2>"; mysql_close();
    }
?>

None of the options listed have been successful so far.

Josealonso14
  • 37
  • 1
  • 6
  • The message tells you what's wrong: **No database selected.**. If you had just a single database on your development server you might have got way without selecting it. **Note**: `mysql_*()` is deprecated and should not be used for new code. I'd also be sure that a persistent connection is what you need before you use it, too. –  Apr 19 '14 at 23:00
  • Add a mysql_query(USE yourdbname); but the main thing is that you are vulnerable to sql injection.http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – Mihai Apr 19 '14 at 23:11
  • You might want to try to use `mysql_connect` instead of `mysql_pconnect` and `$connect = mysql_connect($hostname_connect, $username_connect, $password_connect,$database_connect)` – Funk Forty Niner Apr 19 '14 at 23:16
  • If you use remote `MYSQL` server, shouldnt you be changing the `$hostname_connect = "localhost";` line ? – iamsleepy Apr 19 '14 at 23:18
  • localhost is valid only if your script is running on the same host – PalDev Apr 19 '14 at 23:45
  • And there is such thing as mysql bind address. And the user account for MYSQL can also be bounded by address. – iamsleepy Apr 19 '14 at 23:55
  • I have so far tried all the options listed in the reply section but so far none seem to have the database functional. – Josealonso14 Apr 20 '14 at 17:49

1 Answers1

0

I can see you connecting, but are you selecting a database to use?

connect.php:

<?php
$hostname_connect = "localhost";
$database_connect = "dan_license";
$username_connect = "dan";
$password_connect = "anfield";

$connect = mysql_pconnect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(), E_USER_ERROR); 
mysql_select_db($database_connect) or trigger_error(mysql_error(), E_USER_ERROR);

It should go without saying that you should be using PDO, or at the very very least MySQLi.

jonnu
  • 728
  • 4
  • 12