Jump to content

Recommended Posts

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';
?>

Link to comment
https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/67457-simple-ifelse-problem/#findComment-338723
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.