Jump to content

Recommended Posts

I have created a script to insert data into a database, but it returns this.

 

Warning: mysql_select_db() expects parameter 2 to be resource, null given in /RJFWS198/testing/elemata_project/admin/elements/create_page.php on line 51

 

Here is the code

 

<?PHP 

//Protect Against Attacks

if (empty($_SESSION['E_User']))
{
die("Access Denied");
}

?>
<?php

if (!empty($_REQUEST['title']) && (!empty($_SESSION['E_User'])))
{ 
require_once('../Connections/default.php');

if (empty($_REQUEST['password'])) { $password = "0"; }else{ $password = $_REQUEST['password']; }

if (empty($_REQUEST['menu_order'])) { $mo = "0"; }else{ $mo = $_REQUEST['menu_order']; }

if (empty($_REQUEST['meta_keywords'])) { $meta_keywords = "0"; }else{ $meta_keywords = $_REQUEST['meta_keywords']; }

if (empty($_REQUEST['meta_desc'])) { $meta_desc = "0"; }else{ $meta_desc = $_REQUEST['meta_desc']; }

if (empty($_REQUEST['meta_copyright'])) { $meta_copyright = "0"; }else{ $meta_copyright = $_REQUEST['meta_copyright']; }

$author = $_SESSION['E_User'];

$date = date("m.d.y");

$day = date("d");

$month = date("n");

$year = date("Y");

$time = ''.date("g").''.date("i").''.date("a").'';

$ptitle = $_REQUEST['title'];

$post_content = $_REQUEST['postContent'];

$searchable = $_REQUEST['seachable'];

$locked = $_REQUEST['privacy'];

$tags = $_REQUEST['tags'];

$meta_robots = $_REQUEST['robots'];

mysql_select_db($database_default, $default);
mysql_query("INSERT INTO posts (`time`, `year`, `month`, `day`, `date`, `author`, `title`, `content`, `searchable`, `locked`, `password`, `menu_order`, `tags`, `meta_keywords`, `meta_desc`, `meta_robots`, `meta_copyright`) VALUES ('$time', '$year', '$month', '$day', '$date', '$author', '$ptitle', '$post_content', '$searchable', '$locked', '$password', '$mo', '$tags', '$meta_keywords', '$meta_desc', '$meta_robots', '$meta_copyright')");

}
?>

This is the code in the required file

 

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_default = "localhost";
$database_default = "X";
$username_default = "X";
$password_default = "X";
$default = mysql_pconnect($hostname_default, $username_default, $password_default) or trigger_error(mysql_error(),E_USER_ERROR); 
//Get Elemata Pro User Data
$ecms_user = "XXXX";
$ecms_password = "XXXX";
$ecms_key = "XXXX";
//Elemata Connection Information
$site_id = "XXXXXX-XXXXX-XXXX-XXXXX"; //Do Not Change This ID
$action_key = "XXXXXXXXXXXXX-XXXXXXXXXX-XXXXXXXXX-XX"; //Do Not Change This Key
?>

The code you have posted cannot produce the error you are getting.

 

Either you have more than one default.php file at different paths and you are including/requiring the wrong one or your require_once() statement is actually using a URL and you altered the code for the post or you have some code somewhere that is un-setting the $default variable after the database connection was made or the code you posted is inside of a function definition and you didn't bother to post the actual code.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.