My php and Msql problems
-
Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:
$query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;
while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) { $found2 = '1'; $userid2 = $result2\['id'\]; }
echo $userid2;
-
Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:
$query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;
while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) { $found2 = '1'; $userid2 = $result2\['id'\]; }
echo $userid2;
Try changing your query to:
$query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username='$username';") ;
I also think you need to SELECT the username as well, since that is what you are comparing:
$query2 = MYSQL_QUERY("SELECT userid,username FROM users WHERE username='$username';") ;
-
Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:
$query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;
while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) { $found2 = '1'; $userid2 = $result2\['id'\]; }
echo $userid2;
-
Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:
$query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;
while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) { $found2 = '1'; $userid2 = $result2\['id'\]; }
echo $userid2;
I debug sql queries by these methods... 1) echo the sql to a browser so I can test in the Mysql Query Browser to make sure that all variables are set as expected and the query is good. I also include page, line # and the mysql error message in the die command. So if any query is bad you will know where and what and why (<--most of the time). example:
$sql = "select uid from users where uname='".$user_name."'";
$rst = mysql_query($sql) or die("
PG: ".__FILE__."
LN: ".__LINE__."
ER: ".mysql_error()."
Q: ".$sql."
");Note: I usually do this as a function call inside the die so I can set a value for local debug and a live production messages. This is because the above information should be used for the developer and not something a user should ever see. Users should have a simple error message if you can not recover from the error in code. 2) if your code crashes out after the mysql_query, then find out what you query is returning...exactly. example:
That should give you more info. Also keep in mind that if you develope on windows and move to linux you will see some error with the case of table and column names make sure you check that. Windows can be lax on case, while linux is not.
Chris J www.redash.org