ShawnCplus 456 Code Monkey Team Colleague

I think this is about the third post like this, you aren't actually querying. You have to call mysql_query, right now you just have it wrapped in parenthesis.

ShawnCplus 456 Code Monkey Team Colleague
$var = $variable.$i;
$$var = $row[0];

I'm not entirely sure why you would want to do this instead of use an array though.

ShawnCplus 456 Code Monkey Team Colleague

mysql_db_query takes two[or three] parameters. The first is the database name, the second is the query, the optional third is the connection. Use php.net it's your friend.

ShawnCplus 456 Code Monkey Team Colleague

Well if they block cookies they're blocking sessions as well since a user's SESSIONID is stored in a cookie.

ShawnCplus 456 Code Monkey Team Colleague

y need some help pls
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\xxxxxxxxx\index.php on line 7
No Template Selected


require("dbconfig.php");
$con =mysql_connect ($db_host,$db_user,$db_pass) or die("Error connecting");
mysql_select_db($db_name,$con);
$tem="select dir from template where active='1'";
$temr=mysql_query($tem,$con);
$temn=mysql_num_rows($temr); line 7
if($temn==0)

Excuse me. Did you not see the GIANT GLARING STICKIED POST that said "FAQ: Supplied argument not valid resource"? How about you go back and take a look at that.

ShawnCplus 456 Code Monkey Team Colleague

So you just gave up on this problem and scrapped your previous work or have you just decided you'd let everyone else do it for you? I told you before you obviously have a strong enough grasp of the concepts (that is, unless you got the code you posted from someone else) and its just coming down to laziness.

ShawnCplus 456 Code Monkey Team Colleague

i think this can be done by spliting and then just show the first 10 words or something like that i bet there is a easier way tho

6 year bump, new record! I think that qualifies for drinking an entire case!

ShawnCplus 456 Code Monkey Team Colleague

No offense but I highly doubt we'll be able to teach you the intricacies of InnoDB any better than the web tutorials would. "Business Logic" is just a term meaning the logic controlling the site.

So I suggest you read a little deeper and maybe read it through a few times because at some point you're going to actually have to learn some of this stuff on your own. Being able to learn new things on your own is one of the most important skills for a programmer.

ShawnCplus 456 Code Monkey Team Colleague

There is no way to create relationships between tables in the MyISAM engine, it all must be done in your business logic. Your tables must use InnoDB for foreign key constraints.

I'll let you look up the info on InnoDB foreign key constraints.

ShawnCplus 456 Code Monkey Team Colleague

[code=pet peeve]
sql time or php date are 10 decimal digits representing the number of seconds from 1/1/1970 (doh,, 1970 or 1980? )
human readable representations of date() or time() are unneccessary and waste processor time
the computer uses digits better than text representations
thus time() + 300 = five minutes from now
thus date() + 3600 = one hour from now
storing timestamps in database, cookies or sessions is much more efficient, than strtotime()-ing a text string to work with it, then formatting the time back as a text string.,

it's 1970, it's known as the epoch if you want to look it up

ShawnCplus 456 Code Monkey Team Colleague

Thanks for the info... I will look through online. I use Dreamweaver now but have not really looked into anything it offers in depth like Coldfusion. Could that be another possible tool I could use?

Not unless you want to pay licensing fees. Coldfusion isn't free and open like PHP

ShawnCplus 456 Code Monkey Team Colleague

you forgot a ; in echo ");" (aka, exactly what the error says on the exact line number the error says)

ShawnCplus 456 Code Monkey Team Colleague

See, that wasn't hard. Now post the contents of graph.php or point to which snippet you posted is graph.php

ShawnCplus 456 Code Monkey Team Colleague

Yes, you told you the code you tried. But as I asked before: What is the error?

ShawnCplus 456 Code Monkey Team Colleague

A) Don't make a thread with a vague title, B) What's the error? there are a lot of possible errors

ShawnCplus 456 Code Monkey Team Colleague

Well when using file_get_contents a request is sent to the remote server with the User Agent as "PHP" which can be configured in php.ini. I believe the same holds true for cURL but a cURL request can be configured to customize the user agent. So yes, it does get logged like a normal request.

ShawnCplus 456 Code Monkey Team Colleague

Why do you keep adding extra parameters to mysql_connect? it only takes hostname, username, password. You're adding two usernames for no reason.

You've also broken encapsulation by making a base class (DBprocess) too specific by entering into one table. There should be child classes which extend the base class that specialize. The base class should be just that: generic.

ShawnCplus 456 Code Monkey Team Colleague

