Feartheyankees Posted June 24, 2010 Share Posted June 24, 2010 Hello, I actually had this working for a day or two, but without changing the code or mysql database, it stopped working, and editing the database like i had it coded to do. No errors or anything come up, it even says that it has been edited, but nothing is changed in the database. Here's the code: <?php mysql_connect("localhost","XXXXX","XXXXX") or die("Error: ".mysqlerror()); mysql_select_db("xxxxx"); $pirepid = $_POST['pirepid']; $username = $_POST['username']; $date = $_POST['date']; $icao_orig = $_POST['icao_orig']; $icao_dest = $_POST['icao_dest']; $aircraft = $_POST['aircraft']; $routenum = $_POST['routenum']; $dep_time = $_POST['dep_time']; $flthrs2 = $_POST['flthrs2']; $comments = $_POST['comments']; $sql = "UPDATE `pirep` SET `spirepid` = '$pirepid',`username` = '$username',`date` = '$date', `icao_orig` = '$icao_orig', `icao_dest` = '$icao_dest', `aircraft` = '$aircraft', `routenum` = '$routenum', `dep_time` = '$dep_time', `flthrs2` = '$flthrs2', `comments` = '$comments' WHERE `pirepid` = '$pirepid'"; mysql_query($sql) or die ("Error: ".mysql_error()); echo "Database updated. <a href='PIREPS.php'>Return to edit info</a>"; ?> If anyone can help, i'd appreciate it Jeremy Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/ Share on other sites More sharing options...
Feartheyankees Posted June 24, 2010 Author Share Posted June 24, 2010 NOTE: $sql = "UPDATE `pirep` SET `spirepid` I know there's an s in pirepid, i took out the S, and it still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076345 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 1) print_r() the $_POST array to make sure the variables are being passed from the form. 2) Comment out the query temporarily, and echo the query string to see if it has the right values in it. Also, you really, really, really need to sanitize the form data before using it in a query string. print_r($_POST); $pirepid = $_POST['pirepid']; $username = $_POST['username']; $date = $_POST['date']; $icao_orig = $_POST['icao_orig']; $icao_dest = $_POST['icao_dest']; $aircraft = $_POST['aircraft']; $routenum = $_POST['routenum']; $dep_time = $_POST['dep_time']; $flthrs2 = $_POST['flthrs2']; $comments = $_POST['comments']; $sql = "UPDATE `pirep` SET `spirepid` = '$pirepid',`username` = '$username',`date` = '$date', `icao_orig` = '$icao_orig', `icao_dest` = '$icao_dest', `aircraft` = '$aircraft', `routenum` = '$routenum', `dep_time` = '$dep_time', `flthrs2` = '$flthrs2', `comments` = '$comments' WHERE `pirepid` = '$pirepid'"; echo "<br />Query string: " . $sql . "<br />"; // COMMENTED OUT mysql_query($sql) or die ("Error: ".mysql_error()); echo "Database updated. <a href='PIREPS.php'>Return to edit info</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076398 Share on other sites More sharing options...
Feartheyankees Posted June 24, 2010 Author Share Posted June 24, 2010 Hmm.. Still not working... i haven't coded in years, so that's probably why things aren't coded as good as it should be.. Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076405 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 The additions aren't intended to get it working, well not directly, at least. They are just for debugging. What was the output from those 2 statements you added? Are you getting any output from the script at all? Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076411 Share on other sites More sharing options...
Feartheyankees Posted June 24, 2010 Author Share Posted June 24, 2010 When I ran the script i got Array ( [pirepid] => [username] => [date] => 6/22/10 [icao_orig] => TEST [icao_dest] => TEST [aircraft] => Airbus A340 [routenum] => 2234 [dep_time] => 11:03 [flthrs2] => 7.2 [comments] => [submitButtonName] => Update [id] => ) Query string: UPDATE `pirep` SET `spirepid` = '',`username` = '',`date` = '6/22/10', `icao_orig` = 'TEST', `icao_dest` = 'TEST', `aircraft` = 'Airbus A340', `routenum` = '2234', `dep_time` = '11:03', `flthrs2` = '7.2', `comments` = '' WHERE `pirepid` = '' Database updated. Return to edit info Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076417 Share on other sites More sharing options...
kenrbnsn Posted June 24, 2010 Share Posted June 24, 2010 Can you post the form that is used to send the data to this script? According to the array dump, you're not getting all the data you want. Ken Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076421 Share on other sites More sharing options...
Feartheyankees Posted June 24, 2010 Author Share Posted June 24, 2010 sure <?phpinclude("connect.php");$pirepid = $_GET['pirepid'];$qProfile = "SELECT * FROM pirep WHERE pirepid='$pirepid' ";$rsProfile = mysql_query($qProfile);$row = mysql_fetch_array($rsProfile);$pirepid = stripslashes($pirepid);$username = stripslashes($username);$date = stripslashes($date);$icao_orig = stripslashes($icao_orig);$icao_dest = stripslashes($icao_dest);$aircraft = stripslashes($aircraft);$routenum = stripslashes($routenum);$dep_time = stripslashes($dep_time);$flthrs2 = stripslashes($flthrs2);$comments = stripslashes($comments);mysql_close();?><form id="FormName" action="updated.php" method="post" name="FormName"><table width="448" border="0" cellspacing="2" cellpadding="0"><tr><td width="150"><div align="right"><label for="pirepid">PIREP ID</label></div></td><td><input id="pirepid" name="pirepid" type="hidden" size="25" value="<?php echo $pirepid ?>" maxlength="11"> Contact the COO to change</td></tr><tr><td width="150"><div align="right"><label for="username">Username</label></div></td><td><input id="username" name="username" type="hidden" size="25" value="<?php echo $username ?>" maxlength="25">Contact the COO to change</td></tr><tr><td width="150"><div align="right"><label for="date">Date</label></div></td><td><input id="date" name="date" type="text" size="25" value="<?php echo $date ?>" maxlength="8"></td></tr><tr><td width="150"><div align="right"><label for="icao_orig"></label>Departing ICAO</div></td><td><input id="icao_orig" name="icao_orig" type="text" size="25" value="<?php echo $icao_orig ?>" maxlength="4"></td></tr><tr><td width="150"><div align="right"><label for="icao_dest">Arriving ICAO</label></div></td><td><input id="icao_dest" name="icao_dest" type="text" size="25" value="<?php echo $icao_dest ?>" maxlength="4"></td></tr><tr><td width="150"><div align="right"><label for="aircraft"></label>Aircraft</div></td><td><input id="aircraft" name="aircraft" type="text" size="25" value="<?php echo $aircraft ?>" maxlength="25"></td></tr><tr><td width="150"><div align="right"><label for="routenum">Route Number</label></div></td><td><input id="routenum" name="routenum" type="text" size="25" value="<?php echo $routenum ?>" maxlength="4"></td></tr><tr><td width="150"><div align="right"><label for="dep_time">Departure Time</label></div></td><td><input id="dep_time" name="dep_time" type="text" size="25" value="<?php echo $dep_time ?>" maxlength="8"></td></tr><tr><td width="150"><div align="right"><label for="flthrs2">Flight Hours</label></div></td><td><input id="flthrs2" name="flthrs2" type="text" size="25" value="<?php echo $flthrs2 ?>" maxlength="4,1"></td></tr><tr><td width="150"><div align="right"><label for="comments">Comments</label></div></td><td><textarea id="comments" name="comments" rows="4" cols="40"><?php echo $comments ?></textarea></td></tr><tr><td width="150"></td><td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?php echo $id ?>"></td></tr></table></form> Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076425 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 Where does the form above get its data for the hidden fields? Does it come from another, previous form? What is the flow of this process? Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076603 Share on other sites More sharing options...
Feartheyankees Posted June 24, 2010 Author Share Posted June 24, 2010 Basically the hidden values are for non-editable things, like the id and the username. I don't want the people that will edit the database values to be able to edit that as it will screw up the sequence. Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076885 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 I know what they're for; I asked where they come from because that appears to be the root cause of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076915 Share on other sites More sharing options...
jcbones Posted June 24, 2010 Share Posted June 24, 2010 Are you sure the $_GET variable is set, you should be checking for that. Try putting: echo $pirepid; at the top of the form page, right below the assignment of that variable. Quote Link to comment https://forums.phpfreaks.com/topic/205693-editing-mysql-data-with-php/#findComment-1076930 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.