Solved

PHP Not Working

Posted on 2011-03-18
4
223 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
Comment Utility
Is there any more to this page? That currently looks fine as it is.
0
 
LVL 15

Author Comment

by:wantabe2
Comment Utility
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 82

Accepted Solution

by:
Dave Baldwin earned 250 total points
Comment Utility
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
Comment Utility
$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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now