Akkari Posted June 12, 2010 Share Posted June 12, 2010 Hi there everyone. Thanks for taking the time to take a look at this. Basically what I'm trying to do is make a simple script that allows users to enter a URL, expiry time and view limit and then get a mydomain.com/links/get.php?id=AUTOLINKID. That loads their specific URL and expires in time. This is my first attempt to use mysql. So in short, it's kinda a very very basic URL expiry service...lol. So here's the PHP page that gives me all the trouble: <?php // Establish database connection mysql_connect("localhost", "db", "pass") or die(mysql_error()); mysql_select_db("akkari_links") or die(mysql_error()); // If there is no link ID, that saved us a lot of effort; Kick'em out! if (!@$_GET['id']) die ('No download ID supplied!'); $dl_id = mysql_real_escape_string($_GET['id']); // Get the database row that corresponds to the link ID. $result = mysql_query("SELECT * FROM expire WHERE id='$dl_id'") or die(mysql_error()); // No comment $array = mysql_fetch_array($result) or die(mysql_error()); // Otherwise, there is an id and FOR NOW, we'll assume it's valid. if ($array['expires'] > time() && $array['viewcount'] < $array['viewcap']){ // Looks a little compicated, but really just fetching the URL using iframes that's all...lol. $array['path'] = $path; echo "<!DOCTYPE html> <html> <head> <meta name=\"robots\" content=\"noindex\"> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> </head> <body> <div id=\"root\"> <iframe src=\"$path\"> Your browser does not support inline frames. </iframe> </div> <style> @charset \"utf-8\"; body { margin: 0px; padding: 0px; } /* iframe's parent node */ div#root { position: fixed; width: 100%; height: 100%; } /* iframe itself */ div#root > iframe { display: block; width: 100%; height: 100%; border: none; } </style> </body> </html>"; // Increase view count by one. $array['viewcount'] = $viewcount; $viewcount++; // Now store new value in database. $array['viewcount'] = $viewcount; mysql_query("UPDATE expire SET viewcount='$viewcount' WHERE id='$dl_id'") or die(mysql_error()); } else{ // Time limit or view cap exceeded, throw 'em out. echo $array['errormessage']; } mysql_close(); ?> Now problems time: 1. When you visit get.php?id=VALIDID, nothing happens. Just a white screen. I wish there was some kind of error 2. the viewcount never gets incremented in the database for some reason. Expected questions: iframe code? Haven't written it myself but worked perfectly well for me in other scripts so I just copied it. Why not use header function? I don't the real URL to stay hidden. Header will just make a redirect. And anyway, I tried replacing iframe code with header() and it still throws a white page at me . If you have another solution to this, please point it out! I thought it may also be helpful to state that the whole code executes successfully. Tried to echo "done!"; at the end of the file and it echoed. Thank you very much for the support! Quote Link to comment https://forums.phpfreaks.com/topic/204587-my-first-script-using-mysql-frustrated/ Share on other sites More sharing options...
Akkari Posted June 15, 2010 Author Share Posted June 15, 2010 *bump* This was posted in the weekend and probably nobody saw it. Sorry for the bump, was just hoping that someone may be able to help out. Quote Link to comment https://forums.phpfreaks.com/topic/204587-my-first-script-using-mysql-frustrated/#findComment-1072498 Share on other sites More sharing options...
DavidAM Posted June 15, 2010 Share Posted June 15, 2010 First, to get any error messages, add these two lines of code to the very top of your scripts error_reporting(E_ALL); ini_set('display_errors', '1'); This line of code looks like it is backwards: $array['path'] = $path; // Shouldn't that be $path = $array['path']; This is way too complicated (and partially backwards as well) // Increase view count by one. $array['viewcount'] = $viewcount; // SHOULDN'T THIS BE TURNED AROUND? $viewcount++; // Now store new value in database. $array['viewcount'] = $viewcount; mysql_query("UPDATE expire SET viewcount='$viewcount' WHERE id='$dl_id'") or die(mysql_error()); You can simplify and correct that with: // Increase view count by one. $viewcount = ++$array['viewcount']; mysql_query("UPDATE expire SET viewcount='$viewcount' WHERE id='$dl_id'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/204587-my-first-script-using-mysql-frustrated/#findComment-1072505 Share on other sites More sharing options...
vbnullchar Posted June 15, 2010 Share Posted June 15, 2010 try to put error_reporting(E_ALL); on top of your script then post the errors here Quote Link to comment https://forums.phpfreaks.com/topic/204587-my-first-script-using-mysql-frustrated/#findComment-1072506 Share on other sites More sharing options...
KevinM1 Posted June 15, 2010 Share Posted June 15, 2010 Yeah, you have your assignment statements backwards. Remember: you're putting the value of the right operand in the left operand. Also, using the '@' symbol with $_GET to squelch errors only to use it in a conditional to catch an error is ass backwards logic. Simply use isset. Quote Link to comment https://forums.phpfreaks.com/topic/204587-my-first-script-using-mysql-frustrated/#findComment-1072511 Share on other sites More sharing options...
Akkari Posted June 15, 2010 Author Share Posted June 15, 2010 Hey thanks a lot everyone. Just changing the "backwards" statements did the trick. So indeed it was the weekend then, the reason for this lol, I'm embarrassed. Everything else is fine and of course, the script threw no errors at me at all so I just couldn't figure out what was going on. Again, thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/204587-my-first-script-using-mysql-frustrated/#findComment-1072515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.