jponte Posted February 19, 2010 Share Posted February 19, 2010 Hi, I'm trying to code a page where users exchange devices. If the shipping information already exists in the DB then I would not create a new contact user in the DB and jus refernce the existing one in the RMA table. Now, if the contact does not exists I would cretae a new contact user and ID and add refernce the newly one create in the RMA table. I'm getting the errror "No database selected Error". Here is the code: //Set variables for database access $Host = "localhost"; $User = "root"; $Password = "escrma"; $DBName = "rma_portal"; //Connect to Database $Link = mysql_connect ($Host, $User, $Password); //RMA info Vars $RMADate = $_POST['RMADate']; $RMANumber = $_POST['RMANumber']; //Customer Info Vars $CustomerID = $_POST['CustomerID']; $CustomerName = $_POST['CustomerName']; //Device Info Vars $DevicePhone = $_POST['DevicePhone']; $DeviceType = $_POST['DeviceType']; $DeviceModel = $_POST['DeviceModel']; $DeviceColor = $_POST['DeviceColor']; $DeviceIMEI = $_POST['DeviceIMEI']; $DescDefect = $_POST['DescDefect']; //Troubleshooting Vars $ResetDevice = isset ($_POST['Troubleshooting']['ResetDevice']) ? 'Y' : 'N'; $SoftwareReload = isset ($_POST['Troubleshooting']['SoftwareReload']) ? 'Y' : 'N'; $WipeDevice = isset ($_POST['Troubleshooting']['WipeDevice']) ? 'Y' : 'N'; $TroubOther = isset ($_POST['Troubleshooting']['TroubOther']) ? 'Y' : 'N'; $TroubNotes = $_POST['TroubNotes']; //Shipping Info Vars $ShipAttention = $_POST['ShipAttention']; $ShipPhone = $_POST['CustomerPhone']; $ShipEmail = $_POST['CustomerEmail']; $ShipStreet = $_POST['ShipStreet']; $ShipAddinfo = $_POST['ShipAddinfo']; $ShipCity = $_POST['ShipCity']; $ShipProv = $_POST['ShipProv']; $ShipPCode = $_POST['ShipPCode']; $ShipAddNotes = $_POST['ShipAddNotes']; // Collects data from rma_contact table $contactqry = mysql_query("SELECT * FROM rma_contact WHERE Cust_Name = '$ShipAttention' AND Cust_Email = '$ShipEmail'") or die(mysql_error()); // puts the "rma_contact" info into the $contactinfo array if found $contactinfo = mysql_fetch_assoc($contactqry); if(!$contactqry){ $Query2 = "INSERT into $rma_devices values (NULL, '$ShipAttention', '$ShipPhone', '$ShipEmail', '$ShipStreet', '$ShipAddinfo', '$ShipCity', '$ShipProv', '$ShipPCode', '$ShipAddNotes')"; //Get the generated ID for Contact_ID $Gen_Contact_ID = mysql_insert_id(); $Query = "INSERT into $rma_devices values ('$RMANumber', '$CustomerID', '$RMADate', '$DevicePhone', '$DeviceType', '$DeviceModel', '$DeviceIMEI', '$DeviceColor', '$DescDefect', '$ResetDevice', '$SoftwareReload', '$WipeDevice', '$TroubNotes', '$Gen_Contact_ID')"; } else{ //Set the Contact_ID to the existsing one $Gen_Contact_ID = $contactinfo ['Contact_ID']; $Query = "INSERT into $rma_devices values ('$RMANumber', '$CustomerID', '$RMADate', '$DevicePhone', '$DeviceType', '$DeviceModel', '$DeviceIMEI', '$DeviceColor', '$DescDefect', '$ResetDevice', '$SoftwareReload', '$WipeDevice', '$TroubNotes', '$Gen_Contact_ID')"; } if (!$link = mysql_connect('localhost', 'root', 'escrma')) { echo 'Could not connect to mysql'; exit; } if (!mysql_select_db('rma_portal', $link)) { echo 'Could not select database'; exit; } print ("The Query is:<BR>$Query<P>\n"); if (mysql_db_query ($DBName, $Query, $Link)) { print ("The RMA form has been saved to the ESC database<br>\n"); } else {print ("There was a problem saving the RMA form to the database<br>Please contact ESC\n"); } mysql_close ($Link); Any help with this code would be appreciated. Link to comment https://forums.phpfreaks.com/topic/192667-no-database-selected-error/ Share on other sites More sharing options...
SchweppesAle Posted February 19, 2010 Share Posted February 19, 2010 you need to select the database using mysql_select_db() before running this query $contactqry = mysql_query("SELECT * FROM rma_contact WHERE Cust_Name = '$ShipAttention' AND Cust_Email = '$ShipEmail'") or die(mysql_error()); update: Also, make sure that you escape those variables before plugging them into any query. Link to comment https://forums.phpfreaks.com/topic/192667-no-database-selected-error/#findComment-1014992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.