PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
Your function returns the value of the internal variable $DUP, which has no relation to the global variable $DUP. You should be setting the global variable $DUP to the value returned from your function checkURLExists(). This is a matter of "scope" of variables. In general, avoid naming global variables and local variables the same.
<?php
mysql_connect("correctip", "correctUsename", "Correctpass") or die(mysql_error());
// you need to select the database here, not the table..
mysql_select_db("correcttable") or die(mysql_error());
// i am lazy
function esc($foo)
{
return mysql_real_escape_string($foo);
}
// pulling all the records? - NO!
#$URLdata = mysql_query("SELECT LT_URL FROM lt_Users")or die(mysql_error()); // the querry
// I am assuming $lturlBox is already set..
$resource_id = mysql_query("SELECT count(*) as total FROM lt_Users WHERE LOWER(LT_URL) = '" . esc(strtolower($lturlBox)) . "'") or die(mysql_error());
$result = mysql_fetch_assoc($resource_id);
if ($result['total'] < 1)
{
// need to escape your strings..
// and you probably only want to update 1 record, so I added a limit..
$result48= mysql_query("UPDATE lt_Users SET LT_URL = '" . esc($lturlBox) . "' WHERE lt_Name = '" . esc($nom) . "' AND lt_Pss = '" . esc($ps) . "' LIMIT 1");
}