PDA

View Full Version : php code error in browser


MaravillaEnt
04-16-2009, 02:37 PM
after following video 7 in php beginners tutorial and writing the code word for word... i got this error.

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\myfirstproject\connections\connection. php on line 10

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\myfirstproject\dwc.php on line 7

this is the result in my browser for my http://localhost/myfirstproject/dwc.php



...and this is the result in my browser for my http://localhost/myfirstproject/connections/connection.php

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\myfirstproject\connections\connection. php on line 10

davidj
04-16-2009, 03:17 PM
post your code

davidj
04-16-2009, 03:20 PM
also read the error

the top error is probably causing all the others so its this we need to look at

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource

Check the spelling of the database name. Compare both code and the database itsself

davidj
04-16-2009, 03:22 PM
also

localhost links are only accessible to you on your network so posting them is pointless

MaravillaEnt
04-16-2009, 05:10 PM
here is dwc.php


<?php
require_once("Connections/connection.php"); // database connection

//////////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
//////////////////////////////////////////////////


echo $row['field2'];



?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

here is code for my connection.php


<?php
//////////////////////////////////
$database = "dwc";
$username = "maravilla";
$password = "villa22";
//////////////////////////////////


$link = @mysql_connect('localhost', $username, $password);
$db = mysql_select_db($database, $link);

?>

davidj
04-16-2009, 05:22 PM
ok

its a warning but we need to find out why its doing it

try this

where you have

$db = mysql_select_db($database, $link)add this to the end of the line

die('unable to connect to mysql server: ' . mysql_error())so it looks like this

$db = mysql_select_db($database, $link) or die('unable to connect to mysql server: ' . mysql_error());

then run it

MaravillaEnt
04-16-2009, 06:31 PM
ok so after putting this in for connection.php code...


<?php
//////////////////////////////////
$database = "dwc";
$username = "maravilla";
$password = "villa22";
//////////////////////////////////


$link = @mysql_connect('localhost', $username, $password);
$db = mysql_select_db($database, $link) or die('unable to connect to mysql server: ' . mysql_error());

?>


i got this message..



Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\myfirstproject\connections\connection. php on line 10
unable to connect to mysql server: Access denied for user 'maravilla'@'localhost' (using password: YES)

davidj
04-16-2009, 07:07 PM
your connection is wrong

username and password

MaravillaEnt
04-17-2009, 01:18 AM
well man ive tried setting up my user manger with the same user name and password as the one ive typed in dreamweaver but im getting errors.. this is starting to be very time consuming.. i hate not knowing what im doing.. so when is your next class.. im going to have to get a mic..

edbr
04-17-2009, 02:12 AM
cleaned reading glasses and decided to keep quiet!

davidj
04-17-2009, 09:29 AM
you need to setup a connection to your database

your username and password are wrong

this has nothing to do with dreamweaver

in your connection script try the following


//////////////////////////////////
$database = "dwc";
$username = "root";
$password = "";
//////////////////////////////////