unknown1 Posted September 3, 2009 Share Posted September 3, 2009 Hello all, I need a little help if someone has some extra time. I have created a script that checks for a line of code on an external url and if it's on the page give a success message and if not found give error alert... The issue I'm having is if the person have more than one site they want to verify and they have already verified the code on one... when they go to verify the other sites it updates automatic because it was found on the first one. because I use $row and it can contain more than one url I assume my script is only checking the 1st url on the list and not the others... anyone have any ideas??? Thanks in advance!!! session_start(); include("config.php"); $sql_site = ("SELECT * FROM table 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)) { $sql_cat = "SELECT Cate_Details FROM `category` WHERE idCategory = '". $row["idCategory"]."'"; $rec_cat = mysql_query($sql_cat) or die(mysql_error()); $rs_cat = mysql_fetch_array($rec_cat); $sql_stat = "SELECT staDetails FROM `site_status` WHERE idStatus = '". $row["idStatus"]."'"; $rec_stat = mysql_query($sql_stat) or die(mysql_error()); $rs_stat = mysql_fetch_array($rec_stat); $row[url] = $row[url]++; $partnersURL="$row[url]"; $htmlString=file_get_contents($partnersURL); if (eregi('46546546546', $htmlString)) { $ver_update=("UPDATE `table` 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 '<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."; } Quote Link to comment https://forums.phpfreaks.com/topic/172913-solved-php-help/ Share on other sites More sharing options...
perrij3 Posted September 3, 2009 Share Posted September 3, 2009 What if you used WHILE for the URLs? That would allow you to cycle through all the URLs. Something like: <?php while($row = mysql_fetch_assoc($sql_stat)) { ?> some code here <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/172913-solved-php-help/#findComment-911318 Share on other sites More sharing options...
unknown1 Posted September 3, 2009 Author Share Posted September 3, 2009 Good plan. Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/172913-solved-php-help/#findComment-911325 Share on other sites More sharing options...
unknown1 Posted September 3, 2009 Author Share Posted September 3, 2009 Ok I have figured out that the script is cycling through the urls fine but updating all sites to verified and not just the one site that is actually has been verified. I assume that it's in the following code but not sure how else I could write it cause the matching rows in this and the user table are email so that is the only way I can think of to do it. $ver_update=("UPDATE `table` SET `id_verification` = '2' WHERE `email` = '".$_SESSION[email]."'") or die(mysql_error()); This is the full script... it works fine but validates all url when it should only update the ones that contain the validation code. <?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."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/172913-solved-php-help/#findComment-911988 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 does that table not have a primary key? just use the primary key when updating. IE if (eregi($var_code, $htmlString)) { $ver_update=("UPDATE `sit_details_tmp` SET `id_verification` = '2' WHERE `id` = '".row['id']."'") or die(mysql_error()); if (!mysql_query($ver_update,$conn)) { die('Error: ' . mysql_error()); } by the way you need to encase associative array keys with single quotes $array[key];//wrong $array['key'];//right Quote Link to comment https://forums.phpfreaks.com/topic/172913-solved-php-help/#findComment-911995 Share on other sites More sharing options...
unknown1 Posted September 3, 2009 Author Share Posted September 3, 2009 I do have a primary key but in table one it's site_id and in the user table it's id_user and the id fields don't match so I'm not sure I follow on how to do what your saying. I used WHERE `email` = '$_SESSION[email]' cause when the user registers I register the session value email and that way I know the information I'm pulling belongs to the right user. The only matching fields I have between the two table is email Quote Link to comment https://forums.phpfreaks.com/topic/172913-solved-php-help/#findComment-912017 Share on other sites More sharing options...
unknown1 Posted September 3, 2009 Author Share Posted September 3, 2009 does that table not have a primary key? just use the primary key when updating. IE if (eregi($var_code, $htmlString)) { $ver_update=("UPDATE `sit_details_tmp` SET `id_verification` = '2' WHERE `id` = '".row['id']."'") or die(mysql_error()); if (!mysql_query($ver_update,$conn)) { die('Error: ' . mysql_error()); } by the way you need to encase associative array keys with single quotes $array[key];//wrong $array['key'];//right Ok I have figured out that the script is cycling through the urls fine but updating all sites to verified and not just the one site that is actually has been verified. *** not all sites in table but all site for that user*** I want it to work so that it checks all the users urls one by one and updates one by one now with ver_update=("UPDATE `sit_details_tmp` SET `id_verification` = '2' WHERE `id` = '".row['id']."'") or die(mysql_error()); it's updating all listings that the user has at once and not only the one that have the verification code. If you understand already... sorry. I just assume you figured the issues was updating all urls in the table and not just the users ones. Anyways, if you have any ideas it sure would help. Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/172913-solved-php-help/#findComment-912024 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.