broj1 356 Humble servant Featured Poster

Had a quick look at it and one of the videos. Seems to be a nice piece of work but haven't figured out why would it be better to use than PDO. Nevertheless, let's not steal hanspeares thread. Hopefully I'll find some more time to test your class sometime in near future.

broj1 356 Humble servant Featured Poster

Post the table structure and complete error message (see my post above).

reply

Please be patient if people don't have time to reply immediately :-)

broj1 356 Humble servant Featured Poster

I hope I understood OK what you want. I suggest you do it as a single unordered list and use css styling (classes) to handle indent. I am posting an example with code for complete page so you can see what I mean. You can adapt CSS to suit your taste. Note that I removed the GROUP BY clause form the query (otherwise you can not display all the posts).

<!DOCTYPE html>
<html>
<head>
<style>
li.cl-year {list-style-type: none; font-weight: bold; margin-left: 0; width: 90%; background-color: silver;}
li.cl-month {list-style-type: none; font-weight: normal; margin-left: 1em;}
li.cl-posts {list-style-type: none; font-style: italic; margin-left: 2em;}
</style>
</head>
<body>
<h1>Archives</h1>
<hr />
<ul>
<?php
$stmt = $db->query("SELECT Month(postDate) as Month, Year(postDate) as Year,
postTitle, postSlug FROM blog_posts_seo ORDER BY postDate DESC");

// you will store current month here to control when the month changes
$currentMonth = 0;

// you will store current year here to control when the year changes
$currentYear = 0;

while($row = $stmt->fetch()){

    // if the year changes you have to display another year
    if($row['Year'] != $currentYear) {

        // reinitialize current month
        $currentMonth = 0;

        // display the current year
        echo "<li class=\"cl-year\">{$row['Year']}</li>";

        // change the current year
        $currentYear = $row['Year'];
    }

    // if the month changes you have to display another month
    if($row['Month'] != $currentMonth) {

        // display the current month
        $monthName = date("F", mktime(0, 0, 0, $row['Month'], 10));
        echo "<li class=\"cl-month\">$monthName</li>";

        // change the current month
        $currentMonth = $row['Month'];
    }

    // display posts within the current month
    $slug = 'a-'.$row['Month'].'-'.$row['Year'];
    echo …
broj1 356 Humble servant Featured Poster

Good to hear it works as you expected. Please mark this as solved so it is officially out of the way :-)

broj1 356 Humble servant Featured Poster

After looking closer at your code I figured out that you do not need neither javascript nor ajax. Before posting my version of code I have to warn you that deleting records using GET method is a bad practice considering the semantics and security. Make sure only authenticated users can get to this script. Here is the code (take it as a concept):

// connect to the database
include 'Connect.php';

// confirm that the 'student_id' variable has been set
if (isset($_GET['student_id']) && is_numeric($_GET['student_id']))
{
    // if user clicked on a Delete buttton, then delete the record and redirect
    if(isset($_POST['confirm-delete'])) {

        // first remove the delete element form the $_POST
        unset($_POST['confirm-delete']);

        // get the 'student_id' variable from the URL
        $student_id = intval($_GET['student_id']);

        // delete record from database
        if ($stmt = $mysql->prepare("DELETE FROM student_information WHERE student_id = ? LIMIT 1"))
        {
            $stmt->bind_param("i",$student_id);
            $stmt->execute();
            $stmt->close();
            $mysql->close();

            header("Location: Admin_Home.php");
            exit();           
        }
        else
        {
            $mysql->close();
            // if error redirect to the error page
            header("Location: Error.php");
            exit();
        }
    }

    // prompt and a form containing the confirm button
    echo "<p>Do you realy want to delete the record?</p>";
    echo '<form action="#" method="post">';
    echo '<input type="submit" name="confirm-delete" value="Delete">';
    echo '</form>';
}
else
    // if the 'student_id' variable isn't set, redirect the user
{
    header("Location: Admin_Home.php");
}

As you see I used a form with a button and a POST method, so I can first check whether a button was clicked. You should add a cancel button as well and redirect without deleting if pressed.

broj1 356 Humble servant Featured Poster

If you wish to use the above soultion by ehpratah you will have to use ajax since queries can not be performed by javascript itself. You can use a jquery Ajax method.

broj1 356 Humble servant Featured Poster

Nice job. Haven't tested the class but after scanning the code it is obvious that this is a nice example of clean coding / useful functionality. Quite some work must have been put into this to gather all the information an put it into this little tool. I remember myself struggling a couple of times needing to convert between formats.

Adding suppport for transparency might be also a very good idea.

Thank you for sharing.

broj1 356 Humble servant Featured Poster

It would help if you could be more specific. Show some code so we can see things like the array structure and values, the table structure, the complete error message etc.

broj1 356 Humble servant Featured Poster

It would be helpful if we see the actual data in the array. Put this code between lines 10 and 11:

die(print_r($skills_1, 1));

Post the output here.

It is also (usually) easier to use a foreach loop to process an array instead of all the for stuff.

broj1 356 Humble servant Featured Poster

Shouldn't line 2 be:

$query = "SELECT * FROM users";

(without the mysql_query part)?

broj1 356 Humble servant Featured Poster

On line 6 you must enclose the associative index in quotes. Consequently you have to change the code for the query slightly, like:

mysql_query("SELECT LRCard FROM student_information where student_id='" . $_GET['id'] . "'");

or:

mysql_query("SELECT LRCard FROM student_information where student_id='{$_GET['id']}'");
broj1 356 Humble servant Featured Poster

Maybe storing session data in database would give you control you need. See this article about the topic:

http://shiflett.org/articles/storing-sessions-in-a-database

broj1 356 Humble servant Featured Poster

Post the code for the insert query.

broj1 356 Humble servant Featured Poster

In any case it is good practice to check for values before using them:

if(isset($_POST['child-fname']) && !empty($_POST['child-fname'])) {
    $childfname = ($_POST['child-fname']);
} elese {
    // do some falback procedure
}
broj1 356 Humble servant Featured Poster

Obviously $_POST['child-fname'], $_POST['child-lname'] and others are arrays, not strings. Can you post the contents of some of them. Put this code somewhere in the script and post the output here.

print_r($_POST['child-fname']);
print_r($_POST['child-lname']);
...

And do not get rid of mysql_real_escape_string in production version. It means security.

broj1 356 Humble servant Featured Poster

Post the bit of code that uses the mysql_real_escape_string() function. It is important that you give this function a string as a parameter (not an array as in your case).

broj1 356 Humble servant Featured Poster

Seems like eburlea was right in his first post since there is no $query variable in your script. Try looping over the query object directly:

foreach ($db->query($sql) as $row) {
    $product = $row['product'];
    $price = $row['price'];
    echo "<tr>";
    echo "<td>" .$product ."</td>";
    echo "<td>" .$price ."</td>";
    echo "</tr>";
}

I saw this here and here.

broj1 356 Humble servant Featured Poster

You have marked it as solved but seems you still have problems? If you wish we can still find a solution. Post the latest version of the script here and post the contents of the $_POST array using print_r($_POST).

broj1 356 Humble servant Featured Poster

You will have to check for values of each of the fields and build the query accordingly. Something like:

$query = "SELECT Schedule.Channel_Number, StationInformation.Station_Name, Schedule.Program_Name, Schedule.Date, Schedule.Time FROM Schedule INNER JOIN StationInformation ON Schedule.Channel_Number=StationInformation.Channel_Number INNER JOIN TVShows ON Schedule.Program_Name=TVShows.Program_Name WHERE 1 ";

If(isset($_POST['date']) && !empty($_POST['date']))  {
    $date = mysql_real_escape_string($_POST['date']);
    $query .= " AND Schedule.Date='$date'";
}

    If(isset($_POST['startime']) && !empty($_POST['startime']))  {
    $startime = mysql_real_escape_string($_POST['startime']);
    $query .=  " AND Schedule.Date='$startime'";
}

etc.

As You can see I also added a bit of security escaping the input. You can enhance it even more. And start thinking of dropping the old mysql extension and maybe start using PDO.

broj1 356 Humble servant Featured Poster

Here's another Excel library with good documentation and examples: https://phpexcel.codeplex.com/

broj1 356 Humble servant Featured Poster

Yes, I was a bit quick, sory. The thing is you want to use ajax to send a request to another php page which then sends a response which is a html code for a table containing results. You send a ServiceOrders category parameter along to use it as a filter in the query. Maybe the best would be to use the jquery post() method which sends a request along with the parameter and puts the response in the div you wanted. Mind you, the called php page does not have to have all the html stuff (like head tags etc) only the php code querying the database and echoing the html table displaying the results. Also I would use data in a JSON instead of string and I moved the script to the bottom of the html. I tested the code below and it works .

<!DOCTYPE html>
<html>

<head>   

<link rel='stylesheet' type='text/css' href='styles.css' />
<link rel="stylesheet" href="grid.css" type="text/css" />
<link rel="stylesheet" href="backgroundcss.css" type="text/css" />
<style>
form { width: 700px; }
label { float: left; width: 100px; }
input[type=text] { float: left; width: 200px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }

</style>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
    <script type='text/javascript' src='menu_jquery.js'></script>
    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>      
<script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });


 $(function() {
     $("#refresh").on("click", function() {
        $("#mydiv").load("http://192.241.175.69/ServiceOrderReport.php");
        return false;
    })
  })

