Jump to content

header() not redirecting for some reason...


boo_lolly

Recommended Posts

i'm writing a redirect.php page for a CMS. the admin user makes whatever changes they want to certain information in the database, then clicks submit. they are taken to redirect.php which handles all the sql commands depending on what the admin wanted to change. and then they are redirected to another page, depending on the types of changes they made, as well... the header is not working. here's the error:

[b]Warning: Cannot modify header information - headers already sent by (output started at /../../../admin/redirect.php) in /../../../admin/redirect.php on line 41[/b]

[code]
<?php
$uID        = $_POST['editID'];
$sub_opt    = $_POST['sub_opt'];
$brideFname = $_POST['brideFname'];
$brideLname = $_POST['brideLname'];
$groomFname = $_POST['groomFname'];
$groomLname = $_POST['groomLname'];
$ship_add  = $_POST['ship_add'];
$ship_city  = $_POST['ship_city'];
$ship_state = $_POST['ship_state'];
$ship_zip  = $_POST['ship_zip'];
$_POST['event_month'];
$_POST['event_day'];
$_POST['event_year'];

if($_POST['event_month2'] != NULL){
$event_month = $_POST['event_month2'];
}if($_POST['event_day2'] != NULL){
$event_day = $_POST['event_day2'];
}if($_POST['event_year2'] != NULL){
$event_year = $_POST['event_year2'];
}

if($sub_opt == "cancel"){
echo "<CENTER>All changes were cancelled. You are being redirected to Home.</CENTER>";
$redirect = "admin1.php?action=view_all";
}elseif($sub_opt == "save"){
//open connection
//SQL commands
//close connection
echo "<CENTER>Your changes have been saved. You are being redirected to Home.";
$redirect = "admin1.php?action=view_all";
}elseif($sub_opt == "save_reg"){
//open connection
//same SQL commands
//close connection
echo "Your changes have been saved. You are being redirected to Registry.";
$redirect = "updateRegistry.php";
}

header("Location: $redirect");
?>
[/code]
Link to comment
Share on other sites

It will not work because you have echoed something out to the browser. Header has to be the first thing outputed to the browser or you will get an error. I this case I would not use a php redirect but instead a META.
Try this. Replace the xxx with the number of seconds to wait
[code]<?php
$uID        = $_POST['editID'];
$sub_opt    = $_POST['sub_opt'];
$brideFname = $_POST['brideFname'];
$brideLname = $_POST['brideLname'];
$groomFname = $_POST['groomFname'];
$groomLname = $_POST['groomLname'];
$ship_add  = $_POST['ship_add'];
$ship_city  = $_POST['ship_city'];
$ship_state = $_POST['ship_state'];
$ship_zip  = $_POST['ship_zip'];
$_POST['event_month'];
$_POST['event_day'];
$_POST['event_year'];

if($_POST['event_month2'] != NULL){
$event_month = $_POST['event_month2'];
}if($_POST['event_day2'] != NULL){
$event_day = $_POST['event_day2'];
}if($_POST['event_year2'] != NULL){
$event_year = $_POST['event_year2'];
}

if($sub_opt == "cancel"){
echo "<CENTER>All changes were cancelled. You are being redirected to Home.</CENTER>";
$redirect = "admin1.php?action=view_all";
}elseif($sub_opt == "save"){
//open connection
//SQL commands
//close connection
echo "<CENTER>Your changes have been saved. You are being redirected to Home.";
$redirect = "admin1.php?action=view_all";
}elseif($sub_opt == "save_reg"){
//open connection
//same SQL commands
//close connection
echo "Your changes have been saved. You are being redirected to Registry.";
$redirect = "updateRegistry.php";
}
?>
<head>
<META HTTP-EQUIV="Refresh" content="xxx;url=<?=$redirect?>">
</head>[/code]
Link to comment
Share on other sites

it works now... however, i'm not sure why my sql commands aren't being executed on this redirect.php... anybody see anything wrong with the code? it's not bringing me any errors...

