PLZ help... mySQL dosent seem 2 like php on my comp...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

PLZ help... mySQL dosent seem 2 like php on my comp...

Post by pb2ya »

ok, i put this code:

<?php
#Connect to the Server
$conn = @mysql_connect("localhost", "", "");
#Select the Database
mysql_select_db("guestbook", $conn);
#Send SQL Query
mysql_query("CREATE TABLE users
(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserName TEXT NOT NULL,
SignUpDate DATE NOT NULL,
UserDescription TEXT,
);",
"$conn");
#Close Connection
mysql_close($conn);
?>

and it comes out as this:

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


plz help.... i typed that stuff in the mysql program, and it works perfectly.... :(
LenHewitt
Forum Newbie
Posts: 10
Joined: Sat Jul 06, 2002 6:13 am
Location: United Kingdom

Post by LenHewitt »

Kill the '@' and then you will get some feedback as to what's going wrong and add an "or die":


$conn = mysql_connect("localhost", "", "")
or die("couldn't connect" . mysql_error());

Chances are you need a username and password supplying for the connection.

Under Windows the deafault Username is "ODBC"
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

naw naw

Post by pb2ya »

tha mySQL_connect("localhost", "", ""); thang works perfectly. The only thang wrong is that the sql querys wont work fo some reason
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

this is tha prollem

Post by pb2ya »

ok, the code is this:
( Green Text means working code, RED text means non-working code.)
<?php
#Connect to the Server
$conn = @mysql_connect("localhost", "", "");
#Select the Database
mysql_select_db("guestbook", $conn);

#Send SQL Query
mysql_query("CREATE TABLE users
(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserName TEXT NOT NULL,
SignUpDate DATE NOT NULL,
UserDescription TEXT,
);",
"$conn");


#Close Connection
mysql_close($conn);
?>
yall PLZ help :?
LenHewitt
Forum Newbie
Posts: 10
Joined: Sat Jul 06, 2002 6:13 am
Location: United Kingdom

Post by LenHewitt »

see next post
Last edited by LenHewitt on Sat Jul 06, 2002 6:24 pm, edited 1 time in total.
LenHewitt
Forum Newbie
Posts: 10
Joined: Sat Jul 06, 2002 6:13 am
Location: United Kingdom

Post by LenHewitt »

Try making your query into a variable:


Code: Select all

$query = "CREATE TABLE 
                                     users
                 (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY
                  , UserName TEXT NOT NULL
                  , SignUpDate DATE NOT NULL
                  , UserDescription TEXT
                 )";

$result = mysql_query($query,$conn)
    or die("query failed" , mysql_error());


I notice that you do have an unrequired comma after the last item in your query.
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

still dont work...

Post by pb2ya »

ok, heres the code i put:
$query = "CREATE TABLE users
(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserName TEXT NOT NULL,
SignUpDate DATE NOT NULL,
UserDescription TEXT,
);"
mysql_query($query, $conn);<--------Line 23
heres tha error:


Parse error: parse error, unexpected T_STRING in c:\program files\apache group\apache\htdocs\MySQL\sendSQLquery.php on line 23
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

:) thx

Post by pb2ya »

:) it worked. thx yall. i owe yall 1
LenHewitt
Forum Newbie
Posts: 10
Joined: Sat Jul 06, 2002 6:13 am
Location: United Kingdom

Post by LenHewitt »

Try the code posted in my previous post above. It should solve your problem

The fact that it is reporting an error at Line23 usually means the error is ABOVE that line.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

$query = "CREATE TABLE users
(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserName TEXT NOT NULL,
SignUpDate DATE NOT NULL,
UserDescription TEXT,
);" <-----You shouldn't put this semi-colon here
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

ty it worked

Post by pb2ya »

:lol: :lol: :lol: it worked, thx. im making a message board, so i might have to ask more soon
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

lol ok, another question:

Post by pb2ya »

ok, i used what u guys taught me to make the aministrator control panel(im makin a message board).
now, i made the user signup page:

Code: Select all

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Signup to the MessageBoards</title>
</head>
<body>
<h1>Message Boards</h1>
<h2>User Signup</h2>
<form method="post" action="signup2.php">
<h3>Type in your desired username:<br /></h3>
<input type="text" name="username">
<h3>Type in your desired password:<br /></h3>
<input type="password" name="password">
<br />
<input type="submit" value="Submit" name="submit" /><input type="reset" value="Reset" />
</form>
</body>
</html>
then the signup2.php page:

Code: Select all

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP page</title>
</head>
<body>
<?php
$newusername = $HTTP_POST_VARS&#1111;"username"];
$newpassword = $HTTP_POST_VARS&#1111;"password"];
$conn = mysql_connect("localhost", "", "");
mysql_select_db("guestbook", $conn);
$query = "INSERT INTO users(username, password) VALUES ($newusername, $newpassword)";
$result = mysql_query($query,$conn)or die("query failed");
if ($result != FALSE)
&#123;
     echo"Query Was Made.";
&#125;
else
&#123;
    echo"Query was not made";
&#125;
?>
</body>
</html>
again, it dosent work. im thinking because of the INSERT INTO thing where im using variables. plz help.
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

nevermind

Post by pb2ya »

i fixed it myself dont reply.
Post Reply