</script>

</head>
  <body  class="container">
  <br>
<div id='cssmenu'>
<ul> …
broj1 356 Humble servant Featured Poster

Why don't you use the second parameter of the load() function for sending it over to the theServiceOrderReport.php. You basically do not need a session var for that.

First add an ID to the select element:

<select name="ServiceOrders" id="ServiceOrders">

Then read its value and send it over with the load():

$("#refresh").on("click", function() {
    // selected value
    var categoryVal = $("#ServiceOrders").val();
    $("#mydiv").load("http://192.241.175.69/ServiceOrderReport.php", categoryVal);
return false;
})

Read it from the $_POST array and use it in the query (you can also store it in session var here):

$ServiceOrders= $_POST["ServiceOrders"];
broj1 356 Humble servant Featured Poster

In your code you use both mssql_* and mysql_* functions. Do you use two different database servers or is that just a typo from copying from some examples?

broj1 356 Humble servant Featured Poster

Sory for late reply. Obviously $_FILES['userfile'] does not exist. You should place the code that reads the uploaded file information and writes to the database within the if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) block. Something like this:

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{

    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    $fp = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    if(!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
    }
    include 'config.php';
    include 'opendb.php';
    $query = "INSERT INTO upload (name, size, type, content , description ) ".
    "VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$description')";
    mysql_query($query) or die('Error, query failed');
    include 'closedb.php';
    echo "<br>File $fileName uploaded<br>";
?>


 <form action="upload.php" method="post">
 Image Description: <input  type="text" name="imgdesc">
                               <input type="submit" value="submit">
</form>

<?php

$allowed_filetypes = array('.jpg','.jpeg','.png','.gif');
$max_filesize = 1445760;
$description = $_POST['imgdesc'];

$filename = $_FILES['userfile']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

if(!in_array($ext,$allowed_filetypes))
  die('The file you attempted to upload is not allowed.');

if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
  die('The file you attempted to upload is too large.');



} else {
     echo 'There was an error during the file upload.  Please try again.';
}

