Page 4 of 5
Posted: Thu Nov 30, 2006 4:40 pm
by boo_lolly
i've got the event_dates to work, somewhat. before the event dates would get deleted no matter what i did. now, IF i change them using the drop down menus, it's saved. but if i don't change them, they get deleted.
Code: Select all
//if event dates changed, replace the variable value
if(isset($_POST['event_month2'])){
$event_month = $_POST['event_month2'];
}if(isset($_POST['event_day2'])){
$event_day = $_POST['event_day2'];
}if(isset($_POST['event_year2'])){
$event_year = $_POST['event_year2'];
}else{
$event_month = $_POST['event_month'];
$event_day = $_POST['event_day'];
$event_year = $_POST['event_year'];
}
can't figure it out. the address stuff still isn't working, but it's not getting deleted either. gonna try and figure this one out before i attempt the address issue.
Posted: Thu Nov 30, 2006 4:52 pm
by Luke
Here it is again with comments to help you understand...
Code: Select all
<?php
/**
* Range just takes a low number and a high number and returns an array
* so range(1, 4) would return an array like [1,2,3,4]
*/
$days = range(1, 31); // Create an array with 1-31 as elements
/**
* This is called the ternary operator... it's the same as doing this:
* if(isset($_POST['day']))
* {
* $selected_day = (integer) $_POST['day'];
* }
* else
* {
* $selected_day = null;
* }
*
* (integer) $_POST['day'] --> this is called "type casting"
* all it does is basically say to php that I want whatever is in $_POST['day'], but convert it to an integer if it isn't already
*/
$selected_day = isset($_POST['day']) ? (integer) $_POST['day'] : null;
// This should be obvious
echo "<select name=\"days\">\n";
echo " <option value=\"\"> - Select One - </option>";
// Loop through the array that has 31 values in it to get the 31 days
foreach($days as $day)
{
// Another ternary operation... basically "if the user selected this day, set it to selected"
$selected = ($selected_day == $day) ? 'selected="selected"' : '';
echo " <option value=\"" . $day . "\" " . $selected . ">" . $day . "</option>\n";
}
echo "</select>\n";
?>
Posted: Thu Nov 30, 2006 5:06 pm
by boo_lolly
thanks A LOT ninja!!! you da man!!! btw i got the event dates to work perfectly.... the problem was my $_POST['event_stuff'] had no value. i tried to write = $row['event_stuff']; but that didn't work. so i just added a hidden input field with the right name and value ($row) and it worked! right on, man. right on. =)
and throughout the process i changed up the code a little bit. now it looks like.
Code: Select all
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'];
}
Posted: Thu Nov 30, 2006 5:39 pm
by Luke
Nice chance to try out that ternary operator (although some people don't like it... personally I love it).
Code: Select all
$event_month = ($_POST['event_month2'] != NULL) ? $_POST['event_month2'] : $_POST['event_month'];
$event_day = ($_POST['event_day2'] != NULL) ? $_POST['event_day2'] : $_POST['event_day'];
$event_year = ($_POST['event_year2'] != NULL) ? $_POST['event_year2'] : $_POST['event_year'];
Posted: Thu Nov 30, 2006 5:53 pm
by John Cartwright
might want to use isset() to avoid notices
Code: Select all
$event_month = (isset($_POST['event_month2'])) ? $_POST['event_month2'] : $_POST['event_month'];
Posted: Thu Nov 30, 2006 5:55 pm
by Luke
good call Jcart... I didn't even pay attention to the expression being evaluated...

Posted: Thu Nov 30, 2006 9:55 pm
by boo_lolly
thanks a lot jcart. that should be a quick fix. thank you all so much for your time. you guys have really helped me take a leap today towards php. it was awesome. peace.
Posted: Fri Dec 01, 2006 9:28 am
by boo_lolly
everything works perfectly... except for a couple of 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 everything except the street address field, then clicks save... when it is redirected back to editCouple.php, it prints all the address information, except it leaves out the street name. so, i guess as the variable responsible for the street address is being evaluated, when it reaches a whitespace, it stops printing... so '1234 Copperfield Dr.' becomes '1234'. however, the information is STILL in the database correctly, it's just an issue with printing. i think it has to do with the HTML input field... i'm not sure how to take care of that one.
this is before i've made the changes from != NULL to if(isset()). however i don't think that's going to fix anything.
Posted: Fri Dec 01, 2006 9:43 am
by boo_lolly
i changed the != NULL to if(isset()) and it screwed EVERYTHING up... i have no idea why... i thought they're practically the same statements... but it just deleted a whole lot of information like that...
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?
Posted: Fri Dec 01, 2006 10:24 am
by boo_lolly
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?
Posted: Fri Dec 01, 2006 10:30 am
by RobertGonzalez
Can you do us a favor? When you have a bunch of updates to make in a thread, can you edit your last post and append your updates to it rather than replying to yourself? This keeps you out of the 'bump' soup and doesn't look so much like you are having a conversation with yourself

.
Ok, post your code again. Post your form, your form processing, everything relevant to what your problem is. A complete code sample makes it a lot easier for us to see what PHP is seeing.
Posted: Fri Dec 01, 2006 10:41 am
by boo_lolly
hahaha, i apologize everah =). sincerely. thank you for your understanding... here's the code...
Code: Select all
//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("localhost", "apache", "nopass");
if(!$db){
echo "Error: Could not connect to the database. Please try again later.";
exit;
}
mysql_select_db("registry_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($POST_['status'] != NULL){
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>
<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>
<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
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>
and the next one
Code: Select all
//redirect.php
<?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("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', 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;
?>
the problem is, my input fields (in editCouple.php) are getting truncated before they are processed in the sql query (in redirect.php) at the first sight of whitespace. so, i'll enter "1234 SomeStreet Dr." in the address field. then when i click save, it prints the information... "1234 SomeStreet Dr." perfectly. but let's say now i want to add something into the Name input field, and nothing else. i do, and click save... now the address will print "1234"... and the change has been made to the database... so, i don't know what's going on... it's like this for every input field.
would i do a string manipulation? or somehow alter my sql query to only contain variables inside it. i have no idea how i'd do that, i don't even know if that's the way to fix this issue...
Posted: Fri Dec 01, 2006 11:05 am
by Luke
[offtopic]
You should enclose your html attributes in quotes
Code: Select all
echo "<form action=\"redirect.php?ID=". $row['uID'] ."\" method=\"post\">\n";
I also through a newline character in at the end, because it makes your html cleaner when you view source
[/offtopic]
Posted: Fri Dec 01, 2006 11:06 am
by boo_lolly
thanks ninja =), that's useful information. i don't know why it's givin me this problem, tho. this is what i've been attempting, but it's still the same...
Code: Select all
list($num_add, $street_add) = split(' ', $ship_add);
$newstring = $num_add ." ". $street_add;
$_POST['ship_add'] = $newstring;
Posted: Fri Dec 01, 2006 11:20 am
by Luke
feyd made me realize in your other thread... that's what is causing all your fields to only show up to the first whitespace... you need to quote your attributes. It's not optional.