Forum Moderators: coopster

Message Too Old, No Replies

Warning: mysql error(): supplied argument is not a valid MySQL-Link re

Insert Fails although code runs in phpmyadmin

         

am3081

5:24 pm on Apr 2, 2009 (gmt 0)

10+ Year Member



I am working on taking some data out of a text file and inserting it into a mysql database for some web work. My mysql_query() line keeps throwing supplied argument is not valid MySQL-Link resource. I have tried everything and looked everywhere, am I missing something stupid?

Here is my connection code and the error it throws.

$con = mysql_connect("localhost","xx","xx") or die('Could not connect: ' . mysql_error());

mysql_select_db("WIM",$con) or die(mysql_error());

//sets query string from previously run code
$query = substr($strsql,0, strlen($strsql)-5);

$result = mysql_query($query) or die(mysql_error($result)." query: X".$query."x");

mysql_close($con);

Throws the error:

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /var/www/wim/test.php on line 134
query: XInsert into wim03_08 (fips, stid , dir, ln , year, month, day, hour, dow, class, twght, numaxles, A, Asp, B, Bsp, C, Csp , D, Dsp, E, Esp, F, Fsp, G, Gsp, H, Hsp, I, Isp , J , Jsp , K , Ksp, L, Lsp) Values (36,'000199',1,2,08,03,01,00,6,08,0228,04,041,039,097,111,048,012,042,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(36,'000199',1,2,08,03,01,00,6,08,0253,04,039,039,098,117,061,012,055,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)x

Having created this table previously this insert statement successfully executes in phpmysql, any help?

[edited by: eelixduppy at 6:23 pm (utc) on April 2, 2009]
[edit reason] removed specifics [/edit]

coopster

8:18 pm on Apr 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, am3081.

What is line 134?

Yuen

4:41 am on Apr 8, 2009 (gmt 0)

10+ Year Member



u mean the database connection code?

u try this..
<php
$host="localhost";
$user="root";
$password="";

$conn = mysql_connect($host,$user,$password);
mysql_select_db("database_name");
?>

Habtom

5:24 am on Apr 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have two different connection names: $con on your first post and $conn on the second post.

Your query is not correct:

Insert into wim03_08 (fips, stid , dir, ln , year, month, day, hour, dow, class, twght, numaxles, A, Asp, B, Bsp, C, Csp , D, Dsp, E, Esp, F, Fsp, G, Gsp, H, Hsp, I, Isp , J , Jsp , K , Ksp, L, Lsp) Values (36,'000199',1,2,08,03,01,00,6,08,0228,04,041,039,097,111,048,012,042,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(36,'000199',1,2,08,03,01,00,6,08,0253,04,039,039,098,117,061,012,055,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)

should be two queries instead of one as shown below:

Insert into wim03_08 (fips, stid , dir, ln , year, month, day, hour, dow, class, twght, numaxles, A, Asp, B, Bsp, C, Csp , D, Dsp, E, Esp, F, Fsp, G, Gsp, H, Hsp, I, Isp , J , Jsp , K , Ksp, L, Lsp) Values (36,'000199',1,2,08,03,01,00,6,08,0228,04,041,039,097,111,048,012,042,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);

Insert into wim03_08 (fips, stid , dir, ln , year, month, day, hour, dow, class, twght, numaxles, A, Asp, B, Bsp, C, Csp , D, Dsp, E, Esp, F, Fsp, G, Gsp, H, Hsp, I, Isp , J , Jsp , K , Ksp, L, Lsp) Values (36,'000199',1,2,08,03,01,00,6,08,0253,04,039,039,098,117,061,012,055,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);

coopster

12:25 pm on Apr 8, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The INSERT query syntax is acceptable. It is a multiple values list:

INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas.

Resource: INSERT Syntax [dev.mysql.com]


You have two different connection names: $con on your first post and $conn on the second post.

Two different members, two different posts, Habtom ;)
Welcome to WebmasterWorld, Yuen.

But I believe Habtom is right about something being amiss with your connection.