Jump to content

I feel dumb (update help)


dropfaith

Recommended Posts

heres  the code im sure im missing something easy as hell (long day)

 

<?php
session_start( ); //bored of this function yet?
if(!isset($_SESSION["username"]))
{
header('Location: index.php');
}
else
{
	include("header.php");
	// validate text input fields
	$Client = mysql_escape_string(trim(htmlentities($_GET['Client'])));
	$Date = mysql_real_escape_string(trim(stripslashes($_POST['Date'])));
	$Website = mysql_real_escape_string(trim(stripslashes($_POST['Website'])));
	$Testimonial = mysql_real_escape_string(trim(stripslashes($_POST['Testimonial'])));
	$loginid = mysql_real_escape_string(trim(stripslashes($_POST['loginid'])));
      // open database connection
	$conn = mysql_connect(HOST, DBUSER, PASS) or  die('Could not connect !<br />Please contact the site\'s administrator.');
	$db = mysql_select_db(DB) or  die('Could not connect to database !<br />Please contact the site\'s administrator.');
        // generate and execute query
		$query = "UPDATE testimonial SET Website = '$Website', Date = '$Date', Testimonial = '$Testimonial' WHERE Client = '$Client'";
		$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
			echo $query;
}
?>

 

the echo query is in there to test this and displays

 

UPDATE testimonial SET Website = 'http://www.imagesbytroy.com', Date = 'January 24, 2009', Testimonial = 'test' WHERE Client = 'imagesbytroy'

 

which is exactly right  but when the script runs it just removes all data from all the fields im trying to update

Link to comment
Share on other sites


