ag3nt42 Posted June 3, 2008 Share Posted June 3, 2008 I'm making an sql install file.. and I want to be able to echo "Success" or "Failure" or something like that depending on wether or not the query was succesful. Any ideas? thanx everyone, ag3nt42 Quote Link to comment Share on other sites More sharing options...
obsidian Posted June 3, 2008 Share Posted June 3, 2008 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 } ?> Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 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>"); } Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted June 3, 2008 Share Posted June 3, 2008 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>"); } Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 still getting failure.. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 I tried all of these ways and still getting failure even tho its still populated my database with the correct information Quote Link to comment Share on other sites More sharing options...
revraz Posted June 3, 2008 Share Posted June 3, 2008 Then maybe it is actually failing. Do you use mysql_error() to see if it works? Post the code for the query Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 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>"); } Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted June 3, 2008 Share Posted June 3, 2008 i agree, log in to phpmyadmin or something to check that the query is actually working, the code you have been given is correct and should affirm that it is working, if you are getting failure, i would bet it is actually failing Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
revraz Posted June 3, 2008 Share Posted June 3, 2008 Regardless, do some error checking anyways. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 why do i need to check for errors if I can see plain as day that its working? mysql_error() isn't working.. and php manual doesn't have an mssql_error() listed Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 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. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 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).. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 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!"); } Quote Link to comment Share on other sites More sharing options...
revraz Posted June 3, 2008 Share Posted June 3, 2008 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)) Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 that makes no sense.. i'm only running 1 query the other is inside an IF statement and is used as a condition. so by yur logic the mssql in the IF statement would build the table as well yes? Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 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>? Quote Link to comment Share on other sites More sharing options...
revraz Posted June 3, 2008 Share Posted June 3, 2008 "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)... Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
revraz Posted June 3, 2008 Share Posted June 3, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 3, 2008 Share Posted June 3, 2008 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. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 well then.. shut me up lol.. thanks for the extra info guys.. thanks for pointing that out revraz again i appreciate the help. and now i feel like an arsehole.. soo.. thankxz ag3nt42 Quote Link to comment Share on other sites More sharing options...
revraz Posted June 3, 2008 Share Posted June 3, 2008 Buying me a beer can solve that Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 lol here ya go 8p Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.