Page 1 of 1

Help with php

Posted: Thu Sep 03, 2009 10:35 pm
by unknown1
I have created a script for my listing site and this script does is asks user to add a line of code to his/her site to verify that they are the owner of the sites...

Code: Select all

<?php
session_start(); 
include("config.php");
 
$sql_site = ("SELECT * FROM sit_details_tmp WHERE `email` = '$_SESSION[EMAIL]' ");
$site_con = mysql_query($sql_site, $conn) or die(mysql_error());
$numrows = mysql_num_rows($site_con);
 
if($numrows > 0){
while($row = mysql_fetch_array($site_con))
{
    
$partnersURL="$row[Url]";
$htmlString=file_get_contents($partnersURL);
$var_code = "$row[ver_code]";
 
if (eregi($var_code, $htmlString)) {
 
$ver_update=("UPDATE `sit_details_tmp` SET `id_verification` = '2' WHERE `email` = '".$_SESSION[EMAIL]."'") or die(mysql_error());
if (!mysql_query($ver_update,$conn))
  {
  die('Error: ' . mysql_error());
  }
 
echo '<script language=javascript>';
echo 'alert("Validation code was found! \n Your site has been successfully verified.");'; 
echo '</script>';
echo '<SCRIPT language="JavaScript">
<!--
window.location="my_account.php";
//-->
</SCRIPT>
';
}else{
    echo"$var_code";
echo '<script language=javascript>';
echo 'alert("Validation code was not found! \n Please make sure you have entered the correct \n validation code and that its on the index page of your site.");';
echo '</script>';
echo '<SCRIPT language="JavaScript">
<!--
window.location="my_account.php";
//-->
</SCRIPT>
';
}
}
}else{
echo"User not logged.";
}
?>
The script is working fine with one big flaw.
Say a user goes to verify the code put on her/her sites they add the code to one site but not the other and hit verify...
the script will update all sites as verified and not just the site that actually has the code.

I assume the problem is in the line

$ver_update=("UPDATE `sit_details_tmp` SET `id_verification` = '2' WHERE `email` = '".$_SESSION[EMAIL]."'") or die(mysql_error());

but I can't think of another way to write it so that it only updates the site that has the verification code.

If anyone has an idea of how I could fix this it sure would be appreciated.

Thanks in advance!!

Re: Help with php

Posted: Sat Sep 05, 2009 11:02 pm
by Robert07
I suggest you add a unique id (or even the unique URL) in your sit_details_tmp table which identifies each website that a specific user is responsible for. Then you can add that URL or id specification to your where clause and only validate one website at a time.
Regards,
Robert