Update database

For some reason, my code wont let me update my database. I know i am connected to proper database with the proper credentials. I have a button that lets me delete a whole row but my update button wont work!. I just want it so that when a user hits Update, itll update the database. There are three files that you may need to look at someone please help!

network.html

<?php include("nameFunctions.php"); include("dbcon.php"); $sql = "SELECT ix, network FROM networkelements GROUP BY network;"; $result = mysql_query($sql) or die (mysql_error()); echo "

Please select a Network from the list - must choose at least one!



"; echo ""; while ($row = mysql_fetch_array($result)) { echo "$row[network]"; } echo "" ; echo ""; echo "
"; if ($_POST[submit]){ if (!empty($_POST[nets])){ ?>
	<div id='table1'>
<?php echo ""; $counter = "edit"; foreach ($_POST[nets] as $net) { $sql = "SELECT ix, network, zone, vendor, element, t1manager, t2manager, t3manager, t4manager, configmgr, capacitymgr, currentplng, engmanager, fnpmanager FROM networkelements WHERE network = '$net' GROUP BY network, zone, vendor, element "; $result = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_array($result)){ echo ""; //Auto incrementing numbers for updating elements. $link = "" . $counter . ""; echo ""; echo ""; echo ""; echo ""; echo ""; $s = $row['t1manager']; $s1 = multinametree($s); echo ""; $s = $row['t2manager']; $s1 = multinametree($s); echo ""; $s = $row['t3manager']; $s1 = multinametree($s); echo ""; $s = $row['t4manager']; $s1 = multinametree($s); echo ""; $s = $row['configmgr']; $s1 = multinametree($s); echo ""; $s = $row['capacitymgr']; $s1 = multinametree($s); echo ""; $s = $row['currentplng']; $s1 = multinametree($s); echo ""; $s = $row['engmanager']; $s1 = multinametree($s); echo ""; $s = $row['fnpmanager']; $s1 = multinametree($s); echo ""; echo ""; } $text = substr($text,0,-1); } echo "
Update Network Network Zone Vendor Element T1 Manager T2 Manager T3 Manager T4 Manager Config Manager Capacity Manager Current Planning Eng Manager Fnp Manager
" . $link . "" . $row['network'] . "" . $row['zone'] . "" . $row['vendor'] . "" . $row['element'] . "" . $s1 . "" . $s1 . "" . $s1 . "" . $s1 . "" . $s1 . "" . $s1 . "" . $s1 . "" . $s1 . "" . $s1 . "
"; } else { $text = <<<EOD
Nothing was selected, please try again!
EOD; } echo "$text"; } mysql_close($con); ?>

updateTool.html

<?php include("dbcon.php"); $ix = $_REQUEST['ix']; $sql = "SELECT * FROM networkelements where ix=" . $ix . " order by ix;"; print ""; print ""; print ""; print "Update Tool"; print ""; print ""; print ""; print ""; $menu = "Ops Model Tool"; $menu .= "
Cancel

"; print "
"; $dbr = mysql_query($sql); $n = mysql_num_rows ($dbr); $row = mysql_fetch_object($dbr); print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print $menu; print "Modify Item

Item Value
"; print "Network"; print ""; print ""; print "
"; print "Zone"; print ""; print ""; print "
"; print "Vendor"; print ""; print ""; print "
"; print "Element"; print ""; print ""; print "
"; print "Tier 1 (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Tier 2 (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Tier 3 (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Tier 4 (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Configuration Manager (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Capacity Manager (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Current Planning Manager (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Engineering Manager (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "Fundamental Network Planning Manager (attid1; attid2; attid3...)"; print ""; print ""; print "
"; print "&nbsp"; print ""; print ""; //print "-- Update This Record --"; $net = $_REQUEST['net']; print "


-- Delete This Record --"; print "
"; print ""; print ""; print ""; mysql_close($con); ?>

uupdateTool.html

<? include("dbcon.php"); $ix = $_REQUEST['ix']; $net = $_REQUEST['net']; $q = " UPDATE networkelements SET "; $q .= "network = '" . addslashes(trim($_REQUEST['network'])) . "', "; $q .= "zone= '" . addslashes(trim($_REQUEST['zone'])) . "', "; $q .= "vendor= '" . addslashes(trim($_REQUEST['vendor'])) . "', "; $q .= "element= '" . addslashes(trim($_REQUEST['element'])) . "', "; $q .= "t1manager= '" . addslashes(trim($_REQUEST['t1manager'])) . "', "; $q .= "t2manager= '" . addslashes(trim($_REQUEST['t2manager'])) . "', "; $q .= "t3manager= '" . addslashes(trim($_REQUEST['t3manager'])) . "', "; $q .= "t4manager= '" . addslashes(trim($_REQUEST['t4manager'])) . "', "; $q .= "configmgr= '" . addslashes(trim($_REQUEST['configmgr'])) . "', "; $q .= "capacitymgr= '" . addslashes(trim($_REQUEST['capacitymgr'])) . "', "; $q .= "currentplng= '" . addslashes(trim($_REQUEST['currentplng'])) . "', "; $q .= "engmanager= '" . addslashes(trim($_REQUEST['engmanager'])) . "', "; $q .= "fnpmanager= '" . addslashes(trim($_REQUEST['fnpmanager'])) . "', "; $q .= " WHERE ix='" . $ix . "' limit 1"; print $q; $resutlt = mysql_query($q); print $result; header("Location: network.html?net=$net"); mysql_close($con); ?>

My index.html is just a webpage with different links to tools

is uupdateTool.html correct? It should be a php page (unless it is included in a php page already)[php]print “”;[/php]

just incase your server has short tags off add ‘php’ here (like you have everywhere else.)[php]<?
include(“dbcon.php”);[/php]

[php]

$q .= “currentplng= '” . addslashes(trim($_REQUEST[‘currentplng’])) . "’, ";
$q .= “engmanager= '” . addslashes(trim($_REQUEST[‘engmanager’])) . "’, ";
$q .= “fnpmanager= '” . addslashes(trim($_REQUEST[‘fnpmanager’])) . "’, "; // << remove this comma
[/php]

$result & $resultlt are not the same thing - typo i expect.
[php]
$resutlt = mysql_query($q);
print $result;
[/php]

For future reference, when adding code/php use the code/php buttons in the editor (like i did) - makes it easier to read.

  • Oh, and stop using mysql - Use mysqli or pdo instead!

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service