Solved

PHP Not Working

Posted on 2011-03-18
4
231 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

691 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