|-|x 126 Junior Poster in Training

I can't see anything specifically wrong with the code you have posted. My suggestion would be to try using a StreamWriter, take a look at File.AppendText - this method opens the file once and closes it at the end, rather than open-closing for each line written. The excessive file handling operations may be causing a problem for you, and the StreamWriter will be more efficient in any case.

Also, just had the thought that the Delete of file 2 might be happening before the ReadAllText has finished handling the file. You might try removing that line to test, or adding a delay in before it.

|-|x 126 Junior Poster in Training

It sounds like a file pointer still pointing to the first file, while you are trying to move it further through the second file (possibly before it is appended to the first). If you are able to post code I could probably be more specific?

|-|x 126 Junior Poster in Training

You just need to remove the comma from line #2. JOINs don't need to be separated by commas the way a table list is.

|-|x 126 Junior Poster in Training

@Rahul47

If a subquery returns more than one row it needs to be compared via IN as = will throw an error.

SELECT * FROM form1 f1, form2 f2
WHERE f1.k8regNo IN ( SELECT f2.form2_ID FROM form2 f2, form4 f4
                 WHERE f2.form2_ID IN ( SELECT f4.form2_ID FROM form4 f4, form3 f3
                                      WHERE f4.k9regNo=f3.k9regNo));

However, subqueries are also an extremely inefficient way of doing this.

Also, re your last post, it is not poor practice not to specify the conditions of a join for readability sake (particularly if she is learning).

@sagisgirl

An updated version of my last example with all tables included:

SELECT * 
FROM form1 t1
JOIN form2 t2 ON t1.k8regNo = t2.k8regNo 
JOIN form4 t4 ON t2.form2_ID = t4.form2_ID
JOIN form3 t3 ON t4.k9regNo = t3.k9regNo 
ORDER BY moveDt

This will return a dataset of all tables joined without filtering of any kind. Without knowing more about the data and the purpose of the query it is impossible for me to make recommendations about the types of joins to use, or other criterea (the resultant dataset may be quite large).

|-|x 126 Junior Poster in Training

OK @sagisgirl

Have a read of that article I linked in my last post, its the mysql man page for proper join statements.

As an example, the query you posted could be written like this:

SELECT * 
FROM form1 t1
JOIN form2 t2 ON t1.k8regNo = t2.k8regNo 
-- more joins can be added here...
ORDER BY moveDt

NOTE: the type of join (INNER, LEFT, RIGHT) will affect the result set, so check what they do in the man article to decide which type you need. Or you can try them to see the difference.

|-|x 126 Junior Poster in Training

Looks to me as though they join like this:

form1.k8regNo <- form2.k8regNo
form2.form2_ID <- form4.form4_ID
form4.k9regNo <- form3.k9regNo

Does this sound about right?

Do you know how to write joins in SQL?

|-|x 126 Junior Poster in Training

Fpdf will work without any external references, it can create the pdf document without having a reader installed. Probably your browser is trying to display the pdf after it's created and that is what is causing it to try to download the reader.

|-|x 126 Junior Poster in Training

Because id_buku is being compared to a string value, which is ok. The table name fk_00_m_buku is not a string, and if you were to add limits to this query they need to be integers not strings.

In the previous query you were creating the table name and limit values as strings, which wont work. String values for comparison (WHERE clause) do need to have quotes.

I feel like maybe I'm not explaining this clearly enough, but not sure how else to put it. You need to take a look at the result SQL query of those you are producing so that you can better see the differences.

your initial query

$table = "t_book";
$start = 1;
$amount = 15;

$sql = "select * '".$table."' limit '". $start ."' , '". $amount ."'";

echo $sql;

//output result is...
select * 't_book' limit '1' , '15'

//Correct syntax should be...
select * from t_book limit 1 , 15

second example

$id_book = "A";

$sql = "select * from fk_00_m_buku where id_buku='". $id_book ."'";

//output is OK ...

select * from fk_00_m_buku where id_buku='A';

NOTE

This second query is treating the book_id as a string, if this is supposed to be a number (is an integer in the database) MySQL is capable of implicitly converting '1' to 1 for the comparison - however, it is better practice to not use quotes and pass the value as an integer yourself.

You only need to use quotes ' when you …

|-|x 126 Junior Poster in Training

You don't need single quotes around your variables inserted in the sql string - there weren't single quotes in the original, and adding them makes the table name and limiters string values.

