PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i've found that there is series or order where sql commands must be executed. so i changed my WHERE statement to the place it's supposed to be... but it STILL gives me an error! You have an error in your SQL syntax near 'groomLname = '', event_month = '', event_day = '' event_year = '' WHERE uID = I2' at line 1
here's my code...
alright, thanks, ninja... i spent like 30 minutes looking at my code and didn't realize i was missing a couple of commas. thank you. but, to no surprise, i'm given another error.... Unknown column 'I2ZMwC61kdJuzEBTqJi2AQYZJK8qU' in 'where clause'
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?
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.
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 actually $_POST the new values... right now it thinks that the new values are NULL... so, yet again my friends, what could i possibly be doing wrong???
<?php
$brideFname = $_POST['brideFname'];
$brideLname = $_POST['brideLname'];
$groomFname = $_POST['groomFname'];
$groomLname = $_POST['groomLname'];
// What exactly are these little beauties doing?
$_POST['event_month2'];
$_POST['event_day2'];
$_POST['event_year2'];
// End sarcastic question
$event_month = $_POST['event_month'];
$event_day = $_POST['event_day'];
$event_year = $_POST['event_year'];
// Just remove these if you are not going to use them
#$_POST['editID'];
#$_POST['ship_add'];
#$_POST['ship_city'];
#$_POST['ship_state'];
#$_POST['ship_zip'];
// Lets clean this out a bit... Also, you should default these vars because
// if they fail the if then they will be considered unitialized
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'];
}
// Removed error suppression and cleaned up error checking
if (!$db = mysql_connect("localhost", "apache", "nopass"))
die('Error: Could not connect to the database server. Please try again later: ' . mysql_error());
}
if (!mysql_select_db("registry_DB", $db)) {
die('Error: Could not connect to the database. Please try again later: ' . mysql_error());
}
$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'] ."'"; // What is $row['uID'] and where is this set?
mysql_query($sql) or die(mysql_error());
mysql_close($db);
ok, the event_....2 variables. when the input fields are pre-populated, by retrieving the data from the sql table, the value of the date is echoed. however, if the admin wishes to change it, they have a drop-down HTML menu for the day, month, and year. THIS is event_day2/month2/year2. as you'll notice in my code, IF these variables (each one) is not empty, replace it the original value of the variable, then, store the new variable value into the database.
as far as removing the commented variables... i do plan on using them, but at the moment they are causing more harm than good. when i try to pre-populate an input field with ship_add... it will only print the value until it gets to a whitespace... so, for instance, in the database the ship_add may be '1234 Copperfield Dr.'... but when i try to put it in an input field it comes out '1234'... so i'll figure that out later, but for now, i've got bigger problems to deal with...
$row['uID'] stands for unique ID. it's a necessary randomly generated unique ID given to each entry in the database table. $row[''] is being printed from a previous while() statement. anyway, it works... when i debug this stuff, it echoes correctly. so it's not that. but it is imperative so the sql command can have an identifier. a location of the row to replace, retrieve, update, or delete the data. and right now, it's finding the right row, but it thinks that all the new values are NULL, and then it replaces the correct row with the wrong information...
<?php
// These are all values from the form
// This assumes cleanliness and value (no empties)
$brideFname = $_POST['brideFname'];
$brideLname = $_POST['brideLname'];
$groomFname = $_POST['groomFname'];
$groomLname = $_POST['groomLname'];
// Setting this here for use later
$uID = $row['uID'];
// Lets clean this out a bit... Also, you should default these vars because
// if they fail the if then they will be considered unitialized
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'];
}
// Removed error suppression and cleaned up error checking
if (!$db = mysql_connect("localhost", "apache", "nopass")) {
die('Error: Could not connect to the database server. Please try again later: ' . mysql_error());
}
if (!mysql_select_db("registry_DB", $db)) {
die('Error: Could not connect to the database. Please try again later: ' . mysql_error());
}
// This assumes that all the data from the form was not empty!
// Also, if the event data parts or uID are numbers, remove the quotes
$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'";
if (!mysql_query($sql) || !mysql_affected_rows()) {
die(mysql_error());
}
mysql_close($db);
?>
i'm a little confused. if the $_POST variables come from the form, then why is it replacing them with NULL values? furthermore, why isn't it replacing it with the NEW edited values?
the event_day/month/year values AND the uID are all VARCHARs.
Looking at what you just posted, there are a host of things that are going to make that page not work. The most prominent is the use of the $row array, mainly because it is not set anywhere in the page. A var_dump() of row should show you what is in the var.
At this point, you are going to need to be able to provide the script with the information for $row. From there it should be a snap. Show the code that sets $row so we can move from there.
i changed the value= in the input fields from $row[''] to $_POST['']. and it still didn't work. it does the same thing. but i think i figured it out.... i don't have the names in the form....