PDA

View Full Version : variable values not working across a break


songboy
10-27-2009, 11:35 PM
I've decided to split a form into three sections. I'm using a switch and hidden values to create script directions. The problem I'm having is that the values for an array don't seem to be crossing over the switch break. The result is my database won't update.
The login works and this leads to a form which has been populated with previous data grabbed from the database. I've also started a session. Now there's a break and the user gets to change the data in the form. However, when it's posted no update occurs. My tests seem to show that the values for the associative array are not crossing over the break even though I've repeated the values on the other side of the break.
Have a look at the troublesome area.

$query = "SELECT * FROM writer_page_details WHERE user_name='$logname'";
$result3 = mysqli_query($cxn, $query) or die ("Couldn't execute query.");
$num3 = mysqli_num_rows($result3);
if($num3 > 0)
{

$resultarr = mysqli_fetch_assoc($result3);
$user_name = $resultarr["user_name"];
$writing_first_name = $resultarr["writing_first_name"];
$writing_second_name = $resultarr["writing_second_name"];
$main_genre = $resultarr["main_genre"];
$user_website_name = $resultarr["user_website_name"];
$country_of_residence = $resultarr["country_of_residence"];
$blog_text = $resultarr["blog_text"];
include("add_the_songsa_update.php");
}
elseif($num3 == 0)
{
include("add_the_songsa.php");
}

//up to here everything works fine//

break;
case "first_form":

$user_name = @$resultarr["user_name"];
$writing_first_name = @$resultarr["writing_first_name"];
$writing_second_name = @$resultarr["writing_second_name"];
$main_genre = @$resultarr["main_genre"];
$user_website_name = @$resultarr["user_website_name"];
$country_of_residence = @$resultarr["country_of_residence"];
$blog_text = @$resultarr["blog_text"];

@$user_namea = $user_name;
@$writing_first_namea = $_POST["writing_first_name"];
@$writing_second_namea = $_POST["writing_second_name"];
@$main_genrea = $_POST["main_genre"];
@$user_website_namea = $_POST["user_website_name"];
@$country_of_residencea = $_POST["country_of_residence"];
@$blog_texta = $_POST["blog_text"];


if
(@$writing_first_name == $writing_first_namea)

{

include("add_the_songsb.php");
exit();
}

elseif ($writing_first_name !== @$writing_first_namea)
{

$query = sprintf("UPDATE writer_page_details SET writing_first_name='$writing_first_namea' WHERE user_name='$user_name'");
$result = mysqli_query($cxn,$query) or die(mysqli_error($cxn));

include("add_the_songsb.php");
exit();
}

It looks to me as if $resultarr isn't registering on the other side of the break. My echo tests seem to prove this. The problem is that I need those values for the comparison with the posted values to take place otherwise the update won't take place.

Any advice or solutions would be much appreciated.
Thanks - Songboy