Using Dreamweaver, i am tryin to append my recordset depending on the username but i am getting the following error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%user1%'' at line 1 What i want to be able to do is if there is a user logged in to display their info. I only got the error when i added the following line of code that is bold. Can someone help please <?php require_once('Connections/PropertyConnect.php'); ?> <?php if (!isset($_SESSION)) { session_start(); } 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") ? mysql_real_escape_string($theValue) : mysql_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; } } mysql_select_db($database_PropertyConnect, $PropertyConnect); $query_rsTestSim = "SELECT information.custId, information.Username FROM information"; if (isset($_POST['InfoID'])) { $Info = mysql_real_escape_string($_POST['InfoID']); $query_rsTestSim.= "WHERE custId LIKE '%$Info%'"; } else if(isset($_SESSION['MM_Username'])){ $logUser = mysql_real_escape_string($_SESSION['MM_Username']); $query_rsTestSim.= "WHERE Username LIKE '%$logUser%'"; }$rsTestSim = mysql_query($query_rsTestSim, $PropertyConnect) or die(mysql_error()); $row_rsTestSim = mysql_fetch_assoc($rsTestSim); $totalRows_rsTestSim = mysql_num_rows($rsTestSim); echo $query_rsTestSim; echo $totalRows_rsTestSim; ?>
am not sure what is your problem but Why using like with certain values ?, if user is logged in so the values stored in the session should be correct then use 'WHERE `field` = '$value' instead of LIKE
For each of the MySQL run statements, add : or die(mysql_error()); PHP: Just append it after you run the query, and it will tell you if there is any issues in your SQL
Using Dreamweaver, i am tryin to append my recordset depending on the username but i am getting the following error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%user1%'' at line 1
I would recommend that you print out the SQL query via your function as it would be parsed via PHP. So have it get your SQL, but instead of running it, make it a string, and print it to your browser. This way, you can see if it's being modified by your hosting in any way, and if it appears fine, test it via PHPMyAdmin, on your hosting, or local environment. If all else fails, generate your SQL via PHPMyAdmin, and adjust it in your function.
It also looks like there are no spaces in your SQL either... $query_rsTestSim = "SELECT information.custId, information.Username FROM information"; if (isset($_POST['InfoID'])) { $Info = mysql_real_escape_string($_POST['InfoID']); $query_rsTestSim.= "WHERE custId LIKE '%$Info%'"; } else if(isset($_SESSION['MM_Username'])){ $logUser = mysql_real_escape_string($_SESSION['MM_Username']); $query_rsTestSim.= "WHERE Username LIKE '%$logUser%'"; }$rsTestSim = mysql_query($query_rsTestSim, $PropertyConnect) or die(mysql_error()); $row_rsTestSim = mysql_fetch_assoc($rsTestSim); $totalRows_rsTestSim = mysql_num_rows($rsTestSim); So it seems like this will print out SELECT information.custId, information.Username FROM informationWHERE custId LIKE '%$Info%' but just double check it first by printing it to your browser as I suggested