PDA

View Full Version : passing the mysql_select_db variables


whitedragon101
10-14-2009, 03:54 AM
I have set up a query which runs fine and my database link is using the dreamweaver connections.php file where the

<?php require_once('../../Connections/myconnect.php'); ?>is put at the top of the page. However when I put my query inside a function submitToDatabasePlease(), like this:



function submitToDatabasePlease()
{
$confirm_code = md5(uniqid(rand()));


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = "MY QUERY HERE"
mysql_select_db($database_myconnect, $myconnect);
$Result1 = mysql_query($insertSQL, $myconnect) or die(mysql_error());

}
}I get the following error.
mysql_select_db(): supplied argument is not a valid MySQL-Link resource

If I copy the actual details out of the connections.php file into the mysql_select_db function the query is successful. But thats obviously not a great solution to update every page every time I change connection details.

Is there a way to pass the connection information into the function?

bee80
10-14-2009, 07:50 AM
make it global

function submitToDatabasePlease()
{
$confirm_code = md5(uniqid(rand()));

global $database_myconnect;
global $myconnect;

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = "MY QUERY HERE"
mysql_select_db($database_myconnect, $myconnect);
$Result1 = mysql_query($insertSQL, $myconnect) or die(mysql_error());

}
}

whitedragon101
10-14-2009, 09:06 PM
make it global

function submitToDatabasePlease()
{
$confirm_code = md5(uniqid(rand()));

global $database_myconnect;
global $myconnect;

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = "MY QUERY HERE"
mysql_select_db($database_myconnect, $myconnect);
$Result1 = mysql_query($insertSQL, $myconnect) or die(mysql_error());

}
}


Bingo :-D thanks Bee80

bee80
10-15-2009, 07:35 AM
no problem :)