Get jQuery (http://www.jquery.com) and read through the documentation

ShawnCplus 456 Code Monkey Team Colleague

Textareas work by having their value as the content between the tags

<textarea cols="60" rows="12" id="query" name="query">
<?php if (isset($_POST["query"])) { echo htmlspecialchars($_POST["query"]); } ?>
</textarea>
ShawnCplus 456 Code Monkey Team Colleague
if ($_POST['query'] < 15 ) {
	echo "<p>You have not entered anything in the text box provided. A minimum of 15 characters is required.</p>";
	$err++;
}

That doesn't do what you think it does. It tries to turn the string into a number and compare it.
You want to do this

if (strlen($_POST['query']) < 15 ) {
ShawnCplus 456 Code Monkey Team Colleague

With the math.h (or cmath someone correct me on this) header you can use the floor and ceil functions if I remember correctly to round down and round up respectively.

ShawnCplus 456 Code Monkey Team Colleague

A) Post your form
B) if (strlen($_POST['query'] == 0 ) ) { should be if (strlen($_POST['query']) == 0) {

ShawnCplus 456 Code Monkey Team Colleague

Parkway Drive - It's Hard to Speak Without a Tongue
http://songza.com/~7jwltz

ShawnCplus 456 Code Monkey Team Colleague

Why would you use Javascript to do this instead of just using ul/li's in your HTML?

ShawnCplus 456 Code Monkey Team Colleague

It's a security feature on browsers, cross-domain AJAX isn't allowed and would be a big issue if it was. If you need to get data from another website use an AJAX call to call a local file which uses cURL or something similar to fetch the file.

ShawnCplus 456 Code Monkey Team Colleague

Thanks, that worked out perfectly. It needed the $connection string and the mysql query

Thanks.

Actually you don't need $connection unless you have multiple mysql connections open. If you leave it out it will just use the most recently opened connection.

ShawnCplus 456 Code Monkey Team Colleague

That's true, I forgot about that (I only wouldn't say 'less annoying' as it can cause conflicts), but as he isn't doing any input/output #include <iostream> isn't even needed or am I wrong?

Right, iostream is only needed if you're using cout, cin and their ilk.

ShawnCplus 456 Code Monkey Team Colleague

You forgot to put the using namespace std; instruction in your snippet :P

using namespace std; isn't required even if you're using things from the std namespace. It's only to make it less annoying so you don't have to type std::cout , std::cin , etcetera.

ShawnCplus 456 Code Monkey Team Colleague

haha, I can't believe I didn't notice. you forgot mysql_query around your the string.

$query = mysql_query("SELECT * FROM participants WHERE participantID = $participantid");
ShawnCplus 456 Code Monkey Team Colleague

See, you're more than capable of doing what the description says, you're just overthinking it. Follow the directions closely and read in your book about Inheritance and Operator Overloading and you'll have it done in no time.

(You're probably thinking I'm being mean by not giving you the answer but if you don't learn now you'll just keep needing help)

Salem commented: Good approach, I like it. +30
tux4life commented: I agree with Salem :) +4
ShawnCplus 456 Code Monkey Team Colleague

Might want to try it yourself first looks like the description is pretty detailed. I'll wait while you give it a shot.

ShawnCplus 456 Code Monkey Team Colleague
"SELECT * FROM participants WHERE participantID = '.$participantid.'";

remove the periods between '.$participantid.'

ShawnCplus 456 Code Monkey Team Colleague

I usually like to take the time and explain why its wrong but I'm lazy today so I'll just fix it.

<?php
class DBconnection {
  private $host="localhost";
  private $user="root";
  private $password=null;
  private $database="classTest";

  private $conn;
  private $db;

  private static $instance = null;

  private function __construct() {
    $this->conn=mysql_connect($this->host, $this->user, $this->password);
    $this->db=mysql_select_db($this->database);
  }

  public static getInstance()
  {
    if(self::$instance === null) {
      self::$instance = new self;
    }
    return self::$instance;
  }

  public function getConnection()
  {
    return $this->conn;
  }
}


// ExecuteSql should NOT extend DBconnection, it just doesn't make any damn sense
class ExecuteSql {
  public static function executeSql($sql) {
    $db = DBconnection::getInstance();
    $runSql=mysql_query($sql, $db->getConnection()) or die ("ERROR: Database connection error");

    if (@mysql_num_rows($runSql) == 1) {
      return "VALID";
    } else {
      return "INVALID";
    }
  }
}


// Once again, why the hell is this extending DBconnection?
class Login {
  public function __construct($username, $password) {
    // NOOOO!!!!!!!!!!!!   DBconnection::__construct();
    echo ExecuteSql::executeSql("SELECT id FROM login WHERE username='$username' AND password='$password'");
  }
}

If you want an explanation ask, otherwise just continue on not reading documentation like you were before.

somedude3488 commented: Nice use of the singleton method. +4
ShawnCplus 456 Code Monkey Team Colleague

Well I can guarantee you haven't tried what you said because you'd get a bunch of errors. A) You're not calling a function, B) you have overlapping/unclosed quotes, C) because of A you have unnecessary commas.

Go look at http://www.php.net because I can also guarantee you haven't looked there yet.

ShawnCplus 456 Code Monkey Team Colleague

Whoops, forgot that file() returns an array so here's how it should look.

$contents = implode("\n", file('filename'));
$contents = preg_replace('/(<cat:\d+?>).+?(<begad:\d+?>)/sm', '\1\2', $contents);
$contents = explode("\n", $contents);