Echo your sql string to the page so you can see it and copy/run it manually to check that it works.

|-|x 126 Junior Poster in Training

Have a read of the MySQL Join documentation, specifically the section that covers Left/Right joins.

What I would use here is a LEFT JOIN which allows the parent record (ie: dealer_item) to be shown with a null record where no data exists in the child record (dealer_product). More left join can be used to add more "optional" child tables to the query in the same way.

Have a go at rewriting the joins and I can help further if you have trouble with syntax or anything.

|-|x 126 Junior Poster in Training

mysql_query returns a resource datatype on success, which is not simply printable like you are trying to do.

You need to call either mysql_fetch_array or mysql_fetch_assoc passing the $result to that function, which will return each row as an Array structure that can be iterated and printed as any typical array.

Example:

$sql = "Select FirstName from Person Where LoginID = (Select LoginID from UserLogin Where Username = '$username')"

$result = mysql_query($sql,$con);

while ($row = mysql_fetch_assoc($result)) {
    echo $row["FirstName"];
}
|-|x 126 Junior Poster in Training

Is that your entire css? You haven't specified any other margin or float values or anything for other elements?

|-|x 126 Junior Poster in Training

Beginnerdev is correct in saying this:

txtRoomComment.text.

If there is a ' character present in that field, you would have been terminating the sql statement

In addition to the syntax changes above, you should apply some parsing/checking for characters that may break your sql. This can be done with a simple Replace but there are several characters that may have adverse affects. It is common to have a function that prepares string / user input data for database insertion, which handles this type of thing.

|-|x 126 Junior Poster in Training

Can you post your table structure. There is obviously something not quite right.

RE: your original method

WHEN I PUT THE ExecuteNonQuery inside the try block i get SYNTAX ERROR IN INSERT INTO STATEMENT

That is what I would expect to see since your SQL is a bit off.

"@Amt/Day" is set as a text feild

The datatype is not relevant, @Amt/Day is not a valid parameter name, you need to remove the slash: ie @AmtDay

When i remove the the blocks from the column i get SYNTAX ERROR IN INSERT INTO STATEMENT

Thats because you need the square brackets.

The following are sytax errors in your INSERT SQL;

  1. you can't have spaces in column names without them, or the SQL will think they are separate fields or aliases and wont match the actual column names.
  2. you can't have spaces or special characters in parameter names.
  3. you don't need to quote ' the parameters as they are already of the appropriate datatype. You have quoted the whole lot which will try to insert a single literal string instead of the parameter values.

You're corrected SQL is:

cmd.CommandText = "INSERT INTO Rooms ([RoomID], [First Name], [Middle Name], [Last Name], [Room Type], [Amt/Day], [Comments]) VALUES (@RoomID, @FirstName, @MiddleName, @LastName, @RoomType, @AmtDay, @Comments)"
|-|x 126 Junior Poster in Training

Also, you will need to block the column names in your insert statement as you had done previously in the commented out line, ie: INSERT INTO Rooms (RoomID, [First Name], [Middle Name], [Last Name], [Room Type], [Amt/Day], Comments) VALUES ...

That's what I can see from a quick glance over your code. If you try these changes and then provide any error messages still received I/someone will help further.

|-|x 126 Junior Poster in Training

What is the error?

Also, why is the execute not inside the try block?

I'm going to take a stab in the dark here and guess that your issue has something to do with having a slash in your parameter name "@Amt/Day" - try removing that and see what happens.

|-|x 126 Junior Poster in Training

I agree with diafol, if you truncate the table and keep the modified schema, then re-import the file into that table it should work.

|-|x 126 Junior Poster in Training

Did you specify column types or let it auto generate? Can you post the table schema?

|-|x 126 Junior Poster in Training

I believe it is your logout button.

<a href="index.jsp" id="btnLogout" onclick="<%session.invalidate();%>">Logout</a>

It is a while since I've worked in jsp, so someone may correct me, but I believe this is executing the session.invalidate() function and printing the result into the javascript onclick call. You are not able to use javascript events to call server side functions in this way.

To test if this is correct, remove temporarily remove the logout button (or at least the call to session.invalidate) and try to run the page again.

Have a look at this post or google for how to call server side code from a hyperlink. But I think you will have to post the request to the server in order to achieve the functionality you require. I don't believe it can be done inline as you are trying to do.

|-|x 126 Junior Poster in Training

