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

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
hustler
Forum Newbie
Posts: 6
Joined: Thu Jul 21, 2005 2:26 am

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

Post 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!";
?>
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$conn versus Sconn
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Good eye feyd!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

having error_reporting set to E_ALL should have told you what was wrong immediately, btw.. :)
Post Reply