[code]
<?php
    $uID        = $_POST['editID'];
    $sub_opt    = $_POST['sub_opt'];
    $brideFname = $_POST['brideFname'];
    $brideLname = $_POST['brideLname'];
    $groomFname = $_POST['groomFname'];
    $groomLname = $_POST['groomLname'];
/**************************************
    $ship_add  = $_POST['ship_add'];
    $ship_city  = $_POST['ship_city'];
    $ship_state = $_POST['ship_state'];
    $ship_zip  = $_POST['ship_zip'];
**************************************/
    $_POST['event_month'];
    $_POST['event_day'];
    $_POST['event_year'];
 
    if($_POST['event_month2'] != NULL){
        $event_month = $_POST['event_month2'];
    }if($_POST['event_day2'] != NULL){
        $event_day = $_POST['event_day2'];
    }if($_POST['event_year2'] != NULL){
        $event_year = $_POST['event_year2'];
    }
 
    if($sub_opt == "cancel"){
        $redirect = "admin1.php?action=view_all";
        header("Location: $redirect");
        echo "<CENTER>All changes were cancelled. You are being redirected to Home.</CENTER>";
    }elseif($sub_opt == "save"){
        @ $db = mysql_connect("yah", "blah", "blah");
        mysql_select_db("my_DB", $db);
        if(!$db){
            echo "Error: Could not connect to the database. Please try again later.";
            exit;
        }
        $sql = "INSERT INTO my_search_table where uID = '". $uID ."' VALUES('NULL', '$brideFname', '$brideLname', ".
            "'$groomFname', '$groomLname', '$event_month', '$event_day', '$event_year', 'NULL', 'NULL', 'NULL', 'NULL'");
        mysql_query($sql);
        mysql_close($db);

        $redirect = "admin1.php?action=view_all";
        header("Location: $redirect");
        echo "<CENTER>Your changes have been saved. You are being redirected to Home.";
    }elseif($sub_opt == "save_reg"){
        @ $db = mysql_connect("yah", "blah", "blah");
        mysql_select_db("my_DB", $db);
        if(!$db){
            echo "Error: Could not connect to the database. Please try again later.";
            exit;
        }
        $sql = "INSERT INTO my_search_table where uID = '$uID' VALUES('NULL', '$brideFname', '$brideLname', ".
            "'$groomFname', '$groomLname', '$event_month', '$event_day', '$event_year'");
        mysql_query($sql);
        mysql_close($db);        $redirect = "updateRegistry.php";
        header("Location: $redirect");
        echo "Your changes have been saved. You are being redirected to Registry.";
        $redirect = "updateRegistry.php";
    }
?>
[/code]
Link to comment
Share on other sites

That META thing.... I've never seen that.  I have been trying to think about how I'm going to make a webpage for the ncaa basketball tournament in march.

I'll have the bracket with all the first round games where the user can pick the winner from each game.... based on their picks for each game I need the page to refresh so that the second round games are populated with the winners they selected. So on for the third, fourth rounds, etc...

Would that META thing work ?
Link to comment
Share on other sites

pushin shuvin pushin me. THERE'S NO LOVE IN FEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAR!!!!!!!!


hey volka, you're right. what i meant to do was UPDATE. not INSERT. good call bud. so how would i do all that insert stuff as an UPDATE command?? this is what i've got so far... but it still gives me the same error...
[code=php:0]
$sql = "UPDATE my_search_table WHERE uID = '". $uID ."' ".
"SET(brideFname, brideLname, groomFname, groomLname, event_month, event_day, event_year)".
" = ('$brideFname', '$brideLname', '$groomFname', '$groomLname', '$event_month', '$event_day', '$event_year')";
mysql_query($sql) or die(mysql_error());
[/code]
Link to comment
Share on other sites

Your double quote after the last NULL  has to go OUTSIDE the close bracket and before the semi-colon

