advancedfuture Posted June 21, 2008 Share Posted June 21, 2008 What I am trying to do here is check the database to see if the client invoice exists prior to showing the "generate invoice" button. And if it does exist I want it to show the "view invoice" button. However even though the invoice does exist it never hits the else statement! It just keeps showing the "generate invoice" button. Any help would be appreciated! I'm sure its simple.. //check to see if invoice is already generated before echoing the generate //invoice button! $queryDelete = "SELECT * FROM invoices WHERE clientId = '$clientId'"; $resultsDelete = mysql_query($queryDelete) or die("error"); if(mysql_num_rows($resultsDelete) <= 0) { echo '<input type="submit" name="generateInvoice" value="Generate Invoice" />'; } //If Invoice Exists Show Invoice else { echo '<input type="submit" name="viewInvoice" value="View Invoice" />'; } Quote Link to comment Share on other sites More sharing options...
DanielWhite Posted June 21, 2008 Share Posted June 21, 2008 Try changing this: if(mysql_num_rows($resultsDelete) <= 0) { echo '<input type="submit" name="generateInvoice" value="Generate Invoice" />'; } //If Invoice Exists Show Invoice else { echo '<input type="submit" name="viewInvoice" value="View Invoice" />'; } To this: if(mysql_num_rows($resultsDelete) == 0) { echo '<input type="submit" name="generateInvoice" value="Generate Invoice" />'; } //If Invoice Exists Show Invoice else if(mysql_num_rows($resultsDelete) == 1) { echo '<input type="submit" name="viewInvoice" value="View Invoice" />'; } Quote Link to comment Share on other sites More sharing options...
advancedfuture Posted June 21, 2008 Author Share Posted June 21, 2008 newp :\ I've been trying several things no results :\ Quote Link to comment Share on other sites More sharing options...
advancedfuture Posted June 21, 2008 Author Share Posted June 21, 2008 wow i feel like an idiot. Then again I havnet slept since yesterday. haha I was trying to pass $clientId in my sql query but I hadn't even defined the variable yet so it was blank. hahaha. I think I need a Rockstar to wake me up.... Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 21, 2008 Share Posted June 21, 2008 If the code you have really doesnt work... well php can be finicky(I've noticed on occasion) so I'd say switch the clauses to be like "if (num_rows > 0) echo view; else echo generate. I don't see any other reason why the code doesn't work. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 @dannyb785: He already solved it. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 21, 2008 Share Posted June 21, 2008 @dannyb785: He already solved it. my bad. the "problem solved" option wasn't check for the thread. How did you know it was solved? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 my bad. the "problem solved" option wasn't check for the thread. How did you know it was solved? I'm pretty sure he said it right before your post. wow i feel like an idiot. Then again I havnet slept since yesterday. haha I was trying to pass $clientId in my sql query but I hadn't even defined the variable yet so it was blank. hahaha. I think I need a Rockstar to wake me up.... =P Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 22, 2008 Share Posted June 22, 2008 ^ lol. whats funny about that is that I assumed that his reply(that said problem solved) was the guy who first suggested help but was saying "I need to wake up, my bad". Quote Link to comment Share on other sites More sharing options...
chuckman Posted June 22, 2008 Share Posted June 22, 2008 <?php $queryDelete = "SELECT * FROM invoices WHERE clientId = '".$clientId".'"; ?> your var $clientid won't pass if it's in your code as a string 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.