Jump to content

danielj

Members
  • Posts

    15
  • Joined

  • Last visited

danielj's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I did wonder why it wasn't array(array(...)). Thanks for that, I got it to work using: foreach ($posts_array as $key){ echo "<li>"; echo $key->{"post_name"}; echo "</li>"; }
  2. I'm having trouble looping through an array. I admit that I'm not that great with associative arrays. The print_r line in my code below prints the array that I am trying to use. It looks like it is an array of associative arrays. Here is a small part of the output. [*]Array ( [0] => WP_Post Object ( [iD] => 52711 [post_author] => 31 [post_date] => 2014-06-05 15:19:12 [post_date_gmt] => 2014-06-05 19:19:12 [post_content] => Test [post_title] => Test [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => test Here is the code. $att = shortcode_atts ( array('category' => 'news', 'posts_per_page' => '0', 'orderby' => 'post_date'), $args); $posts_array = get_posts($att); print_r(array_values($posts_array)); echo "<ul>"; foreach ($posts_array as $key => $value){ foreach($value as $key2 => $value2){ echo "<li>"; echo $value2["post_name"]; echo "</li>"; } } echo "</ul>"; The output doesn't make sense to me. It is a bunch of li items of one character. A few of the li items are: 3 2 2 T T p o o t 2 2 h p 0. Note that each character is a different li item. Thanks for any suggestions.
  3. What I'm trying to do is use an xml DOM created in php to display on my webpage using an ajax call. I'm pretty sure this is a JavaScript problem, but it's possible there may be an issue with my php code. Part of the php code is below if needed. The reason I believe the php code is fine, is because if I go directly to the page and uncomment the saveHTML() line, it displays fine. The first code below is my ajax call. I think the call fails, because what I get is the alert error message in my code (An error has occured). I'm not sure what the issue is. Thanks for any suggestions. request = $.ajax({ url: "results.php", type: "POST", dataType: "xml" }).done(function (data){ $(data).find("stat").each(function(){ $("result").append($(this).find("fName").text() + "<br>"); }); }).fail(function (){ alert("An error has occured."); }); $result=mysqli_query($con,$cmd);$doc = new DOMDocument("1.0", "utf-8"); $root = $doc->createElement('stats'); $doc->appendChild($root); while($row=mysqli_fetch_array($result)){ // Creates the main xml element stat $element = $doc->createElement("stat"); // Declares variables from SQL table to be used for sub-elements $fName = $row['fName']; $lName = $row['lName']; $position = $row['position']; $pYard = $row['pYard']; // Create sub-elements $pfName = $doc->createElement("fName", $fName); $plName = $doc->createElement("lName", $lName); $pPosition = $doc->createElement("position", $position); $pPYard = $doc->createElement("pYard", $pYard); // Add sub-elements to main element stat $element->appendChild($pfName); $element->appendChild($plName); $element->appendChild($pPosition); $element->appendChild($pPYard); // Add main element to root $root->appendChild($element); } //echo $doc->saveHTML(); echo $doc;
  4. Great, that works. One site I was looking at didn't have it, so I had that line commented out. Thanks for the help.
  5. I get the error once it reaches the line cmd.ExecuteNonQuery();.
  6. Thanks for taking the time to help. I figured I would try a slightly different approach, but this isn't working either. I get the error: Insert Error:Procedure or function 'SubmitCheck' expects parameter '@pfName', which was not supplied. From what I can see this should work. The code is below. SqlConnection conn = new SqlConnection(GetConnectionString()); try { conn.Open(); SqlCommand cmd = new SqlCommand("SubmitCheck", conn); SqlParameter sqlCheck = new SqlParameter("@check", DbType.Int16) {Direction=ParameterDirection.Output }; cmd.Parameters.Add(sqlCheck); cmd.Parameters.AddWithValue("@pfName", fName.Text); cmd.Parameters.AddWithValue("@plName", lName.Text); cmd.Parameters.AddWithValue("@pssn", ssn.Text); cmd.ExecuteNonQuery(); int check = int.Parse(cmd.Parameters["@check"].Value.ToString()); if (check==1) { checkEntrylbl.Text = "You have not yet completed this form. Please complete the form."; checkEntrylbl.Visible = true; lName.Enabled = false; fName.Enabled = false; ssn.Enabled = false; submitButton.Enabled = true; } else { checkEntrylbl.Text = "You have completed this form. You do not have to fill it out again."; checkEntrylbl.Visible = true; } } ALTER PROCEDURE [dbo].[submitCheck] -- Add the parameters for the stored procedure here @pfName varchar(50), @plName varchar(50), @pssn int, @check int OUTPUT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SET @check = 0; -- Checks if there is an entry with the same first name, last name, and last four of ssn. IF (EXISTS(SELECT fName, lName, ssn FROM dbo.compassSurvey WHERE @pfName = fName AND @plName = lName AND @pssn = ssn)) BEGIN -- This statement runs if there is an entry. Since there is an entry, they do not need to fill out the form. -- Thus, return 0 (false). RETURN (@check); END BEGIN SET @check = 1; -- This statement runs if there is not an entry. Since there is not an entry, they do need to fill out the form. -- Thus, return 1 (true). RETURN (@check); END END
  7. In Visual Studios, cmd >Parameters>base>Results View- it shows all three parameters having the expected values.
  8. It is always gets set to false. Whether I try a entry that is not there (should be true) or try an entry that is there (should be false).
  9. My goal is to have users fill out three fields and click on a button that will check an sql table to see if there is a record with those three fields already in the database. I'm not 100% sure, but I think my issue is in my C# code calling the procedure. I have tested my stored procedure from sql and it works. I've tried a few things, but nothing is working. The code below is one of my attempts that isn't working. I'm not sure, but when I step through the program it doesn't appear to be calling the procedure (though I could be wrong and the problem is elsewhere). SqlConnection conn = new SqlConnection(GetConnectionString()); try { conn.Open(); SqlCommand cmd = new SqlCommand("SubmitCheck", conn); SqlParameter sqlCheck = new SqlParameter("@result", DbType.Int16); cmd.Parameters.AddWithValue("@pfName", fName.Text); cmd.Parameters.AddWithValue("@plName", lName.Text); cmd.Parameters.AddWithValue("@pssn", ssn.Text); cmd.CommandType = CommandType.StoredProcedure; bool check = Convert.ToBoolean(cmd.ExecuteScalar()); if (check) { checkEntrylbl.Text = "You have not yet completed this form. Please complete the form."; checkEntrylbl.Visible = true; lName.Enabled = false; fName.Enabled = false; ssn.Enabled = false; submitButton.Enabled = true; } else { checkEntrylbl.Text = "You have completed this form. You do not have to fill it out again."; checkEntrylbl.Visible = true; } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } finally { conn.Close(); } Here is the stored procedure code. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE SubmitCheck -- Add the parameters for the stored procedure here @pfName varchar(50), @plName varchar(50), @pssn int AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Checks if there is an entry with the same first name, last name, and last four of ssn. IF (EXISTS(SELECT fName, lName, ssn FROM dbo.compassSurvey WHERE @pfName = fName AND @plName = lName AND @pssn = ssn)) BEGIN RETURN (0); END BEGIN RETURN (1); END END Thanks for any suggestions.
  10. Thanks, those links helped. I got it working. I don't know if I understand it 100%, but the web server needed to be to added to the Security Logins in SQL (using the SQL management tool). The login made is domainservername$ ($ included).
  11. Edit: I got it to work print and it prints what I put in the connection string.
  12. The thing is, is that it works when I run the page using Visual Studios. The connection string is called when I click the submit button. The submit button calls Button1_Click which calls ExecuteInsert, which creates a SqlConnection variable. That variable calls GetConnectionString and that is where the connection string is used.
  13. I'm not sure if you are asking something else, but I'm connecting to it using the connection string. I haven't setup a connection to the database anywhere else. Edit: It had initially confused me since it appeared to be using the server's name to log in. I wasn't exactly sure if that was happening, but if it is, what could be causing that?
  14. I replaced the actual names. The $ is after the name though.
  15. I created an asp.net webform that submits to an sql database on an sql server. The web server is Windows server 2012. The page successfully submits when I run the page using Visual Studio 2012, but when I run it on the web server (not using Visual Studios) I get the error message below when I click submit. It says login failed for user domainservername$, but the username in the connection string is user we created for the sql database. It uses Windows Authentication. I setup the web server for asp.net. I haven't done it before, so I assume the issue is there or in the connection string, though I'm not sure. The connection string is below. I'm new to asp.net, c#, and sql, so I'm learning as I go in this project. Let me know if you need anymore information. Thanks for any suggestions. <connectionStrings> <add name="MyConsString" connectionString="Server=sqlserver; Database=database; User Id=username; password=password; Trusted_Connection=Yes;" providerName="System.Data.SqlClient" /> </connectionStrings> Server Error in '/' Application. -------------------------------------------------------------------------------- Insert Error:Login failed for user 'domainservername$'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: Insert Error:Login failed for user 'domainservername$'. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [Exception: Insert Error:Login failed for user 'domainservername$'.] Survey.WebForm1.ExecuteInsert(EventArgs e) in servernamec$inetpubSurvey2Surveydefault.aspx.cs:489 Survey.WebForm1.Button1_Click(Object sender, EventArgs e) in servernamec$inetpubSurvey2Surveydefault.aspx.cs:39 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804
×
×
  • Create New...