etmurphy Posted May 14, 2015 Share Posted May 14, 2015 i'm recieving error 79 and 81 <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } // *** Redirect if username exists $MM_flag="MM_insert"; if (isset($_POST[$MM_flag])) { $MM_dupKeyRedirect="Register.php"; $loginUsername = $_POST['Username']; $LoginRS__query = sprintf("SELECT Username FROM users WHERE Username=%s", GetSQLValueString($loginUsername, "text")); mysql_select_db($database_localhost, $localhost); $LoginRS=mysql_query($LoginRS__query, $localhost) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); //if there is a row in the database, the username was found - can not add the requested username if($loginFoundUser){ $MM_qsChar = "?"; //append the username to the redirect page if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&"; $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername; header ("Location: $MM_dupKeyRedirect"); exit; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "Registerform")) { $insertSQL = sprintf("INSERT INTO users (Firstname, Lastname, Email, Username, Password) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['Firstname'], "text"), GetSQLValueString($_POST['Lastname'], "text"), GetSQLValueString($_POST['Email'], "text"), GetSQLValueString($_POST['Username'], "text"), GetSQLValueString($_POST['Password'], "text")); mysql_select_db($database_localhost, $localhost); $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error()); $insertGoTo = "Login.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_localhost, $localhost); $query_register = "SELECT * FROM users"; $register = mysqli_query($query_register, $localhost) or die(mysqli_error()); $row_register = mysql_fetch_assoc($register); $totalRows_register = mysql_num_rows($register); ?> Link to comment https://forums.phpfreaks.com/topic/296312-solution-mysql_query-expects-parameter-2-to-be-resource-object-given-in-cwampwwwregisterphp-on-line-81/ Share on other sites More sharing options...
etmurphy Posted May 14, 2015 Author Share Posted May 14, 2015 the error start from mysql_select_db($database_localhost, $localhost);$query_register = "SELECT * FROM users";$register = mysqli_query($query_register, $localhost) or die(mysqli_error());$row_register = mysql_fetch_assoc($register);$totalRows_register = mysql_num_rows($register); Link to comment https://forums.phpfreaks.com/topic/296312-solution-mysql_query-expects-parameter-2-to-be-resource-object-given-in-cwampwwwregisterphp-on-line-81/#findComment-1511826 Share on other sites More sharing options...
Barand Posted May 14, 2015 Share Posted May 14, 2015 You can't mix mysql_ functions and mysqli_ functions, Use one or the other and not mysql_. Link to comment https://forums.phpfreaks.com/topic/296312-solution-mysql_query-expects-parameter-2-to-be-resource-object-given-in-cwampwwwregisterphp-on-line-81/#findComment-1511833 Share on other sites More sharing options...
etmurphy Posted May 14, 2015 Author Share Posted May 14, 2015 BUT I'VE use only mysqli but still the same Link to comment https://forums.phpfreaks.com/topic/296312-solution-mysql_query-expects-parameter-2-to-be-resource-object-given-in-cwampwwwregisterphp-on-line-81/#findComment-1511853 Share on other sites More sharing options...
Barand Posted May 14, 2015 Share Posted May 14, 2015 $register = mysqli_query($query_register, $localhost) or die(mysqli_error()); // query params in wrong order $row_register = mysql_fetch_assoc($register); // NOT mysqli You have mixture in the above lines and in other lines in your code. To use mysqli_ you must have a mysqli connection Link to comment https://forums.phpfreaks.com/topic/296312-solution-mysql_query-expects-parameter-2-to-be-resource-object-given-in-cwampwwwregisterphp-on-line-81/#findComment-1511855 Share on other sites More sharing options...
etmurphy Posted May 14, 2015 Author Share Posted May 14, 2015 i wil still try more because, when i change it, i still recieve this "mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\Register.php on line 79" Link to comment https://forums.phpfreaks.com/topic/296312-solution-mysql_query-expects-parameter-2-to-be-resource-object-given-in-cwampwwwregisterphp-on-line-81/#findComment-1511859 Share on other sites More sharing options...
Ch0cu3r Posted May 14, 2015 Share Posted May 14, 2015 You can not just rename the mysql_ functions to mysqli_ as they are completely different. You should be looking at php.net/mysqli for the correct usage of these functions. For what its worth your better of deleting the code generated by Dreamweaver and just writing the code yourself, with a lot few lines of code. Link to comment https://forums.phpfreaks.com/topic/296312-solution-mysql_query-expects-parameter-2-to-be-resource-object-given-in-cwampwwwregisterphp-on-line-81/#findComment-1511862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.