Pages: 12Next
Current Page: 1 of 2
PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 04:40PM

<?php
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$db=mysql_select_db('dvd') or die("could not connect ".mysql_error);

Performing SQL query
$query = 'SELECT * FROM actor';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

?>


it works unitil you get to the mysql_select_db
part


Im stuck just trying to simply make a connection

Any ideas?



Edited 1 time(s). Last edit at 04/02/2008 04:44PM by Catling.

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 04:46PM

wat error are u getting... did u make a dbase called dvd and do u have a table in it?

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 05:06PM

Parse error: syntax error, unexpected T_STRING in C:\wamp\apps\phpmyadmin2.11.5\connectionscript.php on line 11


Ive changed my dvd database name to moviedatabase

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 05:13PM

<?php
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$db=mysql_select_db('dvd') or die("could not connect ".mysql_error);

Performing SQL query <<<<<<this line
$query = 'SELECT * FROM actor';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

?>





lol is this ur code?


u have - performing sql query there...

delete it or comment it out



Edited 1 time(s). Last edit at 04/02/2008 05:14PM by stevenmartin99.

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 05:14PM

Me and my friend are trying to do it between us and his database is dvd and mine is movie database lol

Thats why it looks stupid lol



Line 11 is "Performing SQL query" --- I commented this out

and the error I get now is "could not connect mysql_error"


Please help me



Edited 2 time(s). Last edit at 04/02/2008 05:16PM by Catling.

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: yfastud (Moderator)
Date: April 02, 2008 05:22PM

$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';
You have to provide user and password in order to connect :-(

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 05:26PM

<?
$dbhost = 'localhost';
$dbuser = 'username';
$password = 'pasword';
mysql_connect($dbhost,$dbuser,$password);

$dbname = 'dvd';
@mysql_select_db($dbname) or die( "Unable to select database"winking smiley;

$query = 'SELECT * FROM actor';

$result = mysql_query($query);

echo $result;
?>




try this code.... use ur username password and dbname if different

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 05:27PM

yfastud Wrote:
-------------------------------------------------------
> > $dbhost = 'localhost';
> $dbuser = '';
> $dbpass = '';
>
> You have to provide user and password in order to
> connect :-(



But I don't have a username and password


Where do I create one?

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 05:28PM

use 'root' as username
and '' as password



this is the defualt

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 05:44PM

I've tried it and now all I get is a blank browser


help lol

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 05:50PM

thats right...


what exactly are u trying to do

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 05:51PM

ive realised i need to return something and put:


echo $result;



now all i get back is :


Resource id #3


What does this mean?

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 05:52PM

im just trying to return the result of my sql query by displaying all the actors

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 05:54PM

well resourse id3 just lets you know that $result has data in it.


u need to display this...

tell me what colums u have in ur table...

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 05:56PM

Actor_ID
Forename
Surname
Age
Date_of_Birth
Nationality
Character_Names
Photo

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 06:03PM

forget echo result


after

$result = MySQL_query($query);

you need this



if(MySQL_num_rows($result) > 0)
{
echo "<table border=1 >";
echo "<tr><td> Actor ID</td><td>Forename</td><td>Surname</td>><td>Age</td><td>Date of Birth</td><td>Nationality</td><td>Character Names</td><td>Photo</td></tr>";
while($row = MySQL_fetch_array($result))
{ echo "<td>{$row['Actor_ID']}</td>";
echo "<td>{$row['Forename']}</td>";
echo "<td>{$row['Surname']}</td>";
echo "<td>{$row['Age']}</td>";
echo "<td>{$row['Date_of_Birth']}</td>";
echo "<td>{$row['Nationality']}</td>";
echo "<td>{$row['Character_Names']}</td>";
echo "<td>{$row['Photo']}</td></tr>";
}

echo "</table>";}

?>



Edited 1 time(s). Last edit at 04/02/2008 06:03PM by stevenmartin99.

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 06:08PM

Thats a great help thanks


Now i have something to work with I cant start attempting things I need to do


Cheers

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 06:09PM

if u need anymore help just ask

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: Catling (---.cable.ubr01.telf.blueyonder.co.uk)
Date: April 02, 2008 06:15PM

Im glad you said that lol

Say I have a search bar that a user can enter an actors name and it returns the result. Obviously, I need to write a script with the SQL query in it but how do I go about making this script work with the seach bar on my web page?



Edited 1 time(s). Last edit at 04/02/2008 06:16PM by Catling.

Options: ReplyQuote
Re: PLEASE HELP: Trouble connecting to my database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: April 02, 2008 06:26PM

first of all what kind of search are u trying to preform?

do u want the to have just one search box? and u can type any thing into it?

a serach box for each column in table and they cant fill in to eeach,,, etc?

do u want it to bring up people with any of the word they serach or only the words they search?

Options: ReplyQuote
Pages: 12Next
Current Page: 1 of 2


Sorry, only registered users may post in this forum.