This way the file gets inserted into the db only when some data about it exists. You might want to reaarange the code depending on what you actually want to achieve.

broj1 356 Humble servant Featured Poster

What is the error? Can you post it?

broj1 356 Humble servant Featured Poster

in simple words this code works fine

Does that mean that the code works fine now?

broj1 356 Humble servant Featured Poster

Sory for late reply, I was away. Can you post the contents of the $this->wp_selected_rar_roles and $wp_roles->roles arrays. You can use this code:

<?php
// show contents of $this->wp_selected_rar_roles
echo '<pre>$this->wp_selected_rar_roles' . print_r($this->wp_selected_rar_roles, 1) . "</pre>";

foreach($this->wp_selected_rar_roles as $role) {

    // show contents of $wp_roles->roles
    echo '<pre>$wp_roles->roles' . print_r($wp_roles->roles, 1) . "</pre>";

?>
<input type="radio" name="wp_rar_user_role" id="wp_rar_user_role" class="input select" value="<?php echo $role; ?>" /> <label>
<?php echo $wp_roles->roles[$role]['name']; ?>
</label>
<?php
}
?>
broj1 356 Humble servant Featured Poster

Ups, I wrongly interpreted your code, I am sory for that. Please disregard my post above.

Can you post the html code for both radio buttons that gets generated, please.

broj1 356 Humble servant Featured Poster

Seems like $role is an array and therefore won't display as a string. Can you post the contents of the $role - you do this by using print_r($role).

Edit: I forgot to mention I am not a WP expert.

broj1 356 Humble servant Featured Poster

Adapted from the PHP site example:

// path to the directory with files (relative to the script)
$path = '.';
// URL to the above path from the browser
$url = 'http://www.example.com/download/';
if ($handle = opendir($path)) {
    // loop through directory entries
    while (false !== ($entry = readdir($handle))) {
        // skip . and ..
        if ($entry != "." && $entry != "..") {
            // construct a link and display it
            echo "<a href=\"$url$entry\">$entry</a><br>";
        }
    }
    closedir($handle);
}
broj1 356 Humble servant Featured Poster

