We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
Dang another sql problem
Topic Started: May 10 2005, 08:47 PM (946 Views)
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Grrr I got another problem.
Quote:
 
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/dasein/public_html/sqltest.php on line 8
Dasein's password is
Dasein is an


What I am trying to do is test a register sql thing. I am trying the basics and working my way up, but I am getting an error. All teh pages ...

install.php // this is adding the main table
 
<?
$dbh=mysql_connect ("localhost", "dasein_dasein", "************") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

mysql_query("CREATE TABLE members
(username VARCHAR(30),
password VARCHAR(30),
type CHAR(9))");
?>



addme.php // this is supposed to add me to the table
 
<?
$dbh=mysql_connect ("localhost", "dasein_dasein", "***************") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

mysql_query("Insert into members (username, password type) Values ('Dasein' 'password' 'admin')");

?>


sqltest.php // this is just supposed to test if it worked. I am getting the error on this page
 
<?
$dbh=mysql_connect ("localhost", "dasein_dasein", "****") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");


$memberget = mysql_query("SELECT * FROM MEMBERS WHERE username = 'Dasein'");

$ACCOUNT_INFORMATION = mysql_fetch_array($memberget);

$password = $ACCOUNT_INFORMATION['password'];

$type = $ACCOUNT_INFROMATION['type'];

echo "Dasein's password is" . $password . "<br />";
echo "Dasein is an" . $type;

?>
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Try removing the single quote brackets from
Code:
 
$memberget = mysql_query("SELECT * FROM MEMBERS WHERE username = 'Dasein'");
:)
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Nice try but no unnfortunaltly.
Offline Profile Quote Post Goto Top
 
Rory
i;m a mess
[ *  *  *  *  *  *  * ]
Das Ein
May 11, 2005 01:47 AM
addme.php // this is supposed to add me to the table
 
<?
$dbh=mysql_connect ("localhost", "dasein_dasein", "***************") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

mysql_query("Insert into members (username, password, type) Values ('Dasein' 'password' 'admin')");

?>

Not sure if it was a type in pasting here, but you were missing a comma between password and type.
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Found the error..
Change
Code:
 
mysql_query("Insert into members (username, password, type) Values ('Dasein' 'password' 'admin')");
to
Code:
 
mysql_query("INSERT INTO `members` (`username`, `password`, `type`) VALUES ('Dasein', 'password', 'admin')") or die(mysql_error());


and
Code:
 
echo "Dasein is an" . $type;
to
Code:
 
echo "Dasein is an" . $type ."";


and...

Code:
 
$type = $ACCOUNT_INFROMATION['type'];
to
Code:
 
$type = $ACCOUNT_INFORMATION['type'];


typo.. :P
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Still getting the error. Do I need to do something other than modding the files, and re-uploading? I mean do I need to use a modify sript or something?
Offline Profile Quote Post Goto Top
 
Rory
i;m a mess
[ *  *  *  *  *  *  * ]
Code:
 

<?php

// mysql_connect.php
define ('DB_USER', 'username');
define ('DB_PASSWORD', 'password');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'databasename');
// Make the connection to the database then select the database.
$dbc = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) OR die('Could not connect to MySQL: ' . mysql_error() );
@mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );
?>


Code:
 

<?php

//addme.php
require_once("mysql_connect.php");

$query = "INSERT INTO members (username, password, type) Values ('Dasein' 'password' 'admin')";

$result = mysql_query($query);
if (!$result) {
  echo "<p>Error: Record could not be inserted</p>";
}

?>


Code:
 

<?php

// sqltest.php
require_once("mysql_connect.php");

$query = "SELECT * FROM MEMBERS WHERE username = 'Dasein'";
$result = mysql_query($query);

if ($result) {
   $account_information = mysql_fetch_array($result);
   $password = $account_information[1];
   $type = $account_information[2];


echo "Dasein's password is $password<br />";
echo "Dasein is an $type";

?>



This is assuming the table is already set up. If not:

Code:
 

<?php
//install.php

require_once("mysql_connect.php");

$result = mysql_query("CREATE TABLE members
(username VARCHAR(30),
password VARCHAR(30),
type CHAR(9))");

if(!$result) {
  echo "Error: Table could not be created.";
}
?>
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
EDIT: I did it in order of top to bottom. On addme.php I got
Quote:
 
Error: Record could not be inserted
Offline Profile Quote Post Goto Top
 
Rory
i;m a mess
[ *  *  *  *  *  *  * ]
I'm assuming you edited the details in mysql.php to your own, and have the table in the database?
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Yes, I tried to redo it, but when I go to your install.php I get
Quote:
 
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/dasein/public_html/install.php on line 14
Quote:
 


Edit: I found a thing called phpMyAdmin. It says that I am there in the table.
Offline Profile Quote Post Goto Top
 
Rory
i;m a mess
[ *  *  *  *  *  *  * ]
i edited the install.php file.

i had an l instead of a ;
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Umm I think everything is good except for one thing. When I run sqltest.php I get
Quote:
 
Parse error: parse error, unexpected $ in /home/dasein/public_html/sqltest.php on line 21

I am probably misssing something odvious again. Code:
Quote:
 
<?php

$dbc = mysql_connect ("localhost", "dasein_dasein", "**********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

// sqltest.php
require_once("mysql_connect.php");

$query = "SELECT * FROM MEMBERS WHERE username = 'Dasein'";
$result = mysql_query($query);

if ($result) {
  $account_information = mysql_fetch_array($result);
  $password = $account_information[1];
  $type = $account_information[2];


echo "Dasein's password is" . $password . "<br />";
echo "Dasein is an" . $type;

?>



It seems everything is ok, but the error on line 21 :/
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
You forgot a closing
Code:
 
}
near the end of the script..

Specifically, change
Code:
 
if ($result) {
 $account_information = mysql_fetch_array($result);
 $password = $account_information[1];
 $type = $account_information[2];


echo "Dasein's password is" . $password . "<br />";
echo "Dasein is an" . $type;
to
Code:
 
if ($result) {
 $account_information = mysql_fetch_array($result);
 $password = $account_information[1];
 $type = $account_information[2];


echo "Dasein's password is" . $password . "<br />";
echo "Dasein is an" . $type;
}
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Yummy! Now I get nothing :lol: umm is the closing tag supposed to be after the echo(s) sani?
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Code:
 
if ($result) {
 $account_information = mysql_fetch_array($result) or die(mysql_error());
 $password = $account_information[1];
 $type = $account_information[2];

}
echo "Dasein's password is" . $password . "<br />";
echo "Dasein is an" . $type;

try using this code, If my calculations are correct(:P) you should get an error.. :lol:
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1