I am using a CMS as a basis for a website. There are some special articles I wish to add and they require custom css.

To keep things tidy, I want to have unique css files for each of these special articles and invoke them using [CODE=css]@import url('filename.css')[/CODE]

However, the files will only load if the @import is at the top of the site css file. Does this make sense? By that logic, anything that appears below the @import will cancel what that which I am trying to code in a special manner. Is it not possible to have an @import at the end of a css file?

Good day,

I am getting an error on a log-in script:

mysql_query(): 4 is not a valid MySQL-Link resource

I've done some research on this and followed such advice as:
[LIST]
[]ensuring the mysql connection is closed after the results have been returned
[
]testing any sql strings I define in phpMyAdmin or some other means directly against the database so I can determine if there's an error. This has proven that the syntax is correct
[/LIST]
I have a file for constants and other functions that are universal to the site. This is being loaded with require_once. Database settings for this application are being defined:
[code=php]
define ("DB_HOST","localhost"); // set database host
define ("DB_USER","[I]username[/I]"); // set database user
define ("DB_PASS","[I]password[/I]"); // set database password
define ("DB_NAME","[I]db_name[/I]"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");
[/code]

My first query in the log-in is to compare the submitted userid or e-mail and password against the database:
[code=php]
if (strpos($data['user_email'],'@') === false) {
$user_cond = "user_name='$data[user_email]'";
} else {
$user_cond = "user_email='$data[user_email]'";
}//end if...else on string position of user_email

$sql = "SELECT `id`, `pwd`, `firstname`, 
    `user_name`, `approved`, `user_level`, `salt`
     FROM users
     where $user_cond AND `banned` = '0'";
$record = mysql_query($sql, $link) or die(mysql_error());
$num = mysql_num_rows($record);
mysql_close($link);

[/code]

I've checked in an IDE with a debugger, $user_cond is defining properly and concatenating properly in the $sql string.

Stepping through the code, the IDE tells me the value of $link is ...

Good day,

I've done some searching on this topic but am not sure if I am defining terms properly in order to get results. I am new to AJAX and can execute the process of dynamically adding some content. But I want to take it one step further for adding content more than once on a page.

This is my basic scenario.
[LIST=1]
[]My page lists a series of posts with userid, post # and post content
[
]Like adding quick replies to posts here, I have a form that a user fills out and clicks a button
[]AJAX does its job and I have programmed my PHP in the background to return the contents of a div with the full HTML mark-up for displaying a message
[
]The method for displaying the block of data returned from the server is to replace the InnerHTML of a div id'd as 'append'
[/LIST]

This works great for one successful post. But what if a user wants to add a second post? Under things as I have them now, my page will only display the most recent post added dynamically. The dynamic post previous to the most recent is lost. It can only be viewed in order if the user refreshes the whole page and then adds a new post.

Hope my logic can be followed and someone can offer insight.

Thanks for all your suggestions. It took copying and pasting the files into new docs in gedit to wipe out the problem, whatever it was. Nothing showed up in the new docs that may have been hidden in the old.

This isn't really a PHP question but I couldn't find the right place for it.

I'm getting these strange characters -  - in my source code before the Doctype tag.

I've encountered this before when working in Notepad++ using ANSI as UTF-8 or similar formats with BOM for encoding. Usually converting the files to UTF-8 solves the problem but it isn't this time.

I've even gone so far as to open all the files in gEdit on a Linux box and save them as UTF-8 and Linux end of line but to no avail. That garbage keeps showing up in my Linux or Windows development environments.

Any other ideas would be most welcome.

Hi Chris,

At first I didn't think this was going to work, based on "Example #2 array_key_exists() vs isset()" located at [URL="

I have an array that is multidimensional and I need to test whether an offset exists. My reading of the PHP manual for array_key_exists makes sense for a single-dimension array.

My script takes results returned from the database and arranges them this way:

[code=php]
Array
(
[1] => Array
(
[0] => Array
(
[merged] => 0
[ingr_qty] => 1
[ingr] => pork tenderloin
)
[1] => Array
(
[merged] => 0
[ingr_qty] => ⅓ roll
[ingr] => sausage meat
)
)
[3] => Array
(
[0] => Array
(
[merged] => 0
[ingr_qty] => 2 tbsp
[ingr] => finely chopped onion
)
[1] => Array
(
[merged] => 0
[ingr_qty] => ⅓ cup
[ingr] => cranberry sauce
)
)
}
[/code]

It would be tedious to explain why the array is written in this fashion. So please accept that it needs to be this way to facilitate making a table later in the script.

Occasionally, the pairs are not balanced. Using the above example, data occasionally comes out like this:

[code=php]
Array
(
[1] => Array
(
[0] => Array
(
[merged] => 0
[ingr_qty] => 1
[ingr] => pork tenderloin
)
[1] => Array
(
[merged] => 0
[ingr_qty] => ⅓ roll
[ingr] => sausage meat
)
)

[3] => Array
    (
        [0] => Array
            (
                [merged] => 0
                [ingr_qty] => 2 tbsp
                [ingr] => finely chopped onion
            )
    )

}
[/code]

Without the existence of an Array[3][1] key, PHP throws an error of 'Undefined offset' when making ...

Good day,

The challenge I am experiencing is obtaining the contents of the private necessary to decrypt data.

I've reviewed tutorials on public/private key generation and my keys are properly formatted.

To debug, I substituted a pair of keys created a year ago when I took a course on secure log-ins. That pair is known to work properly but does not in this application.

My private key is not encrypted so I do not need the passphrase specified under openssl_pkey_get_private.

Here is the function I am using:
[code=php]function decrypt ($encrypted) {
$private_key = openssl_pkey_get_private("file:///login.key");
/in the above, have tried file:// and file:/// /
$encryptedData = base64_decode($encrypted);
$data = '';
openssl_private_decrypt($encryptedData, $data, $private_key);
return $data;
}[/code]

If I run the above through a debugger, $private_key remains FALSE.

In the overall scheme, the private key is supposed to reside on the server. I am only programming on a development system right now. Is that a factor?

Hey ardav,

For some reason, removing those lines of code did the trick. Now I can access the data.

Thanks for the help.

I intend to do the decryption as a function once I can create the array. What I am banging my head against the wall on is that when the while is evaluated $row comes up as FALSE. So it doesn't matter right now what syntax I have as a second line in the while statement for the file pointer never gets there.

Here is an expanded view of my code. Maybe I'm missing something that a fresh pair of eyes will see.

[CODE=PHP]
/*$user_cond is a string variable that can inject different query parameters

  • It is not having a negative impact on the query for the query string dumps okay on
  • debug and there's no indication of a 0 result once executed. I am getting a result
  • from the database
    /
    $record = mysql_query("SELECT id, pwd, firstname, approved, user_level, salt
    FROM users
    where $user_cond AND banned = '0'") or die(mysql_error());
    $num = mysql_num_rows($record);
    if($num <= 0){
    $msg[] = "The data you entered does not match any of our users.";
    }
    if($num > 1){
    $msg[] = "Your log-in can not be processed at this time. Contact the administrator.";
    }
    if($num = 1){
    list($id,$pwd,$firstname,$approved,$user_level,$salt) = mysql_fetch_row($record);
    //this I know works for the variables in list will echo on a debug dump
    if (!$approved) {
    if ($user_registration = 0) {
    /
    message for manual registration approval process/
    $err[] = 'Your registration has not been approved. Contact the administrator.';
    } else {
    /
    message for automatic registration approval process*/
    $err[] = 'Your registration ...

Good day,

I am climbing a wall trying to figure out why I can not retrieve the results of a mysql query to a php array.

My query polls the database and it is retrieved but all the data is encrypted. I need to take the results and put them through a decryption algorithm. Hence the need for an array because I can implement a foreach..

If I do the following:
[CODE=PHP]
//$record is the result of a mysql_query
list($id,$pwd,$firstname,$approved,$user_level,$salt) = mysql_fetch_row($record);[/CODE]

I get the variables stored in memory.

What is the simplest method to take the same result of the query and output it to an array? I want something like
[CODE=PHP]
$encrypted['id']
$encrypted['firstname']
etc.
[/code]

I've tried
[CODE=PHP]
while ( $row = mysql_fetch_assoc($record)) {
$encrypted['id'] = $row['id'];
$encrypted['firstname'] = $row['firstname'];
etc.
}
[/code]
but when I run it and print_r the array, there's no data. Same goes for mysql_fetch_array. If I do a dump on the individual variables stated in the list() function, they output as they should.

If I step through the code with a debugger, $row comes up as FALSE.

Any idea would be most welcome.

Until a few minutes ago, I was viewing it using Safari 3.2.3 on Windows XP. Recently, I had to rebuild my Windows installation. I thought the download of Safari was the most recent version. Just now, after reading your most recent reply, I checked the version. It didn't look right and I investigated further to see that Safari for PC is up to ver 5.x.

Now I am seeing results that are identical to the other browsers and I imagine what you are viewing.

Just so you don't think I'm totally nuts, [URL="

That is not a viable solution for this is a liquid/flexible lay-out. By what you're suggesting, all CSS in Safari would only work if it was fixed layout.

Intrigued to find a solution, I tried what you suggest and it didn't solve the problem.

Thanks for trying.

Good day,

I've run into a problem with list items displayed inline (i.e., horizontally) using Safari for Windows.

If you [URL="

I'm new to Classes. For a project to improve my skills I'm stuck.

This project is a registration in which:
[LIST=1]
[]form data is validated
[
]some variable from the form are encrypted
[*]some variables from the form are hashed
[/LIST]
It is getting the Class for hashing to load and work that is a problem. Here is my code so far:
[CODE=php]
if (isset ($_POST['submit'])) {
include ('include/Validate.php');

$newUser = new Validate();

if ($newUser->isValidated()){

include ('include/Encrypt.php');
$newEncrypt = new Encrypt();

if($newEncrypt->isEncryptedOk()){

  include ('include/Hash.php');
  $newHash = new HashVariables();  //error occurs here

  if($newHash->isHashOk()){
    echo 'This is good';die();
  } else {
    echo 'This is bad';die();
  }

} else {
  //NOT Encrypted ok, generate output
  $output = "    <div class=\"error\"><h1 id=\"encryptError\">Program halted.  Encryption failure.</h1></div>";
}

} else {
.....what to do if $_POST not set
[/CODE]

This is the error I get:

Call to private HashVariables::__construct() from invalid context in ..... and it pertains to Line 14 above.

Am I somehow breaking rules by having Classes nested in if's within if's?

I've googled the above error message and not found anything helpful.

In case this helps, here is the top of the HashVariables Class to the end of __construct():
[CODE=php]
class HashVariables {

private $password;
//private $passwordsalt_hash;
private $salt;

private function __construct(){

$this->_errors = array();

$this->password         = $this->verifyPassword($_POST['password1']);
$this->salt             = $this->verifiySalt($_POST['salt']);  

}
[/CODE]

Thanks for taking time to read this.

D

I'm trying to write a CGI script as part of a web technology programme I am undertaking. There's a challenge with getting form data to concatenate into my SQL strings to populate my database which is in Postgre.

This is my HTML form:
[CODE="HTML"]
<form action="review_input.cgi" method="post">
<input type="hidden" id="cdid" name="cdid" value="1" />
<label for="review">Rate from 1 to 5:</label>
<select name="review" class="review">
<option value="1"selected="selected">1- Don't bother</option>
<option value="2">2- Borrow from a friend</option>
<option value="3">3- Worth the money</option>
<option value="4">4- Wonderful</option>
<option value="5">5- Instant classic</option>
</select>
<label for="comment" >Comment:</label>
<br />
<textarea name="comment" wrap="soft"></textarea>
<input type="submit" value="Submit" class="button" />
</form>
[/CODE]

These are relevant snippets from C++ source for review_input.cgi. All required libraries that we have learned to date are loading. If they did not, I would get warnings if not outright compiling errors.
[CODE="C++"]
CGI_parameters request;
const int cdid = atoi(request["cdid"].c_str());
const int rating = atoi(request["review"].c_str());
const string comments = request["comment"];

connection conn ("<blah - blah - blah>");
nontransaction db (conn);

ostringstream ipt_sql;
ipt_sql  << "insert into  ratings "
         << "(cdid, userid, rating, comments) "
         << "values "
         << "(" << cdid <<", " << user_ID <<", " << rating <<", '" << comments << "')";

[/CODE]

The source compiles all right but if I load the form with data and submit it, none of it transfers to the variables in the last line of the SQL statement. I receive a database error of a primary key violation for cdid is 0. I modified the program to spit out the ...