broj1 356 Humble servant Featured Poster

Broj1, that qoute error..cannot put double qoute.. it show programming error..

What is the exact error message?

broj1 356 Humble servant Featured Poster

There is another way of doing this. Instead of constructing a html and setting the headers you could open a csv file for writing:

$result=mysql_query($sql) or die(mysql_error());
$fp = fopen('file.csv', 'w');
// fetch row as numerical array
while ($row=mysql_fetch_row($result)) {
    // you can set field and text delimiters (3rd and 4th parameter)
    fputcsv($fp, $row,',','"');
}
fclose($fp);

Then you could provide a link to the user to open / download the csv file.

See http://php.net/manual/en/function.fputcsv.php.

broj1 356 Humble servant Featured Poster

If you have only drop down boxes (select elements in HTML terms) in your table, you can assign this function to the checkbox's onclick event:

function selectAll {
    // read all select elements
    var selectArray = document.getElementsByTagname('select');
    // loop thorugh the select elements array
    for(var oneSelect in selectArray) {
        // if you want i.e second option be selected, use index 1
        oneSelect.selectedIndex = 1;
    }
}

You can enhance this function by checking whether checkbox is in checked state or not. If you have other select elements on the page, you can use div or class. The above code has not been tested, it is just an idea.

broj1 356 Humble servant Featured Poster

I think you do not need any php nor javascript code in the html document according to the instructions. If required fields
are missing, you will handle an error message in the process.php.

In the process.php file first check whether the required fields are there (use isset() and empty() functions as it is said in the instructions):

if(isset['book_title'] && !empty['book_title'] && isset['isbn'] && !empty['isbn'] {
    // process the data or do whatever you want here
    // ...
// if required fields are not present, then do whatever you want to handle the error
} else {
    // display error message, provide a link to get back to the form etc
}
broj1 356 Humble servant Featured Poster

The code seems to be OK. It can be a problem in that the query is not what you expect. Maybe you have already done this but if not put the following statement on line 27 and post here what it outputs:

die($sql);

broj1 356 Humble servant Featured Poster

I have not tried this but I think text fields should be put within text delimiters (usualy double quotes). Try changing your code this way:

$csv_output .= '"$row['misRefId']"' . ", ";
...

This way commas will be within double quotes as part of the text and wont be treated as a field delimiter. Be careful if you have double quotes in text. In that case you have to escape them.

broj1 356 Humble servant Featured Poster

Just to comment on the post by fobos above. If you use tc_tool.forms it is OK since this is mySql's notation of database_name.table_name or table_name.col_name. So tc_tools is probably a database name and forms is table name. Maybe tubesnube can confirm or correct me.

broj1 356 Humble servant Featured Poster

You can not use % wildcards if you use equals (=) operator. Wildcards (% or _) can be used only with LIKE statement. I suggested you use equal operator only if you are certain that doc_id is an integer not a string (or a complete string to match not just part of). In that case the query would be:

$searchById = "SELECT * FROM tc_tool.forms WHERE doc_id = $doc_id"; // $doc_id is and integer

or

$searchById = "SELECT * FROM tc_tool.forms WHERE doc_id = '$doc_id'"; // $doc_id is a complete string

That was just a suggestion. If you want to use wildcards then stick to your version:

$searchById = "SELECT * FROM tc_tool.forms WHERE doc_id LIKE '%$doc_id%'";
broj1 356 Humble servant Featured Poster

No worries, mate. It is important that your problem has been solved. This forum is kind a great :-)

broj1 356 Humble servant Featured Poster

Since I have to go I am posting a quick checklist for debugging:

$_GET['check'] array should contain array of the Codes you checked with checkboxes
$code_list should be a string of the same codes, separated by commas (it is created from $_GET['check'] array using implode() function)
SELECT query should use $code_list to select all rows that have selected codes (that is why you use IN statement). It should look something like SELECT * FROM books where Code IN (1100,1102).