[code]<?php
//LINE 37

$sql = "INSERT INTO my_search_table where uID = '". $uID ."' VALUES('NULL', '$brideFname', '$brideLname', '$groomFname', '$groomLname', '$event_month', '$event_day', '$event_year', 'NULL', 'NULL', 'NULL', 'NULL'");
?>
[/code]

should be

[code]]<?php
//LINE 37

$sql = "INSERT INTO my_search_table where uID = '". $uID ."' VALUES('NULL', '$brideFname', '$brideLname', '$groomFname', '$groomLname', '$event_month', '$event_day', '$event_year', 'NULL', 'NULL', 'NULL', 'NULL')";
?>
[/code]
Link to comment
Share on other sites

i've got ANOTHER problem... for some odd reason, my $_POST[''] commands aren't working. it's weird, they're just not being sent to the next page... i have no idea why. they're being sent the same way all my data has been sent to other pages... but it just won't work for this one... and the worst part about it is that the page that the information is coming from is an admin editing page... when the admin clicks 'SAVE' it takes them to 'redirect.php' which runs all the SQL queries. but the new editions aren't being posted either... it's just taking the same information from before the editions were made to the data....

the first thing i need to do is figure out the syntax error...
[b]You have an error in your SQL syntax near 'WHERE uID = '' SET brideFname = '', brideLname = '', groomFname = '' groomLname ' at line 1[/b]

my SQL command
[code=php:0]
$sql = "UPDATE my_search_table WHERE uID = '". $uID ."' ".
"SET brideFname = '$brideFname', brideLname = '$brideLname', groomFname = '$groomFname' ".
"groomLname = '$groomLname', event_month = '$event_month', event_day = '$event_day' ".
"event_year = '$event_year'";
[/code] what am i doing wrong?
Link to comment
Share on other sites

First of all your where clause is in the wrong place. There is an order to sql statements.

UPDATE xxx SET xxx WHERE xxx
SELECT xxx FROM xxx WHERE xxx GROUP BY xxx ORDER BY xxx
DELETE FROM xxxx WHERE xxx

Just something to keep in mind

Ray
Link to comment
Share on other sites

thanks buddy. i did not know that. but i changed it, alright, thanks, ninja... i spent like 30 minutes looking at my code and didn't realize i was missing a couple of commas as well. thank you. but, to no surprise, i'm given another error....
[b]Unknown column 'I2ZMwC61kdJuzEBTqJi2AQYZJK8qU' in 'where clause'[/b]

uID is the column. I2ZMwC61kdJuzEBTqJi2AQYZJK8qU is used to locate the correct ROW of information in the entire table to update. what's the deal? why is it looking for I2ZMwC61kdJuzEBTqJi2AQYZJK8qU as a column name?

[code]
<?php
$sql = "UPDATE my_search_table ".
"SET brideFname = '$brideFname', brideLname = '$brideLname', groomFname = '$groomFname', ".
    "groomLname = '$groomLname', event_month = '$event_month', event_day = '$event_day', ".
    "event_year = '$event_year' ".
"WHERE uID = I2ZMwC61kdJuzEBTqJi2AQYZJK8qU";
?>
[/code]
Link to comment
Share on other sites

nevermind... i put single quotes around it and now it doesn't give me an error... but it STILL WON'T SAVE THE NEW EDITED INFO!!!!! what could i possibly be doing wrong man!!! here's the code at the top of my page... the editinfo.php page is now set to <form action SELF, but when it does that, it's supposed to $_POST the editions in the input fields, and then replace them, and THEN spit out the new results again in input fields.
[code]
<?php
$brideFname    = $_POST['brideFname'];
$brideLname    = $_POST['brideLname'];
$groomFname    = $_POST['groomFname'];
$groomLname    = $_POST['groomLname'];
$_POST['event_month2'];
$_POST['event_day2'];
$_POST['event_year2'];
$event_month  = $_POST['event_month'];
$event_day    = $_POST['event_day'];
$event_year    = $_POST['event_year'];
#$_POST['editID'];
#$_POST['ship_add'];
#$_POST['ship_city'];
#$_POST['ship_state'];
#$_POST['ship_zip'];

