dropfaith Posted January 24, 2009 Share Posted January 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/ Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745188 Share on other sites More sharing options...
Zane Posted January 24, 2009 Share Posted January 24, 2009 Have you tried using backticks UPDATE testimonial SET `Website` = 'http://www.imagesbytroy.com', `Date` = 'January 24, 2009', `Testimonial` = 'test' WHERE `Client` = 'imagesbytroy' Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745191 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745192 Share on other sites More sharing options...
RichardRotterdam Posted January 24, 2009 Share Posted January 24, 2009 shouldn't $conn = mysql_connect(HOST, DBUSER, PASS) or die('Could not connect !<br />Please contact the site\'s administrator.'); be before you use mysql_real_escape_string()? I usually get an error if i don't do that Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745194 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 hrmm odd but no thats actually not needed now that i look into my code a bit more i have the whole connection in header.php just never removed it i guess Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745195 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 hrmm think it could be the comma in the date field?? throwing this all off? Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745196 Share on other sites More sharing options...
Zane Posted January 24, 2009 Share Posted January 24, 2009 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 "" . print_r($_GET) . " Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745197 Share on other sites More sharing options...
RichardRotterdam Posted January 24, 2009 Share Posted January 24, 2009 What happens if you put UPDATE testimonial SET Website = 'http://www.imagesbytroy.com', Date = 'January 24, 2009', Testimonial = 'test' WHERE Client = 'imagesbytroy' in mysql query browser or phpmyadmin Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745198 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745200 Share on other sites More sharing options...
Zane Posted January 24, 2009 Share Posted January 24, 2009 damn, I guess I meant to say $_REQUEST...not $_GET Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745201 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745202 Share on other sites More sharing options...
Zane Posted January 24, 2009 Share Posted January 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745203 Share on other sites More sharing options...
PFMaBiSmAd Posted January 24, 2009 Share Posted January 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745204 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745206 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745207 Share on other sites More sharing options...
PFMaBiSmAd Posted January 24, 2009 Share Posted January 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745208 Share on other sites More sharing options...
Zane Posted January 24, 2009 Share Posted January 24, 2009 else // Report all PHP errors error_reporting(E_ALL); // { include("header.php"); I'm surprised you don't have an unexpected { error occurring. May not be the solution to this problem...but every little bit helps.. I'm stumped. Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745209 Share on other sites More sharing options...
dropfaith Posted January 24, 2009 Author Share Posted January 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142241-i-feel-dumb-update-help/#findComment-745211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.