|
-
Jan 6th, 2003, 08:46 PM
#1
Thread Starter
Hyperactive Member
Dont know what im doing wrong...
Im not sure what im doing wrong, it keeps returning Select Failed! every time. Can you help me fix the problem thanks!
PHP Code:
<?
mysql_connect("localhost","username","password")
or die("Unable to connect to SQL server");
mysql_select_db("jokes")
or die("Unable to select database");
$query = "SELECT * FROM jokes";
$joke = mysql_query($query) or die("Select Failed!");
?>
<?php echo $joke['JokeText'];?>
Last edited by Muk108; Jan 6th, 2003 at 10:38 PM.
-
Jan 7th, 2003, 11:42 AM
#2
Frenzied Member
try this
PHP Code:
<?
mysql_connect("localhost","username","password")
or die("Unable to connect to SQL server");
mysql_select_db("jokes")
or die("Unable to select database");
$query = "SELECT * FROM jokes";
$joke = mysql_query($query);
if (!$joke){echo mysql_error();}
?>
// and this won't work. it will echo Resource ID instead
// need to add mysql_fecth_array() to get this
<?php echo $joke['JokeText'];?>
-
Jan 7th, 2003, 03:33 PM
#3
Thread Starter
Hyperactive Member
Its not returning any errors now, but i can't get it to print out the text from the database. Could you help me do this please. My database is layed out like this...
Code:
CREATE TABLE jokes (
joke_id int(4) NOT NULL auto_increment,
joke_name varchar(50) default NULL,
joke_date datetime NOT NULL default '0000-00-00 00:00:00',
joke_message text,
PRIMARY KEY (joke_id)
) TYPE=MyISAM;
Do you think you could help me display what is in the message part? I am have problems with this. Thank You.
-
Jan 7th, 2003, 03:38 PM
#4
Frenzied Member
Originally posted by phpman
try this
PHP Code:
<?
mysql_connect("localhost","username","password")
or die("Unable to connect to SQL server");
mysql_select_db("jokes")
or die("Unable to select database");
$query = "SELECT * FROM jokes";
$joke = mysql_query($query);
if (!$joke){echo mysql_error();}
while ($row = mysql_fetch_array($joke)){
echo $row['joke_id'];
echo $row['joke_name'];
echo $row['joke_message'];
echo $row['joke_date'];
echo"<br />"\n";
?>
-
Jan 7th, 2003, 04:01 PM
#5
Thread Starter
Hyperactive Member
I tryed it exactly how you put it exept i change the username and password and it got this error. "Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\HTTP\www\test2.php on line 15"
-
Jan 7th, 2003, 04:03 PM
#6
Frenzied Member
oh sorry, change this line
echo"<br />"n";
to this
echo"<br />\n";
-
Jan 7th, 2003, 04:08 PM
#7
Thread Starter
Hyperactive Member
After i fix that i get this error "Parse error: parse error, unexpected $ in C:\HTTP\www\test2.php on line 17"
-
Jan 7th, 2003, 04:13 PM
#8
Frenzied Member
hehe man I am not with it today. ad a } right after the last line you just fixed. so it all should look like this
PHP Code:
<?
mysql_connect("localhost","username","password")
or die("Unable to connect to SQL server");
mysql_select_db("jokes")
or die("Unable to select database");
$query = "SELECT * FROM jokes";
$joke = mysql_query($query);
if (!$joke){echo mysql_error();}
while ($row = mysql_fetch_array($joke)){
echo $row['joke_id'];
echo $row['joke_name'];
echo $row['joke_message'];
echo $row['joke_date'];
echo"<br />\n";
}
?>
-
Jan 7th, 2003, 04:20 PM
#9
Thread Starter
Hyperactive Member
Thank you very much for your help phpman. That works this time.
-
Jan 7th, 2003, 04:28 PM
#10
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|