if($_POST['event_month2'] != NULL){
$event_month = $_POST['event_month2'];
}if($_POST['event_day2'] != NULL){
$event_day = $_POST['event_day2'];
}if($_POST['event_year2'] != NULL){
$event_year = $_POST['event_year2'];
}


@ $db = mysql_connect("localhost", "apache", "nopass");
mysql_select_db("registry_DB", $db);
if(!$db){
echo "Error: Could not connect to the database. Please try again later.";
exit;
}
$sql = "UPDATE my_search_table ".
"SET brideFname = '$brideFname', brideLname = '$brideLname', groomFname = '$groomFname', ".
    "groomLname = '$groomLname', event_month = '$event_month', event_day = '$event_day', ".
    "event_year = '$event_year' ".
"WHERE uID = '". $row['uID'] ."'";
mysql_query($sql) or die(mysql_error());
mysql_close($db);
[/code]
it kinda works. it's actually replacing the data in the SQL table now FINALLY! except, it's replacing it with NULL values... i'll be in editinfo.php, with all the nice pre-populated input fields... i'll make a couple of changes... click submit... and then it brings up input fields with nothing in them. then i check the database, and sure enough... it's replaced it... with nothing. so now, the ONLY problem i have is a problem i've had since the beginning... getting this info to $_POST
Link to comment
Share on other sites

$row[''] is part of a while() function earlier in the script. if i debug and echo the value of $row['uID'], it outputs the correct information, so that leads me to believe that it's not the $row[''] variable. as i said before, the sql query is finding the correct row, and replacing the data in the correct columns that are a part of that row. it locates the sql table row using $uID as an identifier. however, it's replacing data with NULL values.. this must mean there is a problem with my $_POST variables. but i am unable to diagnose the issue any further than that.
Link to comment
Share on other sites

...it's so weird... when i click a link to go to editCouple.php... the input fields are completely blank... all of them. and when i click 'back' on my browser, all the information is there, except somehow, the event_date fields get deleted automatically... then i click editCouple.php again.... and it's got nothing, still... so i'll type in some information... drop the dropdown menu and click a date field. then click save... then all the info is stored and when it reloads it shows.. except the event_date.... then without typing anything.... i'll click save again.... and NOW everything shows, including the event_date.... but then i'll click back to the home screen, and all the new information is stored, except the date.... even tho it showed me, after two clicks, that is was there..... NIGHTMARE on ZEND street....

here's my code...

[code]
<?php
$row['brideFname']    = $_POST['brideFname'];
$row['brideLname']    = $_POST['brideLname'];
$row['groomFname']    = $_POST['groomFname'];
$row['groomLname']    = $_POST['groomLname'];
$_POST['event_month2'];
$_POST['event_day2'];
$_POST['event_year2'];
#$row['event_month']  = $_POST['event_month'];
#$row['event_day']    = $_POST['event_day'];
#$row['event_year']    = $_POST['event_year'];
#$_POST['editID'];
#$_POST['ship_add'];
#$_POST['ship_city'];
#$_POST['ship_state'];
#$_POST['ship_zip'];

    $uID = $row['uID'];
   
if($_POST['event_month2'] != NULL){
$event_month = $_POST['event_month2'];
}if($_POST['event_day2'] != NULL){
$event_day = $_POST['event_day2'];
}if($_POST['event_year2'] != NULL){
$event_year = $_POST['event_year2'];
}

@ $db = mysql_connect("localhost", "apache", "nopass");
mysql_select_db("registry_DB", $db);
if(!$db){
echo "Error: Could not connect to the database. Please try again later.";
exit;
}
$sql = "UPDATE my_search_table ".
"SET brideFname = '$brideFname', brideLname = '$brideLname', groomFname = '$groomFname', ".
    "groomLname = '$groomLname', event_month = '$event_month', event_day = '$event_day', ".
    "event_year = '$event_year' ".
