Hybride Posted August 31, 2007 Share Posted August 31, 2007 I know, it's sad, but I can't figure it out for the life of me. The update works if you comment out the insert statement; if you comment out the update, the insert statement works. If you combine both, then only update works. I know it's with the if/else (or the actual placement/naming of the query), but I can't figure out where to place it. <input type="hidden" name="submitted" value="TRUE" /> <div align="center"><input type="submit" name="submit" value="Submit" /> <? ob_start(); session_start(); include ('./marketing/includes/post.php'); $date = date('m.d.Y'); if (isset($_POST['submitted'])) { //Handle form if(empty($_POST['name'])) { echo '<br /><i>Please insert an artist name. </i>'; } require('./includes/dbconnect.php'); // This will search the database for a name at the current date // If date is the same as the date in the database (ie: previous insert query), it will update that query // Otherwise, it will go on to insert a new row $m = date("m"); // Month value $de = date("d"); //today's date $y = date("Y"); // Year value $curdate = date('Y-m-d', mktime(0,0,0,$m,($de),$y)); $queryup = "SELECT * FROM manual WHERE name='$name'"; $resultup = mysql_query($queryup) OR die(mysql_error()); if($resultup) { while($rows = mysql_fetch_array($resultup, MYSQL_ASSOC)){ if ($curdate == $rows['date']) { // These are the updated results $physup = $rows['physalbum'] + $physalbum; $digup = $rows['digalbum'] + $digalbum; $upquery1 = "UPDATE manual SET physalbum='$physup', digalbum='$digalbum' WHERE name='$name' AND date='$curdate'"; $upresult1 = mysql_query($upquery1) OR die(mysql_error()); if($upresult1) { echo '<br /><b>Successfully updated.</b>'; } else { echo 'Failed.'; } } } } else { $query = "INSERT INTO manual (name, label, avg, physalbum, digalbum, digsinsales, date) VALUES ('$name','$label','$avg', '$physalbum','$digalbum',NOW())"; $result = mysql_query($query) or die(mysql_error()); $mid = mysql_insert_id(); if($result) { //if ran ok echo '<br />Data added successfully.'; } else { echo '<br />Your submission cound not be processed.' . mysql_error(); $querydel = "DELETE FROM manual WHERE mid=$mid"; mysql_query($querydel); } } } ?> </fieldset></div> </form> <? } else { print ' '; } // If the user is not an admin, it will show up blank (no insert menu). ?> <? include './includes/rightmenu.php'; include './includes/bottommenu.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/ Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 Do you mean commenting out the entire part of the if statement, or just the query line? What is not working about it? Is mysql returning an error? Quote Link to comment https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/#findComment-338638 Share on other sites More sharing options...
soycharliente Posted August 31, 2007 Share Posted August 31, 2007 I find that you have too many closing braces. Take out the last closing } before your < /fieldset > tag near the bottom. Quote Link to comment https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/#findComment-338683 Share on other sites More sharing options...
Hybride Posted August 31, 2007 Author Share Posted August 31, 2007 If I remove that last }, it returns an $end error. What the script does is check against the current date: if the date is the same day, then it updates the database; if it's not the same day, it inserts a new row into the db. And what I meant about not working is that the two queries do not work together -> if I press "submit" and have the update query commented, it updates the database; if I have the insert query commented out, the query updates the db; however, if I try to put them both together, then only the update query works, not insert a new row into the db, even if the query submitted is a new name/date. Quote Link to comment https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/#findComment-338723 Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 Since it is an if-else statement, they shouldn't ever work at the same time. Are you saying that commenting out a part of the code that isn't even being executed is making the other code run? Quote Link to comment https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/#findComment-338735 Share on other sites More sharing options...
Hybride Posted August 31, 2007 Author Share Posted August 31, 2007 Yeah That's the weird thing about it. Is there some other way I can fix it? I'd prefer using the same submit button, but am all ears for any other idea. Quote Link to comment https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/#findComment-338772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.