spires Posted July 5, 2007 Share Posted July 5, 2007 Hi Thanks for reading. I'm having a problem with an update command. I have used these hundreds of time and have not come across this before. What i'm trying to do is split test a landing page. So, Page 'A' shows then page 'B' then 'A' then 'B' and so on. The way that I am doing this, is by updating the database, Spage = 1 then 2 then 1 then 2 and so on. It then redirecting the user to the alternate page. For some reason the update command will not work when i insert the header command. here is the web address: http://www.your-adsense-secrets.com THIS DOES WORK, BUT DOES NOT REDIRECT include('dbconnect.php'); $query2 = "SELECT * FROM split WHERE id='1'"; $result2 = mysql_query($query2) or die ("query 1 failed"); $count2 = mysql_num_rows($result2); $row2 = mysql_fetch_array($result2); $Spage = $row2['Spage']; if($Spage=='1'){ $split = mysql_query("UPDATE split SET Spage = '2' WHERE id ='1' LIMIT 1 ") or die (mysql_error()); }else{ } THIS DOES NOT UPDATE THE DATABASE include('dbconnect.php'); $query2 = "SELECT * FROM split WHERE id='1'"; $result2 = mysql_query($query2) or die ("query 1 failed"); $count2 = mysql_num_rows($result2); $row2 = mysql_fetch_array($result2); $Spage = $row2['Spage']; if($Spage=='1'){ $split = mysql_query("UPDATE split SET Spage = '2' WHERE id ='1' LIMIT 1 ") or die (mysql_error()); }else{ header('Location: index2.php'); } Any Ideas please Thanks Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 5, 2007 Share Posted July 5, 2007 try this. afther all that remove that silly limit from update ok, that should be on a select statement. <?php include("dbconnect.php"); $query2 = "SELECT * FROM split WHERE id='1' LIMIT 1"; << limit added $result2 = mysql_query($query2) or die ("query 1 failed"); $count2 = mysql_num_rows($result2); while($x=mysql_fetch_assoc($result2)){ if($x['Spage']==1){ $split = "UPDATE `split` SET `Spage` = '2' WHERE `id` ='1' "; $result_split=mysql_query($split) or die ("mysql_error()"); }else{ header("Location: index2.php"); } } ?> Quote Link to comment Share on other sites More sharing options...
spires Posted July 5, 2007 Author Share Posted July 5, 2007 Hi redarrow Thanks for your help. But, it did not work. I'm now echoing $split, which is being displayed on the screen. if($Spage==1){ $split = "UPDATE split SET Spage = '2' WHERE id ='1' LIMIT 1 "; $result_split=mysql_query($split) or die ("mysql_error()"); echo $split; }else{ header("Location: index2.php"); } This also means that $result_split should have updated. Any more ideas please. Thanks again Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 5, 2007 Share Posted July 5, 2007 <?php include("dbconnect.php"); $id=addslasles($_POST['id']); $page=addslashes($_POST['page']); $query2 = "SELECT * FROM split WHERE id='1'"; $result2 = mysql_query($query2) or die ("mysql_error()"); while($x=mysql_fetch_assoc($result2)){ if($x['Spage']>0){ $split = "UPDATE `split` SET `Spage`= '2' WHERE`id`='1' "; $result_split=mysql_query($split) or die ("mysql_error()"); }else{ header("Location: index2.php"); } } ?> <?php include("dbconnect.php"); $id=addslasles($_POST['id']); $page=addslashes($_POST['page']); $query2 = "SELECT * FROM split WHERE id='1'"; $result2 = mysql_query($query2) or die ("mysql_error()"); if(mysql_num_rows($result2)>0){ $split = "UPDATE `split` SET `Spage`= '2' WHERE`id`='1' "; $result_split=mysql_query($split) or die ("mysql_error()"); }else{ header("Location: index2.php"); } } ?> Quote Link to comment Share on other sites More sharing options...
spires Posted July 5, 2007 Author Share Posted July 5, 2007 Thanks That is now working, However, it only works every now and then? If you keep refreshing the page it will eventually work. http://www.your-adsense-secrets.com/index2.php Do you know why it doesn't work every time? Anyway, Thanks you very much for your help. Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 5, 2007 Share Posted July 5, 2007 you need to set the number field that holds the number 1 to a int ok. Quote Link to comment 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.