"WHERE uID = '$uID'";
mysql_query($sql) or die(mysql_error());
mysql_close($db);

echo "<TABLE><TR><TD>";
echo "<form action=editCouple.php?editID=". $row['uID'] ." method=post>";
echo "<B>Full name:</B> ". $row['brideFname'] ." ". $row['brideLname'] ."<br />";
echo "<B>Bride's First Name:</B> <input type=text name=brideFname value=". $row['brideFname'] ."><br />";
echo "<B>Bride's Last Name:</B> <input type=text name=brideLname value=". $row['brideLname'] ."><br /><br />";

echo "<B>Full name:</B> ". $row['groomFname'] ." ". $row['groomLname'] ."<br />";
echo "<B>Groom's First Name:</B> <input type=text name=groomFname value=". $row['groomFname'] ."><br />";
echo "<B>Groom's Last Name:</B> <input type=text name=groomLname value=". $row['groomLname'] ."><br /><br />";

echo "<B>Event date:</B> ". $row['event_month'] ."/". $row['event_day'] ."/". $row['event_year'] ."<br /><br />";
?>
Change the date using the drop down menus below:<BR>
<SELECT NAME="event_month2">
<OPTION VALUE="">select a month
<OPTION VALUE="01">January
<OPTION VALUE="02">February
<OPTION VALUE="03">March
<OPTION VALUE="04">April
<OPTION VALUE="05">May
<OPTION VALUE="06">June
<OPTION VALUE="07">July
<OPTION VALUE="08">August
<OPTION VALUE="09">September
<OPTION VALUE="10">October
<OPTION VALUE="11">November
<OPTION VALUE="12">December
</SELECT>
&nbsp;
<SELECT NAME="event_day2">
<OPTION VALUE="">select a day
<OPTION VALUE="01">01
<OPTION VALUE="02">02
<OPTION VALUE="03">03
<OPTION VALUE="04">04
<OPTION VALUE="05">05
<OPTION VALUE="06">06
<OPTION VALUE="07">07
<OPTION VALUE="08">08
<OPTION VALUE="09">09
<OPTION VALUE="10">10
<OPTION VALUE="11">11
<OPTION VALUE="12">12
<OPTION VALUE="13">13
<OPTION VALUE="14">14
<OPTION VALUE="15">15
<OPTION VALUE="16">16
<OPTION VALUE="17">17
<OPTION VALUE="18">18
<OPTION VALUE="19">19
<OPTION VALUE="20">20
<OPTION VALUE="21">21
<OPTION VALUE="22">22
<OPTION VALUE="23">23
<OPTION VALUE="24">24
<OPTION VALUE="25">25
<OPTION VALUE="26">26
<OPTION VALUE="27">27
<OPTION VALUE="28">28
<OPTION VALUE="29">29
<OPTION VALUE="30">30
<OPTION VALUE="31">31
</SELECT>
&nbsp;
<SELECT NAME="event_year2">
<OPTION VALUE="">select a year
<OPTION VALUE="2002">2002
<OPTION VALUE="2003">2003
<OPTION VALUE="2004">2004
<OPTION VALUE="2005">2005
<OPTION VALUE="2006">2006
<OPTION VALUE="2007">2007
<OPTION VALUE="2008">2008
<OPTION VALUE="2009">2009
<OPTION VALUE="2010">2010
</SELECT></TD></TR>
<TR><TD>
<?php
/*********************DEBUG************************
echo $row['ship_add'] ."<br />";
echo "<B>Address:</B> <input type=text name=ship_add value=". $row['ship_add'] ."></br />";
echo "<B>City:</B> <input type=text name=ship_city  value=". $row['ship_city'] ."></br />";
echo "<B>State:</B> <input type=text name=ship_state value=". $row['ship_state'] ."></br />";
echo "<B>Zip Code:</B> <input type=text name=ship_zip value=". $row['ship_zip'] ."></br /><br />";
**************************************************/
?>
<TABLE width=400><TR>
<BR>

