Page 1 of 1

Warning: mysql_query(): supplied argument is not a valid

Posted: Fri Aug 12, 2005 4:33 pm
by hustler
Hi. I have been stuck this on a while now and I can't seem to figure this out. Connection is good after I put up a test on it. I check the columns and that looks good too.

Here are the columns:

Code: Select all

mysql> describe 0001tran;
+------------+---------------------+------+-----+-------------------+-----------
-----+
| Field      | Type                | Null | Key | Default           | Extra
     |
+------------+---------------------+------+-----+-------------------+-----------
-----+
| contact_id | int(11)             |      | PRI | NULL              | auto_incre
ment |
| fname      | varchar(50)         |      |     |                   |
     |
| lname      | varchar(50)         |      |     |                   |
     |
| hphone     | varchar(13)         |      |     |                   |
     |
| cphone     | varchar(13)         |      |     |                   |
     |
| wphone     | varchar(13)         |      |     |                   |
     |
| email      | varchar(50)         |      |     |                   |
     |
| address    | varchar(70)         |      |     |                   |
     |
| city       | varchar(50)         |      |     |                   |
     |
| state      | char(2)             |      |     |                   |
     |
| zip        | bigint(20) unsigned |      |     | 0                 |
     |
| bday       | date                |      |     | 0000-00-00        |
     |
| note       | text                |      |     |                   |
     |
| date_added | timestamp           | YES  |     | CURRENT_TIMESTAMP |
     |
+------------+---------------------+------+-----+-------------------+-----------
-----+
14 rows in set (0.00 sec)
Im getting this error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\projects\addressbook\addcont.php on line 24

Here is the php script to insert values into table 0001tran of database addressbk:
First line is line 9. Line 24 is the $query. On a side note, whats up with the php offset. I tried putting [php = 9] but it didnt go through.

Code: Select all

<?php
	$conn = mysql_connect("localhost", "root", "huidaoguoqu123");
	mysql_select_db("addressbk", $conn);
	
	/* $sql = "INSERT INTO 0001tran (fname, lname, hphone, cphone,
		wphone, email, address, city, state, zip, note) 
		values ('".$_POST['addfname']."', '".$_POST['addlname']."', '".$_POST['addhphone']."',
		'".$_POST['addcphone']."', '".$_POST['addwphone']."', '".$_POST['addemail']."', 
		'".$_POST['addaddress']."', '".$_POST['addcity']."', '".$_POST['addstate']."', 
		'".$_POST['addzip']."', '".$_POST['addnote']."')"; */
		
	$query = "INSERT INTO 0001tran (fname, lname, email) 
		VALUES ('Abdullah', 'Hamad', 'test@test.com')";
	
	echo $query;
	$test = mysql_query($query, Sconn);
	echo "Contact added!";
?>

Posted: Fri Aug 12, 2005 4:42 pm
by neophyte
It would appear to me that you are not connected to your database. So, I'd check to make sure your $conn var is in the right places, double check my username/password/host info, and add:

Code: Select all

mysql_select_db("addressbk", $conn) or die(mysql_error());
Then try again.

Posted: Fri Aug 12, 2005 7:45 pm
by feyd
$conn versus Sconn

Posted: Fri Aug 12, 2005 8:30 pm
by neophyte
Good eye feyd!

Posted: Fri Aug 12, 2005 8:32 pm
by feyd
having error_reporting set to E_ALL should have told you what was wrong immediately, btw.. :)