View Full Version : Mysql Query not executing inside dynamic image

02-02-2007, 05:13 AM
So i have an image that checks to see if your on AIM or not. In the process I log your aim username, the time that the image was viewed, and your myspace friendid. For whatever reason my mysql is not working, the code looks fine to me and all the tables/columns exist. Can anyone tell me what Im doing wrong?

$link = mysql_connect("","myspace_aim","*****");
$sql = "SELECT * FROM users WHERE mid = '$ref' OR ausr = '$username'";
$result = mysql_query($sql);
$now = time();
$sql = "INSERT INTO `users` ( `mid` , `ausr` , `when` ) VALUES ('$ref', '$username', '$now')";
$ref and $username are defined earlier in the script.

02-02-2007, 01:04 PM
i don't realy understand a lott of your code. most of it is pointless (closing the connection at the end, storing the linkID without using it, running a select without using the result, storing the time in a variable) + you don't have any debugging included. Below code would result in exactly the same as yours, but is easier to debug

$link = mysql_connect("","myspace_aim","*****") or die('Unable to connect to db-server');
mysql_select_db("myspace_aim") or die('Unable to select db');
$sql = "INSERT INTO `users` ( `mid` , `ausr` , `when` ) VALUES ('$ref', '$username', '". time() ."')";
mysql_query($sql, $link) or die('Unable to execute query: '. $sql . '<br />Error:' . mysql_error());

maybe try it like that. + it might help to be a bit more informative then 'my mysql is not working'