Forum Moderators: coopster
Unknown column 'ho234' in 'where clause'
this is my code:
<?php require_once('../Connections/conn_users.php');?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="registration_failed.php";
$loginUsername = $_POST['user_name'];
$LoginRS__query = sprintf("SELECT `user_name` FROM `users` WHERE `user_name`=`%s`", GetSQLValueString($loginUsername, "-1"));
mysql_select_db($database_conn_users, $conn_users);
$LoginRS=mysql_query($LoginRS__query, $conn_users) 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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO `users` (`name`, `lastname`, `user_name`, `password`, `address`, `city`, `state`, `zipcode`, `email`, `phone`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['lastname'], "text"),
GetSQLValueString($_POST['user_name'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['state'], "text"),
GetSQLValueString($_POST['zipcode'], "int"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['phone'], "text"));
mysql_select_db($database_conn_users, $conn_users);
$Result1 = mysql_query($insertSQL, $conn_users) or die(mysql_error());
$insertGoTo = "exito.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?'))? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
any idea what a heck did I do wrong?
That error is coming from MySQL, therefore there is a problem with this query:
$LoginRS__query = sprintf("SELECT `user_name` FROM `users` WHERE `user_name`=`%s`", GetSQLValueString($loginUsername, "-1"));
Try something like this:
$LoginRS__query = "SELECT `user_name` FROM `users` WHERE `user_name` = '".GetSQLValueString($loginUsername, "-1")."'";
`%s` should be '%s' in your query. Like this:
$LoginRS__query = sprintf("SELECT `user_name` FROM `users` WHERE `user_name`='%s'", GetSQLValueString($loginUsername, "-1"));
The ticks are used when the value refers to a column in MySql. Since there is no column labeled ho234, you get an error. Likely what you wanted was to see if the user ho234 existed in the column user_name, ie. user_name = 'ho234'.