You can do it all in the loop if you handle the parameters properly.

private void autofillyr(int incrementBy, int maxyr, int no_year)
{
   for (int i = no_year; i < maxyr; i += incrementBy)
   {
       year.Items.Add(new ListItem(i.ToString(), i.ToString()));
   }
}

and the function call...

protected void Page_Load(object sender, EventArgs e)
{
    ...
    autofillyr(1, 2050, 1900);
}

actually, i repurposed your no_year parameter as start year since it is unclear what the purpose of this parameter is.

I would susggest doing the days function the same way since

if (incrementBy <= max) // this line is irrelevant

try...

private void autofilldate(int incrementBy, int max) //don't need `itemcount`
{
    for (int i = 1; i < max; i += incrementBy)
    {
        day.Items.Add(new ListItem(i.ToString(), i.ToString()));
    }
}

You haven't posted your month function, but it can be done the same way. In fact you could use the same function to fill all 3 dropdowns (as per the Year function I just posted) call them with appropriate start, max, and increment values, just pass the dropdown itself as another parameter. I would also make the increment an optional parameter with default of 1.

|-|x 126 Junior Poster in Training

have a look at these pages for various server packages (including links).
https://en.wikipedia.org/wiki/List_of_AMP_packages
https://en.wikipedia.org/wiki/Comparison_of_WAMPs

|-|x 126 Junior Poster in Training

Great! No worries, glad I could help. Can you make this thread as solved please? thx

|-|x 126 Junior Poster in Training

the comparison you have should tell you the exact matches (though you are missing ;'s off the end of lines 5 & 8 (javascrip is a little forgiving if its the last line in a block).

You will have to have a nested loop to do the "correct but in wrong place" check.

Are you able to post any more code, the snippet posted above is obviously only a portion and it would be easier to help spot the issue if you can provide the whole function.

|-|x 126 Junior Poster in Training

you're missing a brace so the for loop will always return on the first iteration.

    for(index = 0; index < length; index++){
        if(array1[index] == array2[index]){
            count++
        }
    } //<-- add this brace and see if that fixes it.
    return count
}
jenny1975 commented: thank you for your help +0
|-|x 126 Junior Poster in Training

I fixed it manually by inserting a div at the point I mentioned before. But effecting the appropriate styling to container div should also do it.

Update - Confirmed, container doesn't seem to be loading the styles (firefox & chrome checked). Maybe change the name to see if it's a conflict with jQuery as TonyG suggests, would appear to be the case at this point.

|-|x 126 Junior Poster in Training

It's appearing left aligned because tou have float:left on the divs primary, content and secondary. If you wrap these 3 divs in another div with margin:0 auto as TonyG said, it should center the lot.
Edit You also need to specify a width on that wrapper div or it will default to 100% and the centering effect will be moot.

|-|x 126 Junior Poster in Training

Try setting padding: 0 on your UL element.

It's common practice to use a "reset" css (either one downloaded from the net or a custom one) to set some global initialisation values such as zero padding margin and border for all elements. This may be something you could look into as it overrides the default values that some elements carry which I think is the source of your issue.

|-|x 126 Junior Poster in Training

You will need to populate the tbl_cat first. (I am going to assume your id fields for both tables are auto_increment)

INSERT INTO tbl_cat (category) VALUES ('Accessories');

The easiest way to do the child table insertions is to manually check the id generated in the previous table.

SELECT * FROM tbl_cat;
+----+-------------+
| id | category    |
+------------------+
| 1  | Accessories |
+------------------+

You can then use this id in the foreign key field for your child table insert like so...

INSERT INTO tbl_subcat (catid,subcat) VALUES (1,'some subcat');
INSERT INTO tbl_subcat (catid,subcat) VALUES (1,'another subcat');
|-|x 126 Junior Poster in Training

Do you want to know how to add the actual foreign key constraint? or how to manage the data insertion?

|-|x 126 Junior Poster in Training

You will need to check the POST variable to see if a user has been selected, then make an additional call to the database to fetch the related data.

I have also added a javascript call to automatically post the form when the dropdown is selected.

It will probably be easier if you move your <select> tags inside the php code. Then you will be able to print out the other data outside of the dropdown, as per below example.