foreach($contents as $line => $stuff) {
 // each $stuff is one entry
}
ShawnCplus 456 Code Monkey Team Colleague

Post your new code, its easier than guessing what you changed.

ShawnCplus 456 Code Monkey Team Colleague

If you've gotten the error "Supplied argument is not a valid MySQL resource" you're in luck because so has everyone else that has ever used PHP... ever. The error is caused by a number of things including: Your query is wrong, you failed to connect to the database or you selected the wrong database.

Now, before you go start modifying your code make sure you've used the correct username, password and host for your mysql_connect function and you've selected the correct database. If you've done this and you're still getting an error follow the steps below.

So to figure out which of these happened we're going to use the mysql_error() function which tells us what went wrong last:1) Your connection string should look something along the lines of the following:

$conn = mysql_connect('host', 'user', 'pass');
if(!$conn) {
  // echo or use die() here, your choice.
  echo mysql_error();
}

2) Your database select statement should look similar:

$dbselect = mysql_select_db('dbname');
if(!$dbselect) {
  // once again, echo or die your choice
  echo mysql_error();
}

3) Finally do the same for your mysql_query() call:

$result = mysql_query('SELECT * FROM some_table WHERE blah = "blah"');
if(!$result) {
  echo mysql_error();
}

If these steps don't solve your error use the Daniweb Search functionality to find other people with similar problems, I can guarantee you aren't the first.

Finally as a LAST resort, and I emphasize last because, as I said, your question has been asked before, post a new topic being as …

Will Gresham commented: Great post. Whether people will look is a different matter... +2
nav33n commented: Good work! :) I hope people read this before creating new threads with title "Error: Supplied argument is not a valid resource! Plzzz help.." +11
jomanlk commented: Good place for a beginner to start learning the basics of DB connection handling +0
ShawnCplus 456 Code Monkey Team Colleague

change all of the file read logic to just be $file = file('filename') then use

$file = preg_replace('/(<cat:\d+?>).+?(<begad:\d+?>)/sm', '\1\2', $file);

Then $file is your entire file with the fixed strings, each data item on its own line.

ShawnCplus 456 Code Monkey Team Colleague

Ok, so they serve the same purpose. Just replace explode("|", $val) with preg_split('/[\|\^]/', $val) and it should work. If it doesn't try replacing \| with just | .

ShawnCplus 456 Code Monkey Team Colleague

heh, you're not making sense. At first you're saying | and ^ are both delimiters but now they're junk and can be thrown away? What I'm trying to get at is that if | is used to delimit strings and ^ are used to delimit fields then its a different solution than if they both delimit fields.

ShawnCplus 456 Code Monkey Team Colleague

I'm not exactly sure what you want to do, the two examples you posted are the same except for a newline after the <cat #> tag

ShawnCplus 456 Code Monkey Team Colleague

What are the two used for, or are they used to delimit the same things?

ShawnCplus 456 Code Monkey Team Colleague

Don't know, do echo mysql_error(); in between $getAll= and $rows =

ShawnCplus 456 Code Monkey Team Colleague

I like the minimalist PHP in this tutorial and I have to somewhat disagree with the posters who commented more on the HTML syntax than the php. It is a tutorial on PHP and not HTML. Someone who is learning PHP probably shouldn't be too nit picking there and focus on the subject at hand.
On the other hand - this might be just a bit TOO minimalist and part two needs a whole lot more substance. I am a perl programmer with a minimal familiarity with PHP and it took me only a few minutes to not only read the whole thing but to understand the basic concepts of embedded scripting. I wil check back and look at part two when it comes out.

Well most of the stuff isn't nitpicking, if you're just starting PHP it is VERY important to start off with the right concepts, syntax and practices.

SeanOBrian commented: good points nicely put +0
ShawnCplus 456 Code Monkey Team Colleague

move the echo '</table>'; outside the loop. or just put </table> before </body> and remove the echo altogether

ShawnCplus 456 Code Monkey Team Colleague

well yeah, the fact that you left out that it said data.Student is pretty big :) lowercase Student on line 32 , case is important, that should fix it

Tonkz commented: Thank You +1
ShawnCplus 456 Code Monkey Team Colleague

K, last addition, if this doesn't give us something then I'm fresh out of ideas. replace mysql_select_db() with

$dbselect = mysql_select_db('data', $conn);
if(!$dbselect) {
  die('Couldn\'t use database: ' . mysql_error());
}
ShawnCplus 456 Code Monkey Team Colleague

Interesting because I don't see anywhere in your code where you're querying a 'data' table. If it couldn't find the database it would give you Unknown database 'data' not Table 'data' doesn't exist .

Is that all of the code or is that just a bit of it? Also, repost your code with the changes.

ShawnCplus 456 Code Monkey Team Colleague

Not necessarily the problem but this code

if (!$conn)
{
  die('Could not connect: ' . mysql_error());
}

Should be moved to line 4.

ShawnCplus 456 Code Monkey Team Colleague

Your query is failing. Try placing this after your query call

if (!$result) {
    die('Invalid query: ' . mysql_error());
}