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
https://forums.phpfreaks.com/topic/57970-checking-database-before-updating/
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.. ?  ???

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

 

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

Archived

This topic is now archived and is closed to further replies.

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