To debug first inspect the $_GET['check'] array. You do this with print_r($_GET['check']) command. It should display something like Array ( [0] => 1100 [1] => 1102 )
When it is OK you can check the $code_list string that comes from the array. YOu use die($code_list) command for that. $code_list should be something like '1100,1101,1102'.
You can also inspect the query using die($query). You can copy displayed query nto phpmyadmin (look for SQL tab) and see if it return correct rows.

Hope that helps.

broj1 356 Humble servant Featured Poster

After the line that says:

$code_list = implode(',', $_GET['check']);

put the following code:

die(code_list);

and post here.

broj1 356 Humble servant Featured Poster

OK, we are back to the beginning. Please uncomment the following line:

// print_r($_GET['check']);

and post what you get.

One more thing: I am leaving in 35 minutes and will not be availabel for 3 - 4 hours.

broj1 356 Humble servant Featured Poster

Your notepad++ should warn you about this error.

broj1 356 Humble servant Featured Poster

You are missing double quote at the end of the following statement:

$query = "SELECT * FROM books where Code IN (1100,1102);

It should be:

$query = "SELECT * FROM books where Code IN (1100,1102)";
broj1 356 Humble servant Featured Poster

Then why is it now different error. Can you post the last version of order.php.

broj1 356 Humble servant Featured Poster

This error is completely different now:

Parse error: syntax error, unexpected '>' in C:\xampp\htdocs\xampp\onlinebookstore\order.php on line 19

What IDE / editor do you use? It should show you the error in syntax. Have you misstyped something?

broj1 356 Humble servant Featured Poster

Also do you use phpmyadmin or other client to accesss the database? Try to test the following query and post what it returns:

SELECT * FROM books where Code IN (1100,1102)
broj1 356 Humble servant Featured Poster

Please uncomment the following line again and post the output:

// print_r($_GET['check']);

This array should contain values from checkboxes or an error message from the query.

broj1 356 Humble servant Featured Poster

Make sure the line print_r($_GET['check']); in order.php is commented like this:

// print_r($_GET['check']);

Go back to the page home_order.php, select some checkboxes and submit.

broj1 356 Humble servant Featured Poster

Comment out the lines you uncommented for debugging (they are there just for debugging):

die($query);

and

print_r($_GET['check']);
broj1 356 Humble servant Featured Poster

The error is probably in home_order.php just before the end of while loop on line that says:

echo '<td align=center><input type="checkbox" name="check[]" value="';
echo $row['code'] . '" ></td>';

It should be:

echo $row['Code'] . '" ></td>';

It is better to use all small caps for field names otherwise the errors like that pop out (it was actually my error since I did not know the table structure).

broj1 356 Humble servant Featured Poster

So the error seems to come from previous script. Can you post both scripts (the one with the table and the order.php) and tell me what is the name of the first script.

broj1 356 Humble servant Featured Poster

$code_list is a string of codes and should get constructed from the $_GET['check'] array by implode function. So we have to check what the array is. Uncomment the following line in order.php:

// print_r($_GET['check']);

and post the output (firstselect a fewcheckboxes).

broj1 356 Humble servant Featured Poster

The following line is returning false instead of a resource (ponter to rows):

$result= mysql_query($query);

This means that there is an error in the query in order.php. You have to display the query and post it here. Uncoment the line that says:

// die($query);

refresh the page and post the output (your query);

broj1 356 Humble servant Featured Poster

Here you have your main file and order.php file. Read the comments since most of explanations are there. Main thing is that checkbox name attribute was changed to an array and value was added to each checkbox so you know which codes were selected. I assumed that code is an integer. If it is a string then you must add single quotes otherwise you will get db error.

This is your table with checkboxes:

<?php
// I have wrapped all HTML attributes in double quotes so you do not run into problems

// added html, head and body tags
echo '<html>';

// this line goes to head section
echo '<head><link rel="stylesheet" type="text/css" href="design.css" /></head>';

include("connect.php");

echo '<body>';
echo '<form method="GET" action="order.php">';
echo '<center><img src="top.png"></center>';

$result= mysql_query("SELECT * FROM books");

echo '<div><table border="0" cellspacing="15" align="center" id="home_orde"r>
<tr>
<th>Code</th>
<th>Title</th>
<th>Price</th>
<th>Stock</th>
</tr>';