<form id="userform" method="post" action="drop.php">

    <?php

        $mysqlserver="localhost";
        $mysqlusername="root";
        $mysqlpassword="";
        $link=mysql_connect(localhost, $mysqlusername, $mysqlpassword) or die ("Error connecting to mysql server: ".mysql_error());
        $dbname = 'members';
        mysql_select_db($dbname, $link) or die ("Error selecting specified database on mysql server: ".mysql_error());
        $myquery="SELECT username FROM members";
        $myresult=mysql_query($myquery) or die ("Query to get data from members failed: ".mysql_error());

        echo '<select id="user" name="user" onchange="document.forms[\'userform\'].submit();">';

        while ($row=mysql_fetch_array($myresult)) {
        $user=$row[username];         // NOTE: username should be in quotes here.
            echo "<option>
                $user
            </option>";
        }

        echo '</select>';

        if (isset($_POST['user'])) {
            $r = mysql_query("SELECT password, email FROM members WHERE username='".$_POST['user']."'") or die ("Unable to get user details: ".mysql_error());
            while ($row=mysql_fetch_array($r)) { // there should only ever be 1 result
                // display the data however you want, add some HTML tags to format nicely.
                echo $row['password'];
                echo $row['email'];
            }
        }

    ?>
</form>

Please note that the above code is not tested, but should give you an idea of how to proceed.

Also, it is bad practice to use a POST variable directly in a query string (as I have done here) without parsing it for …

|-|x 126 Junior Poster in Training

sorry mate, still not sure I understand your problem correctly.

so the dropdown determines the column you want to sum? if that is the case you need to build your query dynamically.

$sql = 'SELECT SUM('.$_POST['select'].') FROM table';
|-|x 126 Junior Poster in Training

do you mean group or filter?

if you want to total the values that match the dropdown selection only then you want something like this:

SELECT SUM(col1) FROM table WHERE col2 = 'dropdownvalue'
|-|x 126 Junior Poster in Training

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

What are you trying to group, what does your data look like?

The basic format is

SELECT SUM(col1) FROM table GROUP BY col2
|-|x 126 Junior Poster in Training

is there a way of incorporating shell commands like PING into a T-SQL procedure?

Yes. This page has a demonstration of such.

However, let it be said that shell access via SQL is regarded as a high security risk and is often disabled, so it will depend on your level of access to the server whether you will be able to use those system procedures or not. Also, just because you can doesn't mean you should... if it is the only workable solution, then just make sure you and your team/admins know what it's doing and have some configuration & monitoring in place to ensure the system access is protected.

|-|x 126 Junior Poster in Training

No worries. Doesn't look like your comment stuck, but thanks and glad I could help.

|-|x 126 Junior Poster in Training

correcting my code because apparently I'm dyslexic...

md5($email);

etc... not mdf

can't believe I posted that wrong through that whole thing and didn't even notice ... <facepalm/>

|-|x 126 Junior Poster in Training

I will give you a really basic example of how this might work. Take a look at the md5 hash function.

This function will generate a hash (using the md5 algorithm) from any string you provide, the hash will always be the same given the same input string. For instance, 'user@hotmail.com' will always produce the hash '7b928f8a1884fc44709e0b17ec65228c'

So your registration page would include something like this:

$email = $_POST['email']; // get the users email address from the form post
$hash = mdf($email); // generate the hash code
$link = "http://mydomain.com/confirm.php?email=".urlencode($email)."&hash=$hash"; // include the hash code in link to email to user

You then send the email to the registered address with the generated link, and the user must click on the link to confirm their valid email address. The confirm.php page will then check the hash code.

$email = urldecode($_GET['email']); // grab the email & hash code from URL
$hash = $_GET['hash'];
if (md5($email) == $hash) { // check if the hash code matches
    // successfully validated
    // add email to registered user list here...
} else {
    echo "invalid registration";
}

---

Note that md5 is a common algorithm and you may want to vary you hash output by adding something unique of your own to it so that people can't generate their own hash codes to manipulate or bypass the registration system. This is called Salt and is generally a fixed or random string that you add to your data …

|-|x 126 Junior Poster in Training

The way email validation usually works is to have a unique key or hash that is sent to the email, and then passed back to the webpage when the user clicks on the link. The web page then needs to identify that the hash is the same as that which was generated for that email, the storage mechanism is largely irrelevant to this process.

You could for instance, store the hash together with the email in a flat file.

newuser@hotmail.com=GENERATEDKEYHASH
...

