Jump to content

mssql select error php script help please


randydg

Recommended Posts

SELECT notes.note from notes INNER JOIN notes on custid.notes OUTER JOIN customer.id where username='{$_SESSION['username']}'");

 

im messing something up in the above command here is what I need.

 

There is a table called notes within are custid and note. The custid points to id in table customer.

Im trying to update the field note in notes table. but inorder to do that you verify the username in id in table customer. the rest of the script is fine, I know for 100% its the select part because when i add an or die it dies.

Thanks,

Randy

 

 

 

 

Link to comment
Share on other sites

Try changing

SELECT notes.note from notes INNER JOIN notes on custid.notes OUTER JOIN customer.id where username='{$_SESSION['username']}'");

to

 

SELECT notes.note from notes INNER JOIN notes on custid.notes OUTER JOIN customer.id WHERE customer.username='".$_SESSION['username']."'");

 

Its still not working :( here is my whole script maybe it will help.(I know its on the select line because the select part dies.

<?php
session_start();
if(!(isset($_SESSION['username']))){ ?> <script language="JavaScript">window.open("index.php", "_self")</script><?php }
include("config.php"); 
$query = ("SELECT notes.note from notes INNER JOIN notes on custid.notes OUTER JOIN customer.id WHERE customer.username='".$_SESSION['username']."'");
$result = @mssql_query($query) or die ('Die'); 
$row = mssql_fetch_array($result); ?>
<table align="center" border="0">
<div align="center">title: 
  <?php $_SESSION['username']; ?>
  <br />
</div>
<tr></tr> <form method="post" action="x.php" onSubmit="return validateForm(edit);"> 
<tr><td class="text"><div align="center">Notes: </div></td><td><div align="center">
  <input id="note" type="text" size="50" maxlength="50" name="note" value="<?php echo $row['note'] ?>">
</div></td></tr> 
<tr><td colspan="2" align="center"><div align="center">
  <input type="Submit" value="Update" />
</div></td></tr>

Link to comment
Share on other sites

change

$result = @mssql_query($query) or die ('Die');

to

$result = mssql_query($query) or die ('Died, ahh, here is why <br>'.mssql_error());

 

not 100% on the mssql error bit

 

 

Unfortunately knowing what's wrong in a MSSQL query is not nearly as easy as MySQL.  There is mssql_get_last_message, but I've heard it's unreliable.

 

 

Anyway:

 

 

SELECT notes.note from notes INNER JOIN notes on custid.notes OUTER JOIN customer.id WHERE customer.username='".$_SESSION['username']."'

 

$_SESSION['username'] could be breaking the query, but most likely, it's this:

 

FROM notes INNER JOIN notes on custid.notes OUTER JOIN customer.id

 

You're joining a table on itself without using an alias.  That might be valid if you're not selecting anything, but I doubt it is.  Also, where did custid.notes come from?  The custid table is never mentioned.  Also, what is up with that outer join?

Link to comment
Share on other sites

custid is not a table is in notes table  custid in notes table points to id in customer table.

You're joining a table on itself without using an alias.  That might be valid if you're not selecting anything, but I doubt it is.  Also, where did custid.notes come from?  The custid table is never mentioned.  Also, what is up with that outer join?

Link to comment
Share on other sites

mssql_get_last_message() is no less reliable than mysql_error().  I've never had a problem with it.

 

 

I was thinking it was unreliable, but after reading the notes on the manual page, it only returns the last line.  Would be fine for 99.99999999999% of the time though.

custid is not a table is in notes table  custid in notes table points to id in customer table.

You're joining a table on itself without using an alias.  That might be valid if you're not selecting anything, but I doubt it is.  Also, where did custid.notes come from?  The custid table is never mentioned.  Also, what is up with that outer join?

 

 

 

Naming in MSSQL when you have a database selected goes:

 

.[column] (the brackets are optional, and if you're aimed for portability, discouraged.  They're equivalent to ` in MySQL.)

 

So, custid would be a table, not a column.

 

 

 

What are your tables' schema, and what exactly are you trying to pull?

Link to comment
Share on other sites

A concurrent query isn't possible in PHP since it's single threaded x.x.

 

Or do you mean something else?

 

 

 

But yeah, I don't think I'll ever run into trouble with mssql_get_last_message. I guess I had just subconsciously changed the last line thing to unreliability in my head.  lol.

Link to comment
Share on other sites

I'm not braining very well today (I blame the weather), I meant consecutive queries.  If you don't append or die(mssql_get_last_message()) you could probably miss that message.  I read an article when I was first getting acclimated to MSSQL and it presented some really bizarre scenario that could make it not work.  I don't have the link anymore but I don't think it's anything to fret over either, lol.

Link to comment
Share on other sites

Ok now im getting the following error:

Fatal error: Call to undefined function mssql_error() in notes.php on line 6

 

 

$sqlquery=("Select notes.note from notes INNER JOIN notes on notes.custid = customer.id where username='{$_SESSION['username']}'");

$result = @mssql_query($sqlquery) or die ('Error: '.mssql_error ());

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.