Jump to content

[SOLVED] validate queries...


ag3nt42

Recommended Posts

If you look at the manual, you'll notice that the mysql_query() function returns a boolean for success or failure. So:

<?php
if (($sql = mysql_query($query)) === FALSE)
{
  // FAILURE
}
else
{
  // SUCCESS
}
?>

Link to comment
Share on other sites

right after this post I actually went and looked at the manual and seen that..

 

so i gave it a shot but it keeps coming back to be as failure even tho its still a successful query.

 

 

maybe i'm just stupid and wrote it incorrectly..(I am still new to writing big apps like this in php)..

 

here's my code

mssql_query($UserSql,$con);
	if(mssql_query=='True')
	{
		echo("Table-Query-" . $UserTble . " Status:<font color='green'> Success!</font>");
	}
	else
	{
		echo("Table-Query-" . $UserTble . " Status:<font color='red'> Failed!</font>");
	}

Link to comment
Share on other sites

You had it.....almost

mssql_query($UserSql,$con);
	if(mssql_query) //you don't need the "==true" because what this says is the same thing
	{
		echo("Table-Query-" . $UserTble . " Status:<font color='green'> Success!</font>");
	}
	else
	{
		echo("Table-Query-" . $UserTble . " Status:<font color='red'> Failed!</font>");
	}

Link to comment
Share on other sites

Then maybe it is actually failing.  Do you use mysql_error() to see if it works?

 

Post the code for the query

 

no trust me it isn't failing I have the SQL Studio up in the other room... my cardio is done for today just from running back and fourth to erase the table each time

Link to comment
Share on other sites

did you try my version of the code? if you did, and it's still failing, I'll bug off. If not, might want to try that bit of code.

 

yes i did jonsjava, no need to bug off tho. all help is appreciated.

 

i just want to figure this out cuz its kinda like a miniscule part of this thing..

I don't have to have this but I really really want it. and I've seen others use a similar setup feature (phpBB)..

 

Link to comment
Share on other sites

This is the chunk of code...maybe this will help maybe not but this is the whole thing..

 

//Users Table
$UserTble = $tblPre . "users";
$UserSql = "CREATE TABLE " . $UserTble . "(Username varchar(15),Password varchar(15),Ident int)";

/////////////////////////
/// START SQL INSTALL ///
/////////////////////////
if($ConSuccess=="True"&&$db_Success=="True")
{
mssql_query($UserSql,$con);
	if(mssql_query($UserSql,$con))
	{
		echo("Table-Query-" . $UserTble . " Status:<font color='green'> Success!</font>");
	}
	else
	{
		echo("Table-Query-" . $UserTble . " Status:<font color='red'> Failed!</font>");
	}
}
else
{
echo("Installation Status: FAILED!");
}

Link to comment
Share on other sites

You are doing 2 identical queries, one creates the table you see, the second errors because it exists

 

mssql_query($UserSql,$con);

if(mssql_query($UserSql,$con))

 

 

ok wow!... i'm completely flabergasted by this.. why would it run the query even if I've got in as a condition?

thats completley retarded. It shouldn't be running that query.

 

you are correct tho.

 

care to elaborate as to why php would do something so retarded>?

Link to comment
Share on other sites

"so by yur logic the mssql in the IF statement would build the table as well yes?"

 

It's not my logic, it's how it is working.  So yes, it is trying and it is failing.

 

You are telling it to do it by having it in the IF statement.  Now if you compared the result of the first query instead, then it would work as well.

 

Something like

 

$result = mssql_query($sql);

 

IF ($result)...

Link to comment
Share on other sites

but why" is it running it ?

 

it should be a condition not a statement

 

don't get me wrong revraz you rock man thankx for the help i really appreciate it but i'm freakin out over here as to why it would run that as a statement?

 

when i started learning php never did anyone say anything about running statements inside an IF statemnets condition section

Link to comment
Share on other sites

In order to generate the IF condition, it has to run the command to see if it results in True or False.  So the only way it can continue the IF statement is to run the contents of the IF statement (this applition is your query).  So you can either do a IF condition on the $result of the query, or do a IF statement and run the query at the same time.

 

 

Link to comment
Share on other sites

but why" is it running it ?

 

it should be a condition not a statement

 

don't get me wrong revraz you rock man thankx for the help i really appreciate it but i'm freakin out over here as to why it would run that as a statement?

 

when i started learning php never did anyone say anything about running statements inside an IF statemnets condition section

 

Umm, what do you think ANY function call does?  Just like isset() in an if statement, ANY function call executes.  Some functions return boolean values such as TRUE or FALSE, and so that is tested in the if statement, just like similar boolean logic with other conditions such as "if (1==1 && 0==0) { }".  Read up on booleans and functions when you get a chance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.