russia5 Posted March 21, 2007 Share Posted March 21, 2007 I need help, please. The code in question, adds admins with different queries of the database. I am not getting the data to populate the Agency field upon Posting. I am getting the error: Sorry, required agency name.(find the face) Below is the database: Field Type Attributes Null Default Extra Action id tinyint(3) No 0 agency varchar(15) No user_name varchar(15) No password varchar(15) No role varchar(15) No admin Below is the form: ?php session_start(); if (!isset($_SESSION['user_name'])) { header("Location: Login.php?url=" . $_SERVER['PHP_SELF']); } if ($_SESSION['admin_role'] <> "super_admin") { ?> <html> <head> <script type="text/javascript" language="JavaScript"> alert("You are not authorized to perform this operation.\nPlease contact the super-admin for requesting authorization."); location.href = 'Profile_Admin.php'; </script> <?php } include_once ("../../config.php"); ?> <title>My New Agency</title> <link rel="stylesheet" type="text/css" href="stylesheet.css"> </head> <body> <h1>My Admin Panel</h1> <h2>Add New Agency</h2> <?php include "html_includes/AdminMenu.inc"; ?> <div class="ContentsBox" id="Contents" style="width: 400"> <?php if($_POST["btnAdd"]<>"") { $agency = $_POST["agency"]; if($agency<>"") { $insertQuery = "INSERT INTO users set agency = '$agency'"; //echo mysql_error(). " ". $insertQuery; if ($result = mysql_query($insertQuery)) { // It worked, give confirmation echo '<font color=red><b>New agency added successfully.<br><br></b></font>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! echo "<font color=red><b>Sorry, there was an error adding the agency >:(name.<br><br></b></font>"; } }else{ echo "<font color=red><b>Sorry, required agency name.<br><br></b></font>"; } } ?> <h3>Enter New Agency</h3> <table class="Input"> <form name=AddAgency action=<?php echo $_SERVER['PHP_SELF'] ?> method=post> <tr> <td>Agency Name:</td> <td><input type=text size=20 maxlength=20 name=agency></td> <td align=right><input type=submit value=Add name=btnAdd></td> </tr> </table> <br><br> <?php if($_POST["btnEdit"]<>"") { $aid = $_POST["id"]; $agency = $_POST["agency"]; if($agency<>"") { $editQuery = "update users set agency = '$agency' where id=$aid"; //echo mysql_error(). " ". $insertQuery; if ($result = mysql_query($editQuery)) { // It worked, give confirmation echo '<font color=red><b>Agency name update successfully.<br><br></b></font>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! echo "<font color=red><b>Sorry, there was an error to modify agency name.<br><br></b></font>"; } }else{ echo "<font color=red><b>Sorry, required agency name.<br><br></b></font>"; } } if($_POST["btnDel"]<>"") { $aid = $_POST["id"]; $agency = $_POST["agency"]; $delQuery1 = "delete from users where id=$aid"; $delQuery2 = "delete from users where agency='$agency'"; $delQuery3 = "delete from subdomain_approval where agency='$agency'"; $delQuery4 = "delete from subdomain_hold where agency='$agency'"; $delQuery5 = "delete from subdomain_submission where agency='$agency'"; if($result1 = mysql_query($delQuery1)) { echo "<font color=red size=1><b>1. Agency name '".$_POST["agency"]."' deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>1. Sorry, there was an error to delete agency.<br></b></font>"; } if($result2 = mysql_query($delQuery2)) { echo "<font color=red size=1><b>2. Admin for '".$_POST["agency"]."' agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>2. Sorry, there was an error to delete admin for this agency.<br></b></font>"; } if($result3 = mysql_query($delQuery3)) { echo "<font color=red size=1><b>3. Approval Table Data for '".$_POST["agency"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>3. Sorry, there was an error to delete Approval for this agency.<br></b></font>"; } if($result4 = mysql_query($delQuery4)) { echo "<font color=red size=1><b>4. Hold Table Data for '".$_POST["agency"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>4. Sorry, there was an error to delete Hold/Edit for this agency.<br></b></font>"; } if($result5 = mysql_query($delQuery5)) { echo "<font color=red size=1><b>5. Submission Data for '".$_POST["agency"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>5. Sorry, there was an error to delete Submission for this agency.<br></b></font>"; } echo "<br>"; } ?> <h3>List of Agencies</h3> <table class="Input"> <?php $query0 = "select * from users order by agency"; $result0 = mysql_query($query0); if(mysql_num_rows($result0)>0) { $cnt = 1; while($row0=mysql_fetch_array($result0)) { ?> <tr> <td><?php echo $cnt; ?></td> <form name=AddAgency action=<?php echo $_SERVER['PHP_SELF'] ?> method=post> <td><input type=hidden name=id value="<?php echo $row0["id"]; ?>"> <input type=text size=20 maxlength=20 name=agency value="<?php echo $row0["agency"]; ?>"></td> <td align=right><input type=submit value=Edit name=btnEdit></td> <td align=right><input type=submit value=Del name=btnDel onClick="return confirm('Are you sure to delete agency name?')"></td> <td align=right><input type=button value="Add New Admin" onClick="javascript: location.href='add_admin.php?ag=<?php echo $row0["agency"]; ?>';"></td> </form> </tr> <?php $cnt++; } }else{ echo "<tr><th colspan=5>No agency found in list.</th></tr>"; } ?> </table> </div> </body> And Below is the include Adminmenu.ini <?php if($_SESSION['agency']<>""){ echo " <b>Agency: <font color=red>".$_SESSION['agency']."</font></b>"; } ?> <div class="MenuBox"> <table> <tr><td class="Header"><a>Profile Management</a></td></tr> <span class="MenuItems"> <tr><td><a class="ButtonLinks" href="Profile_Admin.php">Profile Admin Console</a></td></tr> </span> </table> </div> <br> <div class="MenuBox"> <table> <tr><td class="Header"><a>User Management</a></td></tr> <span class="MenuItems"> <?php if ($_SESSION['admin_role'] == "super_admin") { ?> <tr><td><a class="ButtonLinks" href="add_agency.php">Add new agency</a></td></tr> <tr><td><a class="ButtonLinks" href="add_admin.php">Add new admin</a></td></tr> <?php } ?> <tr><td><a class="ButtonLinks" href="change_password.php">Change Password</a></td></tr> <tr><td><a class="ButtonLinks" href="logout.php">Logout</a></td></tr> </span> </table> </div> <br> <div class="DayTimeBox"> <center> <script language="javascript"> function calcTime() { var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); var seconds = currentTime.getSeconds(); if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } var clockLocation = document.getElementById('Clock'); clockLocation.innerHTML = hours + ":" + minutes + ":" + seconds; setTimeout("calcTime()", 1000); } calcTime(); </script> </center> </div> And here is the form: Sorry, required agency name. Enter New AgencyAgency Name: List of Agencies1 2 Thanks for any help! Quote Link to comment Share on other sites More sharing options...
UTAlan Posted March 21, 2007 Share Posted March 21, 2007 Instead of: $insertQuery = "INSERT INTO users set agency = '$agency'"; Try: $insertQuery = "INSERT INTO users (agency) VALUES ('$agency')"; Quote Link to comment Share on other sites More sharing options...
russia5 Posted March 21, 2007 Author Share Posted March 21, 2007 Thanks for the try, but I am still getting the same error after making your suggested change. <?php session_start(); if (!isset($_SESSION['user_name'])) { header("Location: Login.php?url=" . $_SERVER['PHP_SELF']); } if ($_SESSION['admin_role'] <> "super_admin") { ?> <html> <head> <script type="text/javascript" language="JavaScript"> alert("You are not authorized to perform this operation.\nPlease contact the super-admin for requesting authorization."); location.href = 'Profile_Admin.php'; </script> <?php } include_once ("../../Newconfig.php"); ?> <title>Russian Sweets New Agency</title> <link rel="stylesheet" type="text/css" href="stylesheet.css"> </head> <body> <h1>Russian Sweets Admin Panel</h1> <h2>Add New Agency</h2> <?php include "html_includes/AdminMenu.inc"; ?> <div class="ContentsBox" id="Contents" style="width: 400"> <?php if($_POST["btnAdd"]<>"") { $agency = $_POST["agency"]; if($agency<>"") { $insertQuery = "INSERT INTO users set (agency) = ('$agency')"; //echo mysql_error(). " ". $insertQuery; if ($result = mysql_query($insertQuery)) { // It worked, give confirmation echo '<font color=red><b>New agency added successfully.<br><br></b></font>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! echo "<font color=red><b>Sorry, there was an error adding the agency name.<br><br></b></font>"; } }else{ echo "<font color=red><b>Sorry, required agency name.<br><br></b></font>"; } } ?> <h3>Enter New Agency</h3> <table class="Input"> <form name=AddAgency action=<?php echo $_SERVER['PHP_SELF'] ?> method=post> <tr> <td>Agency Name:</td> <td><input type=text size=20 maxlength=20 name=agency></td> <td align=right><input type=submit value=Add name=btnAdd></td> </tr> </table> <br><br> <?php if($_POST["btnEdit"]<>"") { $aid = $_POST["id"]; $agency = $_POST["agency"]; if($agency<>"") { $editQuery = "update users set agency = '$agency' where id=$aid"; //echo mysql_error(). " ". $insertQuery; if ($result = mysql_query($editQuery)) { // It worked, give confirmation echo '<font color=red><b>Agency name update successfully.<br><br></b></font>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! echo "<font color=red><b>Sorry, there was an error to modify agency name.<br><br></b></font>"; } }else{ echo "<font color=red><b>Sorry, required agency name.<br><br></b></font>"; } } if($_POST["btnDel"]<>"") { $aid = $_POST["id"]; $agency = $_POST["agency"]; $delQuery1 = "delete from users where id=$aid"; $delQuery2 = "delete from users where agency='$agency'"; $delQuery3 = "delete from subdomain_approval where agency='$agency'"; $delQuery4 = "delete from subdomain_hold where agency='$agency'"; $delQuery5 = "delete from subdomain_submission where agency='$agency'"; if($result1 = mysql_query($delQuery1)) { echo "<font color=red size=1><b>1. Agency name '".$_POST["agency"]."' deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>1. Sorry, there was an error to delete agency.<br></b></font>"; } if($result2 = mysql_query($delQuery2)) { echo "<font color=red size=1><b>2. Admin for '".$_POST["agency"]."' agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>2. Sorry, there was an error to delete admin for this agency.<br></b></font>"; } if($result3 = mysql_query($delQuery3)) { echo "<font color=red size=1><b>3. Approval Table Data for '".$_POST["agency"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>3. Sorry, there was an error to delete Approval for this agency.<br></b></font>"; } if($result4 = mysql_query($delQuery4)) { echo "<font color=red size=1><b>4. Hold Table Data for '".$_POST["agency"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>4. Sorry, there was an error to delete Hold/Edit for this agency.<br></b></font>"; } if($result5 = mysql_query($delQuery5)) { echo "<font color=red size=1><b>5. Submission Data for '".$_POST["agency"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>5. Sorry, there was an error to delete Submission for this agency.<br></b></font>"; } echo "<br>"; } ?> <h3>List of Agencies</h3> <table class="Input"> <?php $query0 = "select * from users order by agency"; $result0 = mysql_query($query0); if(mysql_num_rows($result0)>0) { $cnt = 1; while($row0=mysql_fetch_array($result0)) { ?> <tr> <td><?php echo $cnt; ?></td> <form name=AddAgency action=<?php echo $_SERVER['PHP_SELF'] ?> method=post> <td><input type=hidden name=id value="<?php echo $row0["id"]; ?>"> <input type=text size=20 maxlength=20 name=agency value="<?php echo $row0["agency"]; ?>"></td> <td align=right><input type=submit value=Edit name=btnEdit></td> <td align=right><input type=submit value=Del name=btnDel onClick="return confirm('Are you sure to delete agency name?')"></td> <td align=right><input type=button value="Add New Admin" onClick="javascript: location.href='add_admin.php?ag=<?php echo $row0["agency"]; ?>';"></td> </form> </tr> <?php $cnt++; } }else{ echo "<tr><th colspan=5>No agency found in list.</th></tr>"; } ?> </table> </div> </body> Quote Link to comment Share on other sites More sharing options...
UTAlan Posted March 21, 2007 Share Posted March 21, 2007 You changed it to: $insertQuery = "INSERT INTO users set (agency) = ('$agency')"; Which is incorrect syntax. Try: $insertQuery = "INSERT INTO users (agency) VALUES ('$agency')"; Quote Link to comment Share on other sites More sharing options...
russia5 Posted March 21, 2007 Author Share Posted March 21, 2007 Thanks again... no... it did not work and I am getting the same error. if($agency<>"") { $insertQuery = "INSERT INTO users set (agency) VALUES ('$agency')"; //echo mysql_error(). " ". $insertQuery; if ($result = mysql_query($insertQuery) The form posted before with the way I had it originally. I changed the database, adding the old to the new, and I changed the variable names. I had agency_name and I changed it to agency. I also changed agency_id to id. Might have been something else too. Then, I got the error. Quote Link to comment Share on other sites More sharing options...
UTAlan Posted March 21, 2007 Share Posted March 21, 2007 Get rid of the word "set" Quote Link to comment Share on other sites More sharing options...
russia5 Posted March 21, 2007 Author Share Posted March 21, 2007 Thanks again... I am stumped... getting the same error... if($agency<>"") { $insertQuery = "INSERT INTO users (agency) VALUES ('$agency')"; //echo mysql_error(). " ". $insertQuery; Quote Link to comment Share on other sites More sharing options...
russia5 Posted March 21, 2007 Author Share Posted March 21, 2007 Here is the previous coding done that works. It posts just fine to the following table. -------------------------------------------------------------------------------- Indexes: Keyname Type Cardinality Action Field PRIMARY PRIMARY 2 id agency_name UNIQUE None agency_name <?php session_start(); if (!isset($_SESSION['user_name'])) { header("Location: Login.php?url=" . $_SERVER['PHP_SELF']); } if ($_SESSION['admin_role'] <> "super_admin") { ?> <html> <head> <script type="text/javascript" language="JavaScript"> alert("You are not authorized to perform this operation.\nPlease contact the super-admin for requesting authorization."); location.href = 'Profile_Admin.php'; </script> <?php } include_once ("../../config.php"); ?> <title>My New Agency</title> <link rel="stylesheet" type="text/css" href="stylesheet.css"> </head> <body> <h1>My Admin Panel</h1> <h2>Add New Agency</h2> <?php include "html_includes/AdminMenu.inc"; ?> <div class="ContentsBox" id="Contents" style="width: 400"> <?php if($_POST["btnAdd"]<>"") { $agency = $_POST["agency_name"]; if($agency<>"") { $insertQuery = "INSERT INTO agencies set agency_name = '$agency'"; //echo mysql_error(). " ". $insertQuery; if ($result = mysql_query($insertQuery)) { // It worked, give confirmation echo '<font color=red><b>New agency added successfully.<br><br></b></font>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! echo "<font color=red><b>Sorry, there was an error adding the agency name.<br><br></b></font>"; } }else{ echo "<font color=red><b>Sorry, required agency name.<br><br></b></font>"; } } ?> <h3>Enter New Agency</h3> <table class="Input"> <form name=AddAgency action=<?php echo $_SERVER['PHP_SELF'] ?> method=post> <tr> <td>Agency Name:</td> <td><input type=text size=20 maxlength=20 name=agency_name></td> <td align=right><input type=submit value=Add name=btnAdd></td> </tr> </table> <br><br> <?php if($_POST["btnEdit"]<>"") { $aid = $_POST["agency_id"]; $agency = $_POST["agency_name"]; if($agency<>"") { $editQuery = "update agencies set agency_name = '$agency' where id=$aid"; //echo mysql_error(). " ". $insertQuery; if ($result = mysql_query($editQuery)) { // It worked, give confirmation echo '<font color=red><b>Agency name update successfully.<br><br></b></font>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! echo "<font color=red><b>Sorry, there was an error to modify agency name.<br><br></b></font>"; } }else{ echo "<font color=red><b>Sorry, required agency name.<br><br></b></font>"; } } if($_POST["btnDel"]<>"") { $aid = $_POST["agency_id"]; $agency = $_POST["agency_name"]; $delQuery1 = "delete from agencies where id=$aid"; $delQuery2 = "delete from users where agency='$agency'"; $delQuery3 = "delete from subdomain_approval where agency='$agency'"; $delQuery4 = "delete from subdomain_hold where agency='$agency'"; $delQuery5 = "delete from subdomain_submission where agency='$agency'"; if($result1 = mysql_query($delQuery1)) { echo "<font color=red size=1><b>1. Agency name '".$_POST["agency_name"]."' deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>1. Sorry, there was an error to delete agency.<br></b></font>"; } if($result2 = mysql_query($delQuery2)) { echo "<font color=red size=1><b>2. Admin for '".$_POST["agency_name"]."' agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>2. Sorry, there was an error to delete admin for this agency.<br></b></font>"; } if($result3 = mysql_query($delQuery3)) { echo "<font color=red size=1><b>3. Approval Table Data for '".$_POST["agency_name"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>3. Sorry, there was an error to delete Approval for this agency.<br></b></font>"; } if($result4 = mysql_query($delQuery4)) { echo "<font color=red size=1><b>4. Hold Table Data for '".$_POST["agency_name"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>4. Sorry, there was an error to delete Hold/Edit for this agency.<br></b></font>"; } if($result5 = mysql_query($delQuery5)) { echo "<font color=red size=1><b>5. Submission Data for '".$_POST["agency_name"]."' Agency deleted successfully.<br></b></font>"; }else{ echo "<font color=red size=1><b>5. Sorry, there was an error to delete Submission for this agency.<br></b></font>"; } echo "<br>"; } ?> <h3>List of Agencies</h3> <table class="Input"> <?php $query0 = "select * from agencies order by agency_name"; $result0 = mysql_query($query0); if(mysql_num_rows($result0)>0) { $cnt = 1; while($row0=mysql_fetch_array($result0)) { ?> <tr> <td><?php echo $cnt; ?></td> <form name=AddAgency action=<?php echo $_SERVER['PHP_SELF'] ?> method=post> <td><input type=hidden name=agency_id value="<?php echo $row0["id"]; ?>"> <input type=text size=20 maxlength=20 name=agency_name value="<?php echo $row0["agency_name"]; ?>"></td> <td align=right><input type=submit value=Edit name=btnEdit></td> <td align=right><input type=submit value=Del name=btnDel onClick="return confirm('Are you sure to delete agency name?')"></td> <td align=right><input type=button value="Add New Admin" onClick="javascript: location.href='add_admin.php?ag=<?php echo $row0["agency_name"]; ?>';"></td> </form> </tr> <?php $cnt++; } }else{ echo "<tr><th colspan=5>No agency found in list.</th></tr>"; } ?> </table> </div> </body> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 You do know it is not illegal to use the [ code ] and [ /code ] tags right? And actually really helps someone reading through that to help you out. Quote Link to comment Share on other sites More sharing options...
russia5 Posted March 21, 2007 Author Share Posted March 21, 2007 Yes I do know that. I was an accident. I thought I had them in. Looking for the edit but I do not see it. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 The edit goes away after 5 minutes. Best to create a new entry with them encapsulated in the code tag. Quote Link to comment Share on other sites More sharing options...
grimmier Posted March 21, 2007 Share Posted March 21, 2007 don't know if it matters, but the one thing that stands out in my eyes is the use of <> for not equal instead of != Quote Link to comment Share on other sites More sharing options...
jcbarr Posted March 22, 2007 Share Posted March 22, 2007 Yeah but he isn't getting the alert, or he isn't saything that he is, so I don't think that seems to be a problem. Quote Link to comment 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.