simplypixie 123 Posting Pro in Training

echo your query and then copy and paste into into your phpmyadmin and see what happens there

simplypixie 123 Posting Pro in Training

If you print_r($_POST); you should see what is being passed to the next page and it will hopefully help you understand why your quesry isn't working (because you are assigning the whole of these arrays to your new array when you need to run them through a foreach):

$whereClauses = '';
$numLocations = count($_POST['Locations']);
$numJobs = count($_POST['Jobs']);
$i = 0;
    if (! empty($_POST['Locations'])) {
      foreach ($_POST['locations'] as $location) {
        $whereClauses .="Locations='".mysql_real_escape_string($location)."'";
        if ($i++ == $numLocations) {
         $whereClauses .= " AND";
        }
      }
    }
    if (! empty($_POST['Jobs'])) {
      foreach ($_POST['Jobs'] as $job) {
        $whereClauses .="Jobs='".mysql_real_escape_string($job)."'";
      }
      if ($i++ == $numJobs) {
         $whereClauses .= " AND";
      }
    }

This is not tested but hopefully it will give you an idea of what you need to do. You can remove the implode(' AND ',$whereClauses) and replace with just $whereClauses

simplypixie 123 Posting Pro in Training

If you really want to get the whole string after the ? you can use something like:

$id = strstr($_SERVER['PATH_INFO'], '?');
$id = str_replace('?','',$id);
simplypixie 123 Posting Pro in Training

You need to run your fetch_array through another while loop:

while ($getthis = mysql_fetch_array($getsubject)) {
echo "<option value=".$getthis['subjectID'].">".$test['subjectCode']."</option>";
}
simplypixie 123 Posting Pro in Training

Please post what you have, not the tutorial, so we can see exactly what you are doing.

simplypixie 123 Posting Pro in Training

