divx Posted July 1, 2007 Share Posted July 1, 2007 Anyone have any ideas why this is not works: Im trying to check the database to see if the url exist (in the db) before writting over it mysql_connect("correctip", "correctUsename", "Correctpass") or die(mysql_error()); mysql_select_db("correcttable") or die(mysql_error()); $URLdata = mysql_query("SELECT LT_URL FROM lt_Users")or die(mysql_error()); // the querry $DUP = FALSE; // need to check if $_POST['LT_URLBox'] already exist, if does, dont update ($DUP = True) CheckURLExists(); if ($DUP == FALSE){ $result48= mysql_query("UPDATE lt_Users SET LT_URL='$lturlBox' WHERE lt_Name ='$nom' AND lt_Pss='$ps'"); } FUNCTION CheckURLExists() { while( $URLinfo = mysql_fetch_array( $URLdata ) ){ if (strtolower($URLinfo['LT_URL']) == strtolower($lturlBox)){$DUP = TRUE;} } Return $DUP; } It seems to write over the url regardless of it already being present in the db Quote Link to comment Share on other sites More sharing options...
no_one Posted July 1, 2007 Share Posted July 1, 2007 If you know the url, you'd be better off selecting from the db only that url (I'm guessing on the where, since I don't know the exact structure of your table) And then check too see if any results were found. <?php if ( isset($_POST['LT_URLBox']) ) { $url = $_POST['LT_URLBox']; $urldata = mysql_query("Select lt_url from lt_users where lt_url='$url'"); if ( mysql_num_rows($urldata) ) { // it found something - } else { // not in the database } } ?> Unless I'm not understanding what you want.. ? ??? Quote Link to comment Share on other sites More sharing options...
divx Posted July 1, 2007 Author Share Posted July 1, 2007 The user puts the data in for the url, then this needs to be checked against the databse to see if it exist before updating. You should never put users entries direct into an sql command, (just one way to avoid Javascript injection attacks) . Its not really what i want either, that would modify all users which do not have a match for the url. I want to check all the users urls before updating for one user Quote Link to comment Share on other sites More sharing options...
no_one Posted July 1, 2007 Share Posted July 1, 2007 It was an example, so I didn't want to clutter it with security and what not, that's up to you. The select would (or should) select all users w/ that url, so it's similar to getting every user and looping through them all. Also, it wouldn't modify any users, I didn't put in any db modifying code, just selecting code. clear? Anyone else correct me if I'm wrong, I'm tired.. Quote Link to comment 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.