Use explode and implode and form an SQL statement:

$values = explode(' ', "claim for my new mercedes");
$sql = "INSERT INTO mytable VALUES ('" . implode("','", "$values") . "')";

Or use str_replace and form an SQL statement:

$sql = "INSERT INTO mytable VALUES ('" . str_replace(' ', "','", "claim for my new mercedes") . "')";

This works only if you use space as a separator. Note that all values in the query are enclosed in quotes.

broj1 356 Humble servant Featured Poster

I tested both my suggestions in my environment and they work. But please note, you have an extra space in one of the elements of the $fields array. I also simplified the code since there is no need to have intermediate $wheres array. Also see how I changed the name attributes of the select elements. So this is the code (see also the comments in the code):

<?php
// first check if $_POST is set and not empty
if(isset($_POST) && !empty($_POST)) {

    $fields = array('eventID','eventTitle', 'te_events.venueID', 'te_events.catID', 'eventStartDate', 'eventEndDate', 'eventPrice');

    // start building the query
    $sql = "SELECT eventID, eventTitle, te_events.catID, te_events.venueID, te_category.catDesc, te_venue.venueName, te_venue.location,  eventStartDate, eventEndDate, eventPrice 
    FROM te_events INNER JOIN te_category ON te_category.catID=te_events.catID 
    INNER JOIN te_venue ON te_venue.venueID=te_events.venueID
    WHERE 1";

    // loop through the POSTed array,
    // and add WHERE clauses to the query
    foreach ($_POST as $key => $val) {

        // check if the $_POST key (form field name) exists in the $fields array
        // and has allowed value
        if(in_array($key, $fields) && ($val != '' && $val != 'Select')) {

            $sql .= " AND $key='$val'";
        }
    }

    // add sorting to the query
    $sql .=  " ORDER BY eventTitle";

    // DEBUG: display the query
    echo $sql;
}

?>
<form action="#" method="post">

<p><label class="label1">Event Title:</label><input type='text' class="input_personal" name='eventTitle' id ='eventTitle'/></p>
<p><label class="label1">Venue Name:</label></p> 
    <p><select class="select" name="te_events.venueID" id ='te_events.venueID' >
      <option>Select</option>
      <option  value='v1'>Theatre Royal</option>
      <option  value='v2'>BALTIC Centre for Contemporary Art</option>
      <option  value='v3'>Laing Art Gallery</option>
      <option  value='v4'>The Biscuit Factory</option>
      <option  value='v5'>Discovery Museum</option>
      <option  value='v6'>HMS Calliope</option>
      <option  value='v7'>Metro Radio Arena</option>
      <option …
broj1 356 Humble servant Featured Poster

My previous post were not tested, only conceptual. Tonight I will simulate/test the code in real environment and let you know how I went.

broj1 356 Humble servant Featured Poster

Yet another approach. Do not use table name in the array:

$fields=array('eventID','eventTitle','venueID','catID ',
'eventStartDate','eventEndDate','eventPrice');

Prepend table name to all $wheres:

// add to array of WHERE clauses only if value is not FALSE
if (${$field}) { $wheres[]="$field='" . 'te_events.' . ${$field}."'"; }

Again, not very flexible (and I am not sure if this is correct since I do not know all the logic).

broj1 356 Humble servant Featured Poster

Depends on the situation. So the venueID and catID are from another table. You could code it this way:

...

  // add to array of WHERE clauses only if value is not FALSE
  if (${$field}) { 
      $wheres[] $field = venueID || $field = catID ? "$field='" . 'te_events.' . ${$field}."'" : "$field='" . ${$field}."'"; 
  }
}
...

The above code checks if the fields need to be prepended with the table name. But this code is not very flexible. Other approach would be to have select names contain table names (with dots) but I am not sure if this is valid in HTML:

<select class="select" name="te_events.catID" id ='catID'>
broj1 356 Humble servant Featured Poster

Select element names are venueID and catID but the field names in the array are te_events.venueID and te_events.catID so you do not get a match here (isset($_POST[$field]) returns false).

broj1 356 Humble servant Featured Poster

Typically you would load all three divs with images of different size. One of the divs will be displayed while the other two will not. You use display:block for displayed div and display:none property for the two other divs:

<div id="large" style="display:none"><img...
<div id="medium" style="display:block"><img...
<div id="small" style="display:block"><img...