CREATE TABLE `testimonial` (
  `Client` varchar(250) NOT NULL,
  `Date` varchar(250) NOT NULL,
  `Testimonial` text NOT NULL,
  `Id` int(4) NOT NULL auto_increment,
  `Website` varchar(250) NOT NULL,
  `loginid` int(5) NOT NULL,
  PRIMARY KEY  (`Id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;[code]

i doubt the table structure is needed but who knows

Link to comment
Share on other sites

using the exact query you used worked fine but making it with varibles from a form still fails for the same reason above no errors just erases all data im trying to update

 

i dont understand why its getting the data just fine

 

UPDATE testimonial SET `Website` = 'http://www.imagesbytroy.com', `Date` = 'January 24, 2009', `Testimonial` = 'nestttt' WHERE `Client` = 'imagesbytroy'

 

just clearing out the database values instead of updating

 

form code ust in case

 

					<form onSubmit="stripHTML(this.Name, this.Testimonial, this.Website)" action="edittestimonialscript.php?Client=<?php $Client = mysql_escape_string(trim(htmlentities($_GET['Client']))); echo $Client; ?>" method="POST">

				<?php
include("header.php");
    $u = $_SESSION['username'];
    $uid = $_SESSION['loginid'];
$query = "SELECT * FROM testimonial WHERE loginid = '$uid'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>
				<p>
					<input type="hidden" name="Client" value="<? echo $row->Client; ?>">
					<input type="hidden" name="loginid" value="<? echo $row->loginid; ?>">
				</p>

				<p>
					<label>Website</label>
					<input type="text" name="Website" size="28" value="<? echo $row->Website; ?>">
				</p>
				<p>
					<label>Date</label>
					<input type="text" name="Date" size="28" value="<?php $today = date("F j, Y"); PRINT "$today";?>">
				</p>
				<p>
					<label>Testimonial</label>
					<textarea name="Testimonial" cols="72" rows="20"><? echo $row->Testimonial; ?></textarea>
				</p>
<?
}
}
// if no records present
// display message
else
{
?>
<?
}
// close database connection
mysql_close($connection);
?>	
<input type="Submit" name="submit" value="Add">


				</form>
			</fieldset>

Link to comment
Share on other sites

so you're telling me that the variables are going into the query fine, but still continue to erase things when updating.....odd

 

just for gits and shiggles....

run

echo "<pre>" .  print_r($_GET) . </pre>"

 

Array ( [Client] => imagesbytroy )

 

1

 

 

UPDATE testimonial SET Website = 'http://www.imagesbytroy.com', Date = 'January 24, 2009', Testimonial = 'test' WHERE Client = 'imagesbytroy'

in phpmyadmin works fine

Link to comment
Share on other sites

damn, I guess I meant to say $_REQUEST...not $_GET

Array ( [Client] => imagesbytroy [loginid] => 122 [Website] => http://www.imagesbytroy.com [Date] => January 24, 2009 [Testimonial] => kj [submit] => Add [__utma] => 209552327.3031029602016247300.1232256851.1232256851.1232256851.1 [__utmz] => 209552327.1232256851.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) [phpSESSID] => b1e08b68ddc0e378c6ec21e79d441b62 )

1

Link to comment
Share on other sites

I honestly can't figure out how it's deleting your info.

$_REQUEST looked exactly the way I thought it would....just fine.

 

So why would it work in phpmyadmin and not in your script?  Even though the script...seems flawless

brainstorm in progress.......

 

 

Most likely.....I would put money on it being something really dumb...like, having selected the wrong database or table or something.

Link to comment
Share on other sites

Your browser is requesting your page twice, the first time with the from's post data, the second time without the post data (only the URL that has the Client= parameter), so the data is first updated with the actual data, then it is updated again with empty data.

 

The reason it is being submitted twice is either due to your browser (which browser are you using and have you tried a different one), some javascript in your form submitting it along with the browser submitting it (what is the code for stripHTML()), or some mod_rewrite that is causing the browser to request the page twice (are you doing any url rewriting and if so what.)

 

Two ways to fix - 1) you should be validating all data being put into the query and if it does not contain expected values, output a meaningful user message and don't execute the query, or 2) set a session variable after you have executed the query once on the page and check if that session variable is already set before you execute the query to prevent duplicate (less the data) submissions.

Link to comment
Share on other sites

Your browser is requesting your page twice, the first time with the from's post data, the second time without the post data (only the URL that has the Client= parameter), so the data is first updated with the actual data, then it is updated again with empty data.

 

The reason it is being submitted twice is either due to your browser (which browser are you using and have you tried a different one), some javascript in your form submitting it along with the browser submitting it (what is the code for stripHTML()), or some mod_rewrite that is causing the browser to request the page twice (are you doing any url rewriting and if so what.)

 

Two ways to fix - 1) you should be validating all data being put into the query and if it does not contain expected values, output a meaningful user message and don't execute the query, or 2) set a session variable after you have executed the query once on the page and check if that session variable is already set before you execute the query to prevent duplicate (less the data) submissions.

 

firefox 3.05 i think is the version im on currently

javascript has actually been removed and theres no effect on this script at all still does the same thing

 

no url rewriting at all

Link to comment
Share on other sites

<?php
session_start( ); //bored of this function yet?
if(!isset($_SESSION["username"]))
{
header('Location: index.php');
}
else
// Report all PHP errors
error_reporting(E_ALL);
{
	include("header.php");
	// validate text input fields
	$Client = mysql_escape_string(trim(htmlentities($_GET['Client'])));
	$Date = mysql_real_escape_string(trim(stripslashes($_POST['Date'])));
	$Website = mysql_real_escape_string(trim(stripslashes($_POST['Website'])));
	$Testimonial = mysql_real_escape_string(trim(stripslashes($_POST['Testimonial'])));
	$loginid = mysql_real_escape_string(trim(stripslashes($_POST['loginid'])));


        // generate and execute query
	//$query = "UPDATE testimonial SET Website = 'http://www.imagesbytroy.com', Date = 'January 24, 2009', Testimonial = 'test' WHERE Client = 'imagesbytroy'";

		$query = "UPDATE testimonial SET Website = '$Website', Date = '$Date', Testimonial = '$Testimonial' WHERE Client = '$Client'";
		$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());


}
?>

i cant see it being any of those errors becuase the currently commented out update works fine but the one with varibiables fails

Link to comment
Share on other sites

FF has a known feature (bug in my book) where it requests a page twice when it applies the character encoding that the user has set. I'm going to guess if you try IE that it will work as expected. You need to detect and prevent duplicate submissions in your code on the server so that your code is browser and browser setting independent.

 

You also need an exit; statement after your header() redirect.

Link to comment
Share on other sites

FF has a known feature (bug in my book) where it requests a page twice when it applies the character encoding that the user has set. I'm going to guess if you try IE that it will work as expected. You need to detect and prevent duplicate submissions in your code on the server so that your code is browser and browser setting independent.

 

You also need an exit; statement after your header() redirect.

 

damn it is a firefox issue

 

any quick fix to this ive never had this issue before and have always used only firefox how strange

Link to comment
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.