Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


 
 php/mysql problem
Author:  (---.cust.uslec.net)
Date:   02-24-04 12:09

I am having a strange problem that hopefully one of you guru's can help me with. I am new to this, just installed PHP, Apache, and MySQL. I followed the instructions for installing PHP under Windows and am in the process of Testing it all. I have my host up and running. I created the database. I created 2 php files, one for inserting and one for querying.
The insert file works fine. The query doesn't work at all, and I don't know why. Here are the two files:

INSERT FILE
<?php
// Connect to the database
$dbhost = 'localhost';
$dbusername = 'testuser';
$dbpasswd = 'testpassword';
$database_name = 'simple';
$connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
or die ('Couldn\'t connect to server.');
$db = mysql_select_db("$database_name", $connection)
or die('Couldn\'t select database.');

// Generate SQL code to store data on database.
$insert_sql = 'INSERT INTO simple_table (text) VALUES (\'test text, 1,2,3\')';

// Execute SQL code.
mysql_query( $insert_sql )
or die ( 'It Didn\t Work: ' . mysql_error() );

// Tell User we are done.
echo 'Code Inserted';
?>


QUERY FILE
<?php
// Connect to the database
$dbhost = 'localhost';
$dbusername = 'testuser';
$dbpasswd = 'testpassword';
$database_name = 'simple';
$connection =

mysql_connect("$dbhost","$dbusername","$dbpasswd")
or die ('Couldn\'t connect to server.');
$db = mysql_select_db("$database_name", $connection)
or die('Couldn\'t select database.');

// Generate code to retrieve data from database.
$select_sql = 'SELECT text FROM simple_table';

echo $select_sql;

// Retrieve code from database.
$result = mysql_query( $select_sql ) or die ( 'It Didn\t

Work: ' . mysql_error() );

// Display results to user.
while ( $row = mysql_fetch_object ( $result ) )
{
echo $row->text . <br>;
echo 'PHP is working.<br>';
}
?>



All help is GREATLY appreciated!

 Topics Author  Date
 php/mysql problem  new
Doug 02-24-04 12:09 
 Re: php/mysql problem  new
bastien 02-24-04 12:35 
 Re: php/mysql problem  new
Doug 02-25-04 04:17 
 Re: php/mysql problem  new
Mhadf 02-25-04 08:05 
 Re: php/mysql problemSTILL NOT WORKING  new
Doug 02-25-04 09:30 
 Re: php/mysql problem  new
bastien 02-25-04 05:25 
 Re: php/mysql problem  new
Doug 02-25-04 05:43 
 Re: php/mysql problem  new
eon 02-25-04 16:42 
Go to Top  |  Go to Topic  |  Flat View  |  Search 
  |  
New Topic
 Reply To This Message
 Your Name:
 Your Email:
 Subject:
Email replies to this thread, to the address above.
    

Provided By
Phorum