Jump to content

Editing MySQL data with PHP


Feartheyankees

Recommended Posts

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  :D

 

Jeremy

Link to comment
Share on other sites

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>";
   ?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

 

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.