12 Replies - 2921 Views - Last Post: 24 August 2012 - 04:51 AM Rate Topic: -----

#1 ersaan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 31-May 12

Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 11:15 AM

I have a problem with this mssq_fetch_array() could anyone help me to fix the problem or tell me how to fix it i will be thankfull to everyone who would like to help me :) ..
HERE IS THE CODE :

<?php

$FName = $_POST['FName'];
$LName = $_POST['LName'];
$PHON = $_POST['PHON'];

$myServer = "ERSAAN-PC\SQLEXPRESS";
$myUser = "";
$myPass = "";
$myDB = "Project1";


//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 
  

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");
  
  $query="INSERT INTO dbo.Table1 (ID,FName,LName,PHON) VALUES (NULL,".$FName.",".$LName.",".$PHON.")";
  
[color="#00FFFF"]//here is the problem i don't know how to fix it[/color] 
while($row = mssql_fetch_array($query))
	{
  echo "ID:".$row['ID']."First Name:".$row['FName']."LastName:".$row['LName']."Phone:".$row['PHON'];
	}

mssql_close($dbhandle);

?>


Is This A Good Question/Topic? 0
  • +

Replies To: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3494
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 11:17 AM

mssql expects a PHP resource to be given (the result of the query), not just the SQL string.
Was This Post Helpful? 0
  • +
  • -

#3 ToshNeox  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 100
  • Joined: 10-December 11

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 11:25 AM

You should make $query a real query:

$query = mssql_query("Query here");


Then it will work.

This post has been edited by ToshNeox: 23 August 2012 - 11:31 AM

Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,903
  • Joined: 10-May 07

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 11:30 AM

I would actually suggest not passing the query straight into the command. If it fails, you can always output the variable & visually inspect the query.

$sql = "Select * from whatever";
$result = $mssql_query($sql);
if(!$result) {
  echo "<p>The following sql failed : ".$sql."</p>";
}



Since most new members seem to like to feed variables unchecked right into their sql, it's a nice way of saying "this is why it failed".
Was This Post Helpful? 1
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 11:43 AM

And common frigging sense.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,903
  • Joined: 10-May 07

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 11:44 AM

Common sense is not so common.

Unfortunately "Warning: Mssql_fetch_array(): Supplied Argument Is Not A Valid SQL-" is! lol
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 12:07 PM

Well, it just seems like "my SQL query failed" should be followed immediately by the thought "I wonder why it failed? What is the error?", followed immediately by -- if the query is constructed from variables, not 'SELECT * FROM users' -- "what is the query I'm submitting?"

I agree the error message is less than optimal in this case; but a conscientious programmer would never hit that because they would check whether their SQL call succeeded.
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,903
  • Joined: 10-May 07

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 12:43 PM

View PostJackOfAllTrades, on 23 August 2012 - 03:07 PM, said:

but a conscientious programmer would never hit that because....

because they would validate their variables before introducing them to the database ;)
Was This Post Helpful? 2
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 01:14 PM

That too :) Validate client side, then server side, then submit.

But one step at a time...
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,903
  • Joined: 10-May 07

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 02:26 PM

View PostJackOfAllTrades, on 23 August 2012 - 04:14 PM, said:

But one step at a time...


So this is bad?

$result = $mssql_query("SELECT * FROM TABLE WHERE ID = ".isset($_GET['id']));



Can you do OR statements in the text? (lol)

$result = $mssql_query("SELECT * FROM TABLE WHERE ID = ".isset($_GET['id']||!is_null($_GET['id']));


Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3494
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 23 August 2012 - 10:41 PM

yes, this is bad since isset() and is_null() return booleans, which I doubt you intend to use here.

PS. itís mssql_query() not $mssql_query()
Was This Post Helpful? 0
  • +
  • -

#12 ersaan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 31-May 12

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 24 August 2012 - 03:21 AM

Can u tell me how to fix it cuz i'm tired of this i don't know how to make it work ... : )
Was This Post Helpful? 0
  • +
  • -

#13 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3494
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-

Posted 24 August 2012 - 04:51 AM

do it like in the Manual: http://www.php.net/mssql-query

PS. if youíre too tired, make a break. it helps, trust me.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1