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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.