or appropriate class. Now when user clicks on radio buttons you use javascript or jquery to change the display property of the divs as apprpriate:

$('#large').show();
$('#medium').hide();
$('#small').hide();

If there are many images on the page you might want to use ajax instead of preloading them.

broj1 356 Humble servant Featured Poster

Are you starting session anywhere? If you have session_start then session variables should be available to you.

broj1 356 Humble servant Featured Poster

http://api.jquery.com/checked-selector/

Have a look at first example.

broj1 356 Humble servant Featured Poster

If I understood correctly you just want to skip first row which is heading row. If that is true then start inserting at row 2. Something like:

$heading = true;
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
    // check if the heading row
    if($heading) {
        // unset the heading flag
        $heading = false;
        // skip the loop
        continue;
    }
    $sql = "INSERT into prod_list_1(p_bench,p_name,p_price,p_reason) values ('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]')";
    mysql_query($sql);
}
keshava_1 commented: Great its worked +0
broj1 356 Humble servant Featured Poster

There is a nice jquery example on the above link. BTW, I do not think you need a plugin for that. It is just few lines of code.

broj1 356 Humble servant Featured Poster

Describe your tables in a way that you can create forms and generate queries. A simple way of doing it would be to have table fields stored in an associative array where keys would be field names and values would be field types. That way you can tell whether to use nput field or textarea in the form.

$table = array(
    'tablename' => 'table1',
    'filed11' => 'varchar',
    'field12' => 'smallint',
    'field13' => 'text',
)


$table2 = array(
    'filed21' => 'integer',
    'field22' => 'smalint',
)

// form for the selected table (i.e.table1)
echo "<form>";
foreach($table1 as $key => $value) {
    if($key == 'tablename') {
        echo "<input type=\"hidden\" value=\"$value\">";
    } else {
        switch($value) {
            case 'varchar':
            case 'smallint':
                echo "<input type=\"text\" name=\"$key\">"; break;
            case 'text':
                echo "<textarea name=\"$key\"></textarea>"; break;
        }
    }
}
echo '<input type="submit" name="submit" value="Insert data">';
echo "</form>";

// this is how you process the form
if(isset($_POST['submit'])) {
    unset($_POST['submit']);
    $tablename = mysqli_real_escape_string($_POST['tablename']);
    unset($_POST['tablename']);

    foreach($_POST as $fieldname => $fieldvalue) {
        $fieldNamesArray[] = mysqli_real_escape_string($fieldname);
        $fieldValuesArray[] = mysqli_real_escape_string($fieldvalue);
    }

    $query = "INSERT INTO $tablename ("`. implode('` ,`', $fieldNamesArray) "`) VALUES (" . implode("','", $fieldValuesArray) . "')";

    // then execute the query
    ...
}

This is just a concept. It can be much improved but you get the idea.

broj1 356 Humble servant Featured Poster

Could you be more specific. Would you like to find all the checkboxes that are clicked? That is easy to implement with the checked selector.

broj1 356 Humble servant Featured Poster

Use one of the PDF libraries out there. I use tcpdf and am very happy with it. Find a function in your pdf library that deals with images. In tcpdf it is the Image() function (see an example here). You can either save the generated image to disk and use it in the Image() function or send the Image() function a base64 encoded string representing the image.

Mahesh_12 commented: Thanks.. I am following same idea but i am strugling to save the image can you explain how to save the image and how to get the saved image url +0
broj1 356 Humble servant Featured Poster

Sory, but I do not understand the question. What insertion do you have in mind?

broj1 356 Humble servant Featured Poster
broj1 356 Humble servant Featured Poster

You are welcome. Did it help?

broj1 356 Humble servant Featured Poster

This is what uncle Google told me:

http://www.php.net/manual/en/function.id3-get-tag.php

broj1 356 Humble servant Featured Poster

After I download it offline to run it in my localhost, that error start appearing.

What do you mean by that? You can not download PHP code from a web page, can you?

Anyway, the error you are getting means that you are sending some HTML output before the session_start function. You can not do that since session_start sends a cookie and cookies are a part of a header. And header directives have to be sent before any HTML output. This includes any spaces that maybe you do not see in your code, as well as included files that also should not send HTML before headers. The solution is to put the session_start function on the very beginning of the code (as it says in the comment).

broj1 356 Humble servant Featured Poster

Nice little function for sending mail if you do not want to be bothered with the details about coding the neccesary mail commands. I haven't tested it but it looks clean and tidy.