Solved

PHP Not Working

Posted on 2011-03-18
4
226 Views
Last Modified: 2012-05-11
I have this bit of code in a script & it is not working correctly. I do get the email but I am NOT getting the confirmation message "Your information has been updated successfully."....any ideas why this is not working?
$query = "UPDATE psrinfo SET pacts='$pt', fname='$fn', lname='$ln', status='$st', location='$loc', office='$off', sent_date='$sd', oth_date='$oth', assgn_date='$ad', interv_date='$iv', due_rev='$rv', due_suspo='$sus', due_clerk='$clk', due_attn='$atn', due_jude='$jdg'  WHERE fid=$id";
	$result = @mysql_query ($query); // Run the query.
		

			if (mysql_affected_rows() == 1)
	echo '<p>Your information has been updated successfully.</p>';
else
	echo '<p class="error">There was a problem updating your information.</p>';

		
		
		
				
$EmailAddress = 'email add@yahoo.com';	
$Message = "Someone has edited the information below.\n \nPACTS No : ${_REQUEST['pacts']}\nLocation : ${_REQUEST['location']}\nFirst Name : ${_REQUEST['fname']}\nLast Name : ${_REQUEST['lname']} \nStatus : ${_REQUEST['status']}";	
$Subject  = "Please Change";
$Headers = "From: PODDS@domain.org \n"; 


 	if (mail($EmailAddress, $Subject, $Message, $Headers))

Open in new window

0
Comment
Question by:wantabe2
4 Comments
 
LVL 3

Expert Comment

by:CombatGold1
ID: 35166685
Is there any more to this page? That currently looks fine as it is.
0
 
LVL 15

Author Comment

by:wantabe2
ID: 35166735
Yes, I think I pinpointed the issue but still can't figure it out... I // out lines 43-49 & I now get the error "There was a problem updating your information." but the information does not get submitted to the database...
<?php # edit_dqa.php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","uname","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("psrflow", $con);

if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { 
	$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted.
	$id = $_POST['id'];
} else { // No valid ID, kill the script.
	echo '<h1 id="mainhead">Page Error</h1>
	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
	include ('./includes/footer.html'); 
	exit();
}
		
		$query = "UPDATE psrinfo SET fname='$fn', lname='$ln', location='$loc' WHERE fid=$id";
		$result = @mysql_query ($query); // Run the query.
				
				
					if (mysql_affected_rows() == 1)
	echo '<p>Your information has been updated successfully.</p>';
else
	echo '<p class="error">There was a problem updating your information.</p>';		

	
$EmailAddress = 'myemail@yahoo.com';	
$Message = "Someone has edited the information below. Location : ${_REQUEST['location']}\nFirst Name : ${_REQUEST['fname']}\nLast Name : ${_REQUEST['lname']}";	
$Subject  = "Please Change";
$Headers = "From: anotheremail@yahoo.com \n"; 

if (mail($EmailAddress, $Subject, $Message, $Headers)) {



//$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
//if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) {
//$url = substr ($url, 0, -1);
//}
//$url ='/flow/index.html'; 

//header("Location: $url");

exit();
		
	} else { // Report the errors.
	
		echo '<h1 id="mainhead">Error!</h1>
		<p class="error">The following error(s) occurred:<br />';
		foreach ($errors as $msg) { // Print each error.
			echo " - $msg<br />\n";
		}
		echo '</p><p>Please try again.</p><p><br /></p>';
		
	} // End of if (empty($errors)) IF.

} // End of submit conditional.

// Retrieve the user's information.
$query = "SELECT pacts, fname, lname, location WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.

	$row = mysql_fetch_array ($result, MYSQL_NUM);
		
?>	

<?php

echo '<form action="edit_dqa.php" method="post">
<fieldset><legend><h1> You are editing a record!</h1></legend>

<b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="'.$row[1].'" /><br />
<b>Last Name:</b> <br><input type="text" name="lname" size="15" maxlength="30" value="'.$row[2].'" /><br />
<b>Location: </b><br><input type="text" name="location" size="15" maxlength="30" value="'.$row[5].'" /><br>
br>
<br>
</fieldset>

<div align="left"><input type="submit" name="submit" value="Submit" /></div>

<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' . $id . '" />
</form>';

} else { // Not a valid user ID.
	echo '<h1 id="mainhead">Page Error</h1>
	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
}

mysql_close(); // Close the database connection.

?>

Open in new window

0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 35167032
Then you need to put this in place of "$result = @mysql_query ($query);" so you see what errors you're getting.  The '@' suppresses error messages.
// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

Open in new window

0
 
LVL 2

Assisted Solution

by:tonykachappilly
tonykachappilly earned 250 total points
ID: 35167541
$query = "UPDATE psrinfo SET fname='$fn', lname='$ln', location='$loc' WHERE fid=".$id.;

Open in new window

try replacing your query with this
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now