while($row = mysql_fetch_array($result)) {

    echo "<tr><td align=center>" . $row['code'] . "</td>";
    echo "<td align=center>" . $row['Title'] . "</td>";
    echo "<td align=center>" . $row['Price'] . "</td>";
    echo "<td align=center>" . $row['Stock'] . "</td>";

    // I have changed the name of checkbox to check[] array and added a value
    // that equals the code, so you know which checkbox was selected
    // I have also wrapped HTML attributes in double quotes
    echo '<td align=center><input type="checkbox" name="check[]" value="';
    echo $row['code'] . '" ></td>';
}
echo"</table></div>";
echo"<table border=0 cellspacing='15' align=center >";
echo"<td align=center>"."<input type=SUBMIT>"."</td>";
echo '</body></html>';
?>

This is order.php:

<?php
// if there were any checkboxes selected, they will be returned …
broj1 356 Humble servant Featured Poster

Just to be sure: You have a table where each row represent a code and each row has a checkbox. When user selects some checkboxes you would like to diplays information for selected rows based on code. Did I get it right?

It would also help if you post the whole script that displays the table with checkboxes. And use formating in the editor (i.e. select the code and click on the Code button).

broj1 356 Humble servant Featured Poster

Do you get any error messages? If yes post them here.

Also display the query and check it in phpmyadmin (or post it here). Change your code to something like:

$query = "SELECT * FROM books where Code='$code'";
// this will display the query so you can check it
die($query);
$result= mysql_query($query);
broj1 356 Humble servant Featured Poster

You are probably missing an assignment to a variable $doc_id (put it on line 22) just before you construct $searchById, like:

$doc_id = $_POST['searchID']

And if $doc_id is a number (integer) you could use = instead of LIKE in your query.

broj1 356 Humble servant Featured Poster

jQuery you use also supports ajax. See http://api.jquery.com/jQuery.ajax/. That's the most I can suggest since I am not too familiar with jQuery.

broj1 356 Humble servant Featured Poster

And another question: is it OK that all the id_no values are the same?

broj1 356 Humble servant Featured Poster

In your insert query there is a comma (",") missing after the second set of values which probably breaks your query (see below).

INSERT INTO system.grades
(id_no ,course ,semester ,year ,subject ,descriptive_title ,final_grades ,remarks)
VALUES 
('003', 'cs', 'second', 'second', 'cs', 'prog', '2', 'pass'), 
('003', 'cs', 'second', 'second', 'java', 'prog', '2.1', 'pass')
('003', 'cs', 'second', 'second', 'vb', 'prog', '2.3', 'pass'), 
('003', 'cs', 'second', 'second', 'C++', 'prog', '2.4', 'pass');

Can you please post the array $new so I can have a look at it. Place this code before if (count($new) > 0) line and post the output:

die(print_r($new, 1))
broj1 356 Humble servant Featured Poster

Your insert query has to be checked if it is OK. Put this code before theif ($query) statement:

die($query);

This will display your final query and stop the script. Please post the displayed query here (and then remove the above die statement).

broj1 356 Humble servant Featured Poster

As I said I would do it like this (it is cleaner and safer and less chances for mistakes):

// assign $value array to variables, you can also do some cleaning here
if(isset($value['subject']) && 
   isset($value['subject']) && 
   isset($value['subject']) && 
   isset($value['subject'])) {

    $subject = $value['subject'];
    $descriptive_title = $value['descriptive_title'];
    $final_grades = $value['final_grades'];
    $remarks = $value['remarks'];
    $is_error = false;
} else {
    $is_error = true;
}
if($is_error) {
    die('ERROR: values missing!');
}
$new[] = "('$course', '$semester', '$year', '$id_no', '$subject', '$descriptive_title', '$final_grades', ' $remarks')";
broj1 356 Humble servant Featured Poster

What is the error?

broj1 356 Humble servant Featured Poster

I prefer to construct statements this way since it is easier to debug:

> $new[] = "('$course', '$semester', '$year', '$id_no', '$value[\"subject\"]', '$value[\"descriptive_title\"]', '$value[\"final_grades\"]', ' $value[\"remarks\"]')";

