ultimachris Posted April 1, 2009 Share Posted April 1, 2009 Hello all, im going round the bend wondering whyyy im getting a mysql query error on this code: <?php $mysql = mysql_connect("*******", "**********", "*******", "********"); if (mysql_errno()) { printf("Connect Failed: %s\n", mysql_connect_error()); exit(); } else { $sql = "INSERT INTO tickets (testfield) VALUES ('".$_POST["testfield"]."')"; $res = mysql_query($mysql, $sql); if ($res === TRUE) { echo "A new ticket has been added."; } else { printf("could not insert record: %s\n", mysql_error($mysql)); } mysql_close ($mysql); } ?> What on earth am i doing wrong??? Hope you can help me guys, you rule! Chris Link to comment https://forums.phpfreaks.com/topic/152089-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/ Share on other sites More sharing options...
Mchl Posted April 1, 2009 Share Posted April 1, 2009 resource mysql_query ( string $query [, resource $link_identifier ] ) As you can see, query goes first, then the connection resource. You have it the other way round. Link to comment https://forums.phpfreaks.com/topic/152089-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-798739 Share on other sites More sharing options...
ultimachris Posted April 1, 2009 Author Share Posted April 1, 2009 thanks MCHL, will try this out! so it should be ($sql, $mysql) hmmm....now it says "could not insert record: No database selected " Link to comment https://forums.phpfreaks.com/topic/152089-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-798756 Share on other sites More sharing options...
Mchl Posted April 1, 2009 Share Posted April 1, 2009 No wonder. You did not use mysql_select_db Link to comment https://forums.phpfreaks.com/topic/152089-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-798764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.