Executing SQL statements using PHP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Executing SQL statements using PHP

Postby kkillgasmm » 20. January 2007 18:52

im trying to insert a table into one of my databases using the following code...

<?php

$db= mysql_connect("localhost", "root", "");

mysql_select_db("people2", $db);

$sql = "CREATE TABLE mytable (col1 INT, col2 VARCHAR(10))";
mysql_query($sql, $conn);

mysql_close($db);

?>

but when i run the script i get this error message:


Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\xampp\htdocs\xampp\Mystuff\new\sqltest.php on line 8


Anyone know the problem here? I'm using the code from a PHP book i have

thanks
kkillgasmm
 
Posts: 9
Joined: 06. January 2007 17:32
Location: Liverpool, UK

Postby Wiedmann » 20. January 2007 19:47

Code: Select all
mysql_query($sql, $conn);

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

What is "$conn"? You never defined this variable in your script.

Hint:
What variable have you used for the mysql_connect()?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby kkillgasmm » 20. January 2007 23:02

ah yea thanks, i managed to solve this problem in the end!

the book i was using defined the connection as $db, then it said to use $conn as the argument!

i would have thought they would have done a bit of proof reading before publishing the book??
kkillgasmm
 
Posts: 9
Joined: 06. January 2007 17:32
Location: Liverpool, UK


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 107 guests