<?php
$_POST['brideFname'];
$_POST['brideLname'];
$_POST['groomFname'];
$_POST['groomLname'];
$_POST['ship_add'];
$_POST['ship_city'];
$_POST['ship_state'];
$_POST['ship_zip'];

$_POST['event_month2'];
$_POST['event_day2'];
$_POST['event_year2'];
$_POST['event_month'];
$_POST['event_day'];
$_POST['event_year'];
$_POST['editID'];
?>

<TD align=center valign=left><input type=submit value="Save"></form></TD>
<TD align=center valign=right>
<form method=post action=updateRegistry.php?regID=<?php echo $uID; ?>><input type=submit value="Continue to Registry >>">
</form>
</TD></TR></TABLE>

</TD></TR></TABLE>
[/code]
Link to comment
Share on other sites

I got no idea what you are doing here. I think you are confusing everyone with alot of the code you have here.

Do you just have a simple form to fill out and add to a database??
You want to also check to see if the information has been entered in already??

Post your entire code with the name of the page above it so I can see where things are coming from.

Ray
Link to comment
Share on other sites

ok, i've rebuilt both pages...
[code]
//editCouple.php
<HTML>
<HEAD><TITLE>Edit Couple</TITLE></HEAD>

<BODY>
<CENTER>
<?php $location = "<B>Edit Couple</B>"; ?>

<TABLE BORDER="1" WIDTH="850" CELLPADDING="20">
<TR>
<TD WIDTH="%50" ALIGN="center"><H1>The Very Thing Gifts</H1>
<?php echo $location; ?>
<form method="POST" action="admin1.php?action=view_all">
<input type="SUBMIT" value="View All">
</form>
</TD>
<TD><?php include "admin_search.inc" ?></TD>
</TR>
</TABLE><BR>

<HR WIDTH="300"><BR>

<TABLE WIDTH="750"><TR><TD>

<?php
$status = $_POST['status']; //sent from redirect.php
if(isset($_POST['uID'])){
$uID = $_POST['uID'];
}else{
$uID = $_POST['editID'];    //sent from homepage to populate the correct row of information
}
@ $db = mysql_connect("yah", "blah", "blah");
if(!$db){
echo "Error: Could not connect to the database. Please try again later.";
exit;
}

mysql_select_db("my_DB", $db);

//retrieve info from the database
$sql = mysql_query("SELECT * FROM my_search_table WHERE uID LIKE '%". $editID ."%'") or die(mysql_error());
$row = mysql_fetch_array($sql);

if(isset($POST_['status'])){
echo "<CENTER>". $_POST['status'] ."</CENTER>";
}
//pre-populate input fields with values from the database.
echo "<form action=redirect.php?ID=". $row['uID'] ." method=post>";
echo "<input type=hidden name=ID value=". $row['uID'] .">";
echo "<B>Bride First:</B> <input type=text name=brideFname value=". $row['brideFname'] ."><br />";
echo "<B>Bride Last:</B> <input type=text name=brideLname value=". $row['brideLname'] ."><br />";
echo "<B>Groom First:</B> <input type=text name=groomFname value=". $row['groomFname'] ."><br />";
echo "<B>Groom Last:</B> <input type=text name=groomLname value=". $row['groomLname'] ."><br /><br />";