Is your PHP really at the bottom of the page? If so, move it to the top before any html etc and add in an if statement to check if the form has been posted (i.e. if (isset($_POST)) { ...... Do your DB stuff here ..... }

Does your table name come from a variable as I notice you have written it as $####### in your query? If so then where is that variable being definined and if not then it should just be the table name.

Have you tried printing out your posted data to make sure it is being sent? If not then use print_r($_POST) to check what data (if any) is being posted.

simplypixie 123 Posting Pro in Training

You want to be using foreach, not while to display your results from the form

simplypixie 123 Posting Pro in Training

It is just a warning that at the time your variables have no values.

Try moving this

$wages=$_POST['wages'];
$hours=$_POST['hours'];

Into your if statement

if (isset($_POST['submit']))
    { 
    $wages=$_POST['wages'];
    $hours=$_POST['hours'];

Also print_r($_POST) to check that you are receiving values through your form post.

simplypixie 123 Posting Pro in Training

I have just looked at the link you posted before on Chrome (Mac) and cannot see any whitespace - should I be looking at a different link?

simplypixie 123 Posting Pro in Training

This is wrong:

        <option value= '1' <?php echo $cat_row->country_id; ?> >

It should be:

        <option value= "<?php echo $cat_row->country_id; ?>" >
simplypixie 123 Posting Pro in Training

You have #Main in your CSS but <div id="Mainpos"> in your HTML, your class and id names need to match what you have in your styelsheet, therefore it should be <div id="Main">

simplypixie 123 Posting Pro in Training

This doesn't do anything:

<form action ="password generator" method="post">

It needs to be a proper file path, like:

<form action ="password-generator.php" method="post">
simplypixie 123 Posting Pro in Training

You can't run PHP in an .html file, it has to be a .php file

blocblue commented: That's incorrect. +0
simplypixie 123 Posting Pro in Training

You have this

for($i=0;$i<$count;$i++){

But don't seem to have set a value for $count anywhere so the is no value to compare $i to.

simplypixie 123 Posting Pro in Training
if (isset($_GET['start'])) {
  $start=$_GET['start'];
}

Read this article to help further.

simplypixie 123 Posting Pro in Training

You need to order the results in your query:

$sql = "SELECT Title, Date, Place, Description FROM Events ORDER BY Date ASC";

Either ASC or DESC depending which order you want them in

simplypixie 123 Posting Pro in Training

Well valid_pid is not a PHP function unless you have made a function called valid_pid somewhere, in which case your file isn't getting that function as it needs to.

The errors you are getting are telling you exactly what your problems are and you need to work with them

simplypixie 123 Posting Pro in Training

This is wrong:

if (isset($_GET['album_id']) === false || valid_pid($_GET['pid']) === false)

It should be:

if (!isset($_GET['album_id']) || valid_pid($_GET['pid']) === false)
simplypixie 123 Posting Pro in Training

Tray correcting this:

echo $error, '<br />';

To

echo $error.'<br />';
simplypixie 123 Posting Pro in Training

As @diafol has said, session_start() has to be before any other code or output in your page - that also means include files

<?php
session_start();
include("config.php");
simplypixie 123 Posting Pro in Training

What is line 53 - it may be nothing to do with the header redirect?

simplypixie 123 Posting Pro in Training

Glad to hear it :-)

simplypixie 123 Posting Pro in Training

I think you need to find a simpler tutorial as there is no need to keep querying your database on every page, just do it once at login and ensure all required data is stored in your session variables as required and then use checks on the session data to determine if a page can be viewed or not.

What all the preg_replace on the session data is for I have no idea either - there is no need for it and is probably what is causing your database query to fail to be honest.

Just get rid of the additional queries and use your session data only.

simplypixie 123 Posting Pro in Training

What you are currently doing is trying to find records where year = '2012, 2011, 201, 2009, 2008' and I would think that you don't have a value like that in your database. I presume you are trying to see if a year matches ONE of the years in your array, in which case do this:

$result = mysql_query("SELECT * FROM VehicleYearModel WHERE year IN ($matches)");
simplypixie 123 Posting Pro in Training

Once you have done whatever it is you need to do with your posted data (that part of your code isn't shown and you currently have to action specified in your form), just add your values to the url:

header('location: your_page.php?post_id={$_POST['post_id}&album_id={$_POST['album_id']}');
simplypixie 123 Posting Pro in Training

Guessing at the id's that link your tables and not knowing the WHERE cluase:

"SELECT tbl_project.project_name, tbl_delivarables.deliverables, tbl_employee.employee_name FROM tbl_project INNER JOIN tbl_deliverables ON tbl_deliverables.project_id=tbl_project.project_id INNER JOIN tbl_employees ON tbl_employees.employee_id=tbl_deliverables.employee_id WHERE ........"
simplypixie 123 Posting Pro in Training

Set a style in you style sheet and apply that.

In style sheet:

.date-celebrants {
    font-color: yellow;
}

And in you HTML/PHP put:

echo '<span class="date-celebrants">' .date('M'). ' ' .('Celebrants'). '</span>';
simplypixie 123 Posting Pro in Training

I have to do it this way as I am using the instance of the object more than once so I have to use a variable for each instance. Thank you anyway, it has clarified for the future.

simplypixie 123 Posting Pro in Training

It doesn't work the way I want it without the return so I will stick with it :-)

simplypixie 123 Posting Pro in Training

OMG - that was so simple to sort after using your script (which worked) and looking at mine again as basically I was missing the return which I didn't think I needed as I was just accessing the class properties from the object as I normalluy would.

Thank you so much for the help.

simplypixie 123 Posting Pro in Training

I have dumped the array already and run lots of checks and all is fine but this is what I get:

array(10) { ["id"]=> string(2) "44" ["show_id"]=> string(2) "12" ["job"]=> string(1) "1" ["time"]=> string(1) "1" ["judge"]=> string(1) "0" ["ring_party"]=> string(1) "0" ["hours"]=> string(1) "1" ["club"]=> string(1) "1" ["job_share"]=> string(1) "0" ["help_text"]=> string(403) "....... (replaced text) " }

Would the array value types be causing a problem???

simplypixie 123 Posting Pro in Training

Rather than write a huge list of properties used by a class I want to know if I can dynamically generate them when needed. I have looked and __set and __get but I am not sure how (or if) I use them with what I am trying to do.

The function I have at the moment is this (obviously doesn't work):

public function getShowHelpingDetails($id) {                
$this->show_id = $id;        
$result = $this->selectRecord($this->table, $this->show_id, '*', '', 'show_');       
foreach ($result as $key => $value) {            
  $this->{$key} = $value;       
}            
}

And then trying to access the properties like this:

$h = new ShowHelping;
     $helping = $h->getShowHelpingDetails($show_id);
echo $helping->time;  

Can anyone help me with this and if not possible advise of a better way to set my class properties without huge lists of them?

simplypixie 123 Posting Pro in Training

Use a join on the same table, something like:

SELECT tbl1.*, tbl2.* FROM table_name AS tbl1 INNER JOIN table_name AS tbl2 ON tbl1.a=tble2.b

Not tested and a quick example

simplypixie 123 Posting Pro in Training

This is the code I use and run a cron job:

backup_tables('user','password','database');


/* backup the db OR just a table */
function backup_tables($user,$pass,$db)
{

    $suffix = date("mdY-Hi");
  #Execute the command to create backup sql file
  exec("mysqldump --user={$user} --password={$pass} --quick --add-drop-table --add-locks --extended-insert --lock-tables --all {$db} > ../db_backups/backup.sql");

  #Now zip that file
  $zip = new ZipArchive();
  $filename = "../db_backups/backup-$suffix.zip";
  if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
   exit("cannot open <$filename>\n");
  }
  $zip->addFile("../db_backups/backup.sql" , "backup.sql");
  $zip->close();
  #Now delete the .sql file without any warning
  @unlink("../db_backups/backup.sql");
  #Return the path to the zip backup file
  return "../db_backups/backup-$suffix.zip";
}
debasisdas commented: agree +13
simplypixie 123 Posting Pro in Training

It's OK, I am using a basic while loop (as I say I have got that working now where it wouldn't before and therefore don't need a foreach within it - did wonder why I would in the first place really) and allocating all rows to a new array and returning that. It is all working now.

If anyone else has this problem, this is what I changed/got working:

public function doQuery($sql)
  {     
    $query = $this->dbh->query($sql);
    $last_query = $sql;

    try {

        if (!$query) {

            throw new CustomException("Query failed: ".$last_query);

        } else {

            $rows = array();
        while($row = $query->fetch_assoc())
        {
            $rows[] = $row;
        }
                return $rows;

        }
    } catch (CustomException $e) {

        echo $e->getErrorReport();

    }
  }

And run the foreach in the page where the data is to be displayed (in brief):

$s = new Shows;
$shows = $s->listShows();

foreach ($shows as $show) {
echo $show['name'].'<br>';
}
simplypixie 123 Posting Pro in Training

Actually, I have just got a basic while loop to work with the foreach from the database class - I wonder why it won't work elseshere.

simplypixie 123 Posting Pro in Training

My query is in () $query = $this->dbh->query($sql);
However, I have just printed the $rows within the while loop and I have all my records showing now, thank you.

Now to work out how to get the data to the index.php page and display it :-)

simplypixie 123 Posting Pro in Training

Generally, undefined variable means that it has no value and it is just a warning, change to this:

<?php if (isset($confirmation)) { echo $confirmation; } ?>

This should get rid of the warning but doesn't help as to why the variable is empty.

Then for your if statement shpould work like this:

$confirmation = !$result ? "Data telah terhapus." : "Gagal menghapus data.";
// or whichever way round you need it
simplypixie 123 Posting Pro in Training

I am not new to OOP I am tidying up a very large site of mine and trying to create a much better structure (more in keeping with the whole point of OOP). I have decided to use mysqli (please don't suggest PDO as I have decided againast it) which is new to me and am a little confused to say the least with a problem I am having with a basic select * query.

In my database class I have the following functions (only the ones relevant to this thread):

public function selectAll($table, $fields = '*', $where = NULL, $order = NULL, $limit = NULL, $offset = NULL)
  {
    $sql = 'SELECT '.$fields.' FROM '.$table;

    if ($where != NULL) {
        $sql .= ' WHERE '.$where;
    }
    if ($order != NULL) {
        $sql .= ' ORDER BY '.$order;
    }
    if ($limit != NULL) {
        $sql .= ' LIMIT '.$limit;
    }
    if ($offset != NULL) {
        $sql .= ' OFFSET '.$offset;
    }

    return $this->doQuery($sql);
  }

  public function doQuery($sql)
  {     
    $query = $this->dbh->query($sql);
    $last_query = $sql;

    try {
        if (!$query) {

            throw new CustomException("Query failed: ".$last_query);

        } else {

            $array['result'] = $query->fetch_assoc();
            $array['total_rows'] = $query->num_rows;
            return $array;

        }
    } catch (CustomException $e) {

        echo $e->getErrorReport();

    }
  }

In my child class, I have the following:

public function listShows($status = 'All') {

        switch ($status) {
            case 'All':
                /* Get all shows in database */
                $where = "";
                $order = "name ASC";
                break;
            // All other cases removed to keep things short
        } …
simplypixie 123 Posting Pro in Training

Use CSS to set a background colour to rows with errors:

tr.error {
  backround-color: red;
}

Then check if there is an error and if so, apply the style to your table row (replaces line 22 in your posted code):

echo'<tr';

if ($part[2] == 'error') { echo ' class="error"'; }

echo '>';
iamthwee commented: css is the way to go +14
simplypixie 123 Posting Pro in Training

Your button should be a submit instead as what you have won't submit your form or post your data.
<input type="submit" id="nw_update" value="NW_Update"/>

simplypixie 123 Posting Pro in Training

Formatting on here is no different to any other forum, just type in the box and when you want to display code, hit the Code link, put in the code and click the Insert Code button.

As for your problem, try this:

SELECT count(*) from Inquiry 
Inner Join Inquirer on Inquirer.ID = Inquiry.InquirerID_fk
WHERE Inquirer.Program = 'value' AND Inquiry.ID 
not in (SELECT TransferInquiryID_fk from Transfer)
simplypixie 123 Posting Pro in Training

Like this:

<input type="radio" name="type" value="Student" <?php if ($type=='Student') { echo 'checked'; } ?> /> Student<br />
<input type="radio" name="type" value="Teacher" <?php if ($type=='Teacher') { echo 'checked'; } ?> /> Teacher<br />
simplypixie 123 Posting Pro in Training

I am wondering if your name="type" is causing a conflict as type is used as part of a form elements details. Have you tried changing it to something else and see what happens?

Also, are you sure that one of the radio buttons is being selected?

simplypixie 123 Posting Pro in Training

What is the code at the top of your index pages?

simplypixie 123 Posting Pro in Training

You aren't getting the data from your query. mysql_num_rows returns exactly what it says, the number of rows returned from a query - therefore it cannot be equal to a strings, only an integer.

Change to:

$query = mysql_fetch_array($login);

// Check username and password match
if ($query['user'] == 'admin') {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location:newAdmin.php');
}
elseif ($query['user'] == 'user') {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location:user.php');
}
else {
// Jump to login page
header('Location: ind.php');
}

Where I have used $query['user'] you need to change user to whatever the column name is in your db table that stores the level of user.

simplypixie 123 Posting Pro in Training

As I put in my original post!

Djmann1013 commented: Thanks +1
simplypixie 123 Posting Pro in Training

I stand corrected - but, I have never once, in all my learning over the years, come across any PHP code that uses the actual words 'and' or 'or' instead of '&&' or '||'

simplypixie 123 Posting Pro in Training

rotten69 didn't change your code for the OR, you cannot use OR in PHP, only in sql queries. So it should be

if($row['banned'] == 1 || $row['banned'] == 2) {
  header ('location: url');
}

You don't need speach marks around numbers/integers as suggested earlier either.

Have you echo'd $row['banned'] to ensure you actually have a value coming from the database?

Also what happens if they aren't banned, surely you should have an else statement following your if for cases like that?

simplypixie 123 Posting Pro in Training

What is your url code that you GET from as if it is echoing out like that as well, then that is where your problem lies.