Jump to content

Checking database, before updating


divx

Recommended Posts

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

Link to comment
Share on other sites

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.. ?  ???

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.