Or you could generate the hash based on the email address itself, so that the confirmation page will recreate the hash from the email and it must match the originally created hash to verify. This way you don't need to actually store the hash at all.

|-|x 126 Junior Poster in Training

You need to set up your mail to be a multi-part MIME message, which means you need to generate boundaries and MIME headers for each section (message & attachments) as well as an overall/outer header. Additionally, non-text files (binary files) such as pdf's or images should be base64 encoded so they do not become corrupted when transmitted.

Here are the mail functions I wrote and use, which work fine for me sending attachments or using inline images etc.

function mime_attach($content,$filename,$format="text/plain",$encode=0,$embed=0) {
   $mime = "Content-Type: $format; \n"
         . ($encode?"Content-Transfer-Encoding: base64\n":"")
         . "Content-Disposition: ".($embed?"inline":"attachment")."; filename=\"$filename\"\n"
         . "Content-ID: <$filename>\n\n"
         . ($encode?base64_encode($content):$content)."\n";

   return $mime;
}

function send_mail($to,$message,$subject,$format="plain",$attach="",$priority=0) {
   $boundary = "==allyourbasearebelongtous==";

   $headers  = "From: \"Altiora Martial Arts\" <noreply@altiorainsurance.com.au>\n"
             . "Reply-To: <martialarts@altiorainsurance.com.au>\n"
             . "MIME-Version: 1.0\n"
             . "Content-Type: multipart/mixed; boundary=\"$boundary\"";
   if ($priority) $headers .= "X-Priority: 1 (Highest)\n"
                           .  "X-MSMail-Priority: High\n"
                           .  "Importance: High\n"; 

   $message = "--$boundary\n"
            . "Content-Type: text/$format; \n"
            . "Content-Disposition: inline\n\n"
            . "$message\n";

   if (is_array($attach))
      foreach ($attach as $item)
         $message .= "--$boundary\n".$item;
   else if ($attach!="")
      $message .= "--$boundary\n".$attach;

   $message .= "--$boundary--\n";

   mail($to, $subject, $message, $headers);
}

Example usage:

$message = "Test message. <br/>This can include HTML formatting."

//repeat this line for multiple attachments.
$atts[] = mime_attach(file_get_contents("./example.pdf"),"example.pdf","application/pdf",1);

send_mail("recipient@email.com",
        $message,
        "Test Email Subject",
        "html",
        $atts);
|-|x 126 Junior Poster in Training

function substr

|-|x 126 Junior Poster in Training

ah, ok... your dropdown is inside a gridview, which I assume means you have a list of Locations the user can select from, and the parent records will display the selected Location they have been saved with. (hopefully that makes sense).

If so, this is going to be a 2 stage process:
1 - bind the dropdown to the list of items (which will be its own query/dataset, and databound as I described above)
2 - bind the selected item to the current record in the gridview.

|-|x 126 Junior Poster in Training

I haven't tested this, but it should give you an idea of how to modify your existing loop to include the page breaks.

$db_results = $wpdb->get_results("SELECT * FROM table");

$counter = 0;
foreach ($db_results as $result) {
    if ($counter % 40 === 0)
        echo '<table><thead><th>Name</th><th>Number</th></thead><tbody>';

    echo '<tr>';
        echo '<td>' .$result->name. '</td>';
        echo '<td>' .$result->number. '</td>';
    echo '</tr>';

    $counter++;
    if ($counter % 40 === 0)
        echo '</tbody></table>';
}
echo '</tbody></table>';
|-|x 126 Junior Poster in Training

... Al... that syntax is for UPDATE statements, not INSERT

|-|x 126 Junior Poster in Training

@bonsoirval you're right, but that assumes he's specifying values for all columns in the table, in the order they appear in the table schema.

|-|x 126 Junior Poster in Training
|-|x 126 Junior Poster in Training

you have told it to be 1 pixel wide... it needs to be something like width:100%

|-|x 126 Junior Poster in Training

Insert syntax is wrong

INSERT INTO table_name [(column_names, ...)] VALUES (value [, values...])

In other words

INSERT INTO leads (`facility`, ...) VALUES ('{$facility}', ...)
|-|x 126 Junior Poster in Training

you need to add a width property, else it defaults to zero.

|-|x 126 Junior Poster in Training

try abs positioning the hr

also, there is an extraneous </p> in there.

|-|x 126 Junior Poster in Training

Try changing from INNER JOIN to LEFT JOIN as your filter is on the left hand table.