Jump to content

UPDATE will not work?


spires

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/58513-update-will-not-work/
Share on other sites

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");
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/58513-update-will-not-work/#findComment-290239
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/58513-update-will-not-work/#findComment-290243
Share on other sites

<?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");
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/58513-update-will-not-work/#findComment-290244
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58513-update-will-not-work/#findComment-290249
Share on other sites

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.