And also you better check for the values in the $value array and assign them to variables (and possiblly clean them):

if(isset($value["descriptive_title"])) {

    $descriptive_title = $value["descriptive_title"];
}
broj1 356 Humble servant Featured Poster

Do the classic trick: insert die(query) after the $query = mysql_query("INSERT INTO grades ... statement and inspect whether the query is OK. Test it in phpmyadmin (or post it here).

broj1 356 Humble servant Featured Poster

This is because you have a return statement within a foreach loop so the loop gets executed only once. Try this way:

function t6($table)
{
    $rows = '';

    foreach ($table as $key => $value) {

        $rows .= "<tr><td>$key</td><td>$value</td></tr>\n";
    }

    return $rows;
}
broj1 356 Humble servant Featured Poster

I copied your code and the value of gender displays OK (if you chose one). Put a break after it in php file to make it more visible

echo "You are: $genderRadio<br />";

If the gender still does not get displayed print the whole $_POST array and see what it says (you can post the output here). Put this line in the beginning of the php file:

print_r($_POST);
broj1 356 Humble servant Featured Poster

I use TCPDF library (http://www.tcpdf.org/). It is being actively developed, has examples, it works and it is free.

broj1 356 Humble servant Featured Poster

I suggest you echo the query to see whether it is what you are expecting. Modifiy the part where you construct the query like this:

// put the query in a variable
$q = "UPDATE books SET Title ='$title_save', Price ='$price_save', Stock='$stock_save' WHERE Code= '$code'";

// submit query using the variable
mysql_query($q) or die(mysql_error(); 

// add this to display the query
die($q);

Now you will be able to see if the query gets constructed OK and you can copy it to phpmyadmin or mysql client and test it.

Two other notes:

  1. your form has no </form> tag. It should be after </table> tag.
  2. your form is missing an action attribute (I think it is required)
broj1 356 Humble servant Featured Poster

To add my 2 cents: I have been using Linux desktop at work and at home for about 4 years now. At work we switched to Fedora desktop and server after not receiving usable support from Microsoft for Windows SBS when we had problems (support was paid for). We had some Linux experience already and a moving all the production was not that hard. At home I also installed Ubuntu on 3 laptops and even my wife has been using it for a couple of years and never complained. For a year or so I have been completelly freed from Windows. The last applications I moved to Linux were the ones I use for music making at home: Wavelab was replaced by Audacity and Cakewalk was replaced by Rosegarden. For long time I have been using Gimp, Inkscape, Open/LibreOffice, Eclipse, VirtualBox, Kontact, K3B, VLC, Kdenlive and tons of other opensource software (that costs zero). Very rarely I have to hack arround the system since most things work out of the box nicely (Wifi, Bluetooth, LAN, sound, camera etc.).

broj1 356 Humble servant Featured Poster

To keep a lang setting in a session seems OK for a session duration, to store it as a preference, put it into a database or a file. But back to your problem: do you have anywhere in your script(s) the session_start() command? It is required on every page for sessions to work.

broj1 356 Humble servant Featured Poster

In the included file check whether the data (and database) exist and if not add records (otherwise do nothing). Or in your primary fle check whether the data exists and if not then include the file.

broj1 356 Humble servant Featured Poster

Sorry, I was away for a week and this was my mistake; correct code is (enclose array element in curly braces):

echo "<p>Topic: {$row['topic']}, Auhor: {$row['author']}, Date: {$row['date']}</p>";
broj1 356 Humble servant Featured Poster

This is i.e enter_name.html with a form containing a text input element and a submit button

...
<form method="post" action="show_name.php">
<input type="text" name="entered_name" />
<input type="submit" name="submit" value="submit">
</form>
...

This is show_name.php that receives the post data and displays it; specific file is in the action of the form, specific div is below.

if(isset($_POST['entered_name'])) {

    echo '<div id="myname">';

    echo $_POST['entered_name'];

    echo '</div>';
}

This is basics, there is much more to it in practice (security, handling errors, some useful functionality etc)

broj1 356 Humble servant Featured Poster

The following is a script I named table.php that displays rows with topic, author etc.

<?php
$con=mysql_connect("localhost","root","");

if(!$con) {

   die('can not connect'.mysql_error());
}

mysql_select_db("scms", $con );
$show_others="show_others";
$sql = "select * FROM $show_others";
$result=mysql_query($sql);
$num = mysql_num_rows($result);

// moved form tag here so the table is properly nested
// action is set to another page (confirm_save.php)
echo '<form name="form1" method="post" action="confirm_save.php">';

echo"<table border='1' width='100%' id='table1'>";
echo"<thead>
    <tr><th>#</th><th>topic</th><th>author</th><th>date</th>
    </thead>";
echo"<tbody>";

while( $row = mysql_fetch_array($result))  {
    echo"<tr>";
?>

<td> <input name="radio[]" type="radio" id="radio[]" value="<?php echo $row['id']?>"> </td>
<td ><?php echo $row['topic']; ?></td>
<td ><?php echo $row['author']; ?></td>
<td ><?php echo $row['date']; ?></td>

<?php
   echo"</tr>";
}

echo"</tbody>";
echo"</table>";
?>

<input name="save" type="submit" id="save" value="save">
</form>

<?php

mysql_close($con);

?>

When radio button is clicked it is submitted to the next page confirm_save.php which also has a form (for buttons to save or cancel).

<?php
// this script will get the form data through POST and ask user for confirmation
// if confirmed it will save the record otherwise it will redirect to the page
// POST was sent (I call it table.php)

// if this form (on this page) was submited with save button
// save the record and redirect back
if(isset($_POST['save']) and isset($_POST['id'])) {

    $id = $_POST['id'];

    $sql = "INSERT INTO others_2 VALUES SELECT FROM show_others WHERE id=$id";

    header('location:table.php');
    exit();
}

// if this form (on this page) was submited with cancel button
// only redirect back
if(isset($_POST['save'])) {

    header('location:table.php');
    exit();
}

// check if radio button has been submitted from the …
broj1 356 Humble servant Featured Poster

Correct me if I did not understand OK:

  1. you want to display a table where each topic, author and date are one row
  2. each row has a radion button
  3. the user clicks one of the radio buttons to select the record to be saved (only one can be selected in a table)
  4. when user clicks on the save button then you want to save that record

How do you want the save to occur:

a. when user clicks on Save the topic, author and date are displayed on a new page with save button and the user has to click save button to actually save the record
b. when user clicks on the save button the record is saved and no new page is displayed (the page with the table remains open)
c. any other option

broj1 356 Humble servant Featured Poster

Sorry, I do not get it. Can you explain a bit more (what is displayed and what are user actions).

broj1 356 Humble servant Featured Poster

Do you want to print topic and author and date on the same page or on another page?

broj1 356 Humble servant Featured Poster

First move the beginning form tag (line 30) out of the while loop. It should be before the <table> tag, just after line 12.

The rest is similar to your previous post. If show_others_0.php script is another page (not this one) then you will process POST data there. First check if $_POST['save'] exists. If yes then the user has clicked the save button; insert the record and redirect to previous page. If $_POST['save'] does not yet exist check if $_POST['radio'] existst (comming from the previous page) and if it yes, display the other fields from the $_POST array. The code for show_others_0.php should be something like (not tested):

// check if the save button was pressed and if yes save the record and go back to previous page
if(isset($_POST['save']) and isset($_POST['id']) {

    $sql = 'INSERT INTO ... SELET * FROM   ... WHERE id=$id';

    // submit the query
    ...

    // go to previous page
    header('location:prev_page.php');
    exit;
}

// if no data in $_POST['radio'], print error message and exit
if(!isset($_POST['radio'])) {

    die('Nothing was selected!');
}

// to be safe force the value to be integer
$id = (int) $_POST['radio'];

// display the data by reading it from the database (you could also have it posted through the POST using hidden fields)
$sql = SELECT topic, author, date FROM ....;
// read the data and store it in variables
$topic = ...
$author = ...
$date = ...

// display the data
echo ...

// display the form
echo '<form>';

// put ID …