echo "<B>Event Date:</B> ". $row['event_month'] ."/". $row['event_day'] ."/". $row['event_year'] ."<br />";
echo "<input type=hidden name=event_month value=". $row['event_month'] .">";
echo "<input type=hidden name=event_day value=". $row['event_day'] .">";
echo "<input type=hidden name=event_year value=". $row['event_year'] .">";
echo "<B>Change event date:</B> ";
?>
<SELECT NAME="event_month2">
<OPTION VALUE="">select a month
<OPTION VALUE="01">January
<OPTION VALUE="02">February
<OPTION VALUE="03">March
<OPTION VALUE="04">April
<OPTION VALUE="05">May
<OPTION VALUE="06">June
<OPTION VALUE="07">July
<OPTION VALUE="08">August
<OPTION VALUE="09">September
<OPTION VALUE="10">October
<OPTION VALUE="11">November
<OPTION VALUE="12">December
</SELECT>
&nbsp;
<SELECT NAME="event_day2">
<OPTION VALUE="">select a day
<OPTION VALUE="01">01
<OPTION VALUE="02">02
<OPTION VALUE="03">03
<OPTION VALUE="04">04
<OPTION VALUE="05">05
<OPTION VALUE="06">06
<OPTION VALUE="07">07
<OPTION VALUE="08">08
<OPTION VALUE="09">09
<OPTION VALUE="10">10
<OPTION VALUE="11">11
<OPTION VALUE="12">12
<OPTION VALUE="13">13
<OPTION VALUE="14">14
<OPTION VALUE="15">15
<OPTION VALUE="16">16
<OPTION VALUE="17">17
<OPTION VALUE="18">18
<OPTION VALUE="19">19
<OPTION VALUE="20">20
<OPTION VALUE="21">21
<OPTION VALUE="22">22
<OPTION VALUE="23">23
<OPTION VALUE="24">24
<OPTION VALUE="25">25
<OPTION VALUE="26">26
<OPTION VALUE="27">27
<OPTION VALUE="28">28
<OPTION VALUE="29">29
<OPTION VALUE="30">30
<OPTION VALUE="31">31
</SELECT>
&nbsp;
<SELECT NAME="event_year2">
<OPTION VALUE="">select a year
<OPTION VALUE="2002">2002
<OPTION VALUE="2003">2003
<OPTION VALUE="2004">2004
<OPTION VALUE="2005">2005
<OPTION VALUE="2006">2006
<OPTION VALUE="2007">2007
<OPTION VALUE="2008">2008
<OPTION VALUE="2009">2009
<OPTION VALUE="2010">2010
</SELECT></TD></TR>
<TR><TD>

<?php      //below is where the shipping address prints until it reaches a whitespace (ship_add)
echo "<B>Address:<B> ". $row['ship_add'] .", ". $row['ship_city'] .", ". $row['ship_state'] .", ". $row['ship_zip'] ."<br />";
echo "<input type=hidden name=ship_add value=". $row['ship_add'] .">";
echo "<input type=hidden name=ship_city value=". $row['ship_city'] .">";
echo "<input type=hidden name=ship_state value=". $row['ship_state'] .">";
echo "<input type=hidden name=ship_zip value=". $row['ship_zip'] .">";
echo "<B>Change address information</B><br />";
echo "Street: <input type=text name=ship_add2><br />";
echo "City: <input type=text name=ship_city2><br />";
echo "State: <input type=text name=ship_state2><br />";
echo "Zip Code: <input type=text name=ship_zip2><br />";

$_POST['ID'];
$_POST['brideFname'];
$_POST['brideLname'];
$_POST['groomFname'];
$_POST['groomLname'];
$_POST['ship_add'];
$_POST['ship_city'];
$_POST['ship_state'];
$_POST['ship_zip'];
$_POST['ship_add2'];
$_POST['ship_city2'];
$_POST['ship_state2'];
$_POST['ship_zip2'];
$_POST['event_month'];
$_POST['event_day'];
$_POST['event_year'];
$_POST['event_month2'];
$_POST['event_day2'];
$_POST['event_year2'];
?>
<input type=submit value=Save></form>
</TD></TR></TABLE>

</BODY>
</HTML>
[/code]

and the redirect page...
[code]
<?php
//redirect.php
$ID        = $_POST['ID'];
$brideFname = $_POST['brideFname'];
$brideLname = $_POST['brideLname'];
$groomFname = $_POST['groomFname'];
$groomLname = $_POST['groomLname'];

//if address values changed, replace the variable value
if($_POST['ship_add2'] != NULL){
$ship_add = $_POST['ship_add2'];
}else{
$ship_add = $_POST['ship_add'];
}if($_POST['ship_city2'] != NULL){
$ship_city = $_POST['ship_city2'];
}else{
$ship_city = $_POST['ship_city'];
}if($_POST['ship_state2'] != NULL){
$ship_state = $_POST['ship_state2'];
}else{
$ship_state = $_POST['ship_state'];
}if($_POST['ship_zip2'] != NULL){
$ship_zip = $_POST['ship_zip2'];
}else{
$ship_zip = $_POST['ship_zip'];
}

//if event dates changed, replace the variable value
if($_POST['event_month2'] != NULL){
$event_month = $_POST['event_month2'];
}else{
$event_month = $_POST['event_month'];
}if($_POST['event_day2'] != NULL){
$event_day = $_POST['event_day2'];
}else{
$event_day = $_POST['event_day'];
}if($_POST['event_year2'] != NULL){
$event_year = $_POST['event_year2'];
}else{
$event_year = $_POST['event_year'];
}

@ $db = mysql_connect("yah", "blah", "blah");
mysql_select_db("registry_DB", $db);
if(!$db){
echo "Error: Could not connect to the database. Please try again later.";
exit;
}
$sql = "UPDATE my_search_table ".
"SET brideFname = '$brideFname', brideLname = '$brideLname', groomFname = '$groomFname', ".
    "groomLname = '$groomLname', event_month = '$event_month', event_day = '$event_day', ".
    "event_year = '$event_year', ship_add = '$ship_add', ship_city = '$ship_city', ".
    "ship_state = '$ship_state', ship_zip = '$ship_zip' ".
"WHERE uID = '$ID'";
mysql_query($sql) or die(mysql_error());

if(!mysql_query($sql)){
$status = "<font color=red>Your data has not been stored</font>";
}else{$status = "<font color=green>Your data was successfully stored.</font>";
}

$_POST['status'] = $status;
mysql_close($db);

header("Location: /../../../editCouple.php?editID=". $ID ."");
exit;
?>
[/code]

everything works perfectly... except for a couple of small things...
1) when i wrote the code, i basically wanted it to be dummy-proof. for instance, if the admin wanted to edit the name of the couple, but leave the rest of the input fields blank, and then click save... only the input fields that were changed would be entered. here's the weird thing... if the admin makes some editions, let's say he/she enters information into an input field that has a whitespace in the middle, like the admin enters "Rhode Island" for the state, then clicks save... when it is redirected back to editCouple.php, it prints everything perfectly. but if the admin leaves that input field blank, enters some more information into a different input field, then clicks save... when the page gets reloaded, it prints everything until it gets to a whitespace... so "Rhode Island" will become "Rhode". however, the data in the SQL table still is "Rhode Island". so, i guess, as the variable responsible for the input fields is being evaluated, when it reaches a whitespace, it stops printing... so '1234 Copperfield Dr.' becomes '1234'.

the whitespace problem is prevalent for ALL the input fields. if there's a whitespace in any of the new data, it gets truncated at the beginning of whitespace. i don't know what the deal is. i would REALLY like to get around this without having to make the user enter the address number in one input field, and then the street name in another... but even then, if the street name was more than one word... we'd still have the same problem... there's GOTTA be a way to get around this... any suggestions?
Link to comment
Share on other sites

so, i've checked my database, and the information that's being stored in the SQL table ALSO get's truncated when it reaches a whitespace.... what's the deal with this? i don't recall ever having a problem with this stuff. i believe it may be a simple matter of string manipulation, which i would need some help on. what do you guys think?

i guess i'm looking for a string function(s) that would do the opposite of trim(); correct?
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.