Solved

PHP Not Working

Posted on 2011-03-18
4
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

749 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