mada Posted January 19, 2007 Share Posted January 19, 2007 I am having problems updating a row within a table using the following file which I wrote using a tutorial:-For some reason it fails to execute the SQL query. Excuse my idiocy, I am very new to PHP.[code=edit.php]<?php include('mysql.php');//If cmd has not been initializedif(!isset($cmd)) { //display all the peopleextensions $result = mysql_query("select * from peopleextensions order by ID"); //run the while loop that grabs all the peopleextensions scripts while($r=mysql_fetch_array($result)) { //grab the Name and the ID of the peopleextensions $Name=$r["Name"];//take out the Name $ID=$r["ID"];//take out the ID //make the Name a link echo "<a href='edit.php?cmd=edit&ID=$ID'>$Name - Edit</a>"; echo "<br />"; }}?><?if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit"){ if (!isset($_POST["submit"])) { $ID = $_GET["ID"]; $sql = "SELECT * FROM peopleextensions WHERE ID=$ID"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden Name="ID" value="<?php echo $myrow["ID"] ?>"> Name:<INPUT TYPE="TEXT" NAME="Name" VALUE="<?php echo $myrow["Name"] ?>" SIZE=30><br /> Area Code:<INPUT TYPE="TEXT" NAME="AreaCode" VALUE="<?php echo $myrow["AreaCode"] ?>" SIZE=30><br /> Number:<INPUT TYPE="TEXT" NAME="Number" VALUE="<?php echo $myrow["Number"] ?>" SIZE=30><br /> Role:<INPUT TYPE="TEXT" NAME="Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br /> Department:<INPUT TYPE="TEXT" NAME="Department" VALUE="<?php echo $myrow["Department"] ?>" SIZE=30><br /> <input type="hidden" Name="cmd" value="edit"> <input type="submit" Name="submit" value="submit"> </form> <? } ?><? if ($_POST["submit"]) { $id = $_POST["ID"]; $Name = $_POST["Name"]; $AreaCode = $_POST["AreaCode"]; $Number = $_POST["Number"]; $Role = $_POST["Role"]; $Department = $_POST["Department"]; $sql = 'UPDATE peopleextensions SET Name="$Name", Name="$Name",AreaCode="$AreaCode",Number="$Number",Role="$Role",Department="$Department" WHERE ID=$ID'; //replace peopleextensions with your table Name above $result = mysql_query($sql);if($result){echo "Update successful";echo "Thank you! Information updated.";echo "<br>";echo "<a href='index.php'>Home</a>";}// use else to execute the code if $result was falseelse{echo "Update failed, please try again";echo "<br>";echo "<a href='index.php'>Home</a>";} }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/34876-problem-editing-table-row/ Share on other sites More sharing options...
paul2463 Posted January 19, 2007 Share Posted January 19, 2007 try this one [code]<?php$sql = "UPDATE peopleextensions SET Name='$Name'",?>[/code] Link to comment https://forums.phpfreaks.com/topic/34876-problem-editing-table-row/#findComment-164389 Share on other sites More sharing options...
paul2463 Posted January 19, 2007 Share Posted January 19, 2007 sorry missed the other bits off[code]$sql = "UPDATE peopleextensions SET Name='$Name',AreaCode='$AreaCode',Number='$Number',Role='$Role',Department='$Department' WHERE ID='$ID'"; //replace peopleextensions with your table Name above[/code] Link to comment https://forums.phpfreaks.com/topic/34876-problem-editing-table-row/#findComment-164391 Share on other sites More sharing options...
mada Posted January 19, 2007 Author Share Posted January 19, 2007 [quote author=paul2463 link=topic=123134.msg508535#msg508535 date=1169213062]sorry missed the other bits off[code]$sql = "UPDATE peopleextensions SET Name='$Name',AreaCode='$AreaCode',Number='$Number',Role='$Role',Department='$Department' WHERE ID='$ID'"; //replace peopleextensions with your table Name above[/code][/quote]Spot on, I managed to do it after your first reply ;DThanks for your help! Link to comment https://forums.phpfreaks.com/topic/34876-problem-editing-table-row/#findComment-164394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.