problem with statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
surforever
Forum Newbie
Posts: 6
Joined: Tue Apr 20, 2004 12:45 am

problem with statement

Post by surforever »

there is some problem with this statement because the execution stops right before this chunk of code
can anyone help please. thanks

Code: Select all

<?
  $SQL = "SELECT p.position_name AS name FROM positions p, applicant_position ap WHERE p.id=ap.positions_id AND ap.applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI>".$row["name"];
  }

?>
User avatar
llanitedave
Forum Commoner
Posts: 78
Joined: Thu Jan 15, 2004 11:24 am
Location: Las Vegas, NV.

Post by llanitedave »

Does it give you an error?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

could it be something before that causing it to stop execution?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

just a note

you should always use mysql_fetch_array instead of mysql_fetch_assoc.


I would venture to say:
AND ap.applicant_id=".$user_id;

is incorrect.
surforever
Forum Newbie
Posts: 6
Joined: Tue Apr 20, 2004 12:45 am

Post by surforever »

This is the error message that I get:

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/webdev/public_html/webdev/test2/final.php on line 9
P.S. I replaced mysql_fetch_assoc() with mysql_fetch_array() and still get same error


It prints "Wishful positions" and returns that error right after it

Code: Select all

<?
  include ("inc/u_header.php");
  if (isset($_GET["user_id"]))
    $user_id = $_GET["user_id"];
  else
    $user_id=$_SESSION["user_id"];

  $SQL = "SELECT * FROM applicant WHERE id=".$user_id;
  $row = mysql_fetch_array(mysql_query($SQL));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Resume</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="admin.css">
</HEAD>

<BODY TOPMARGIN=2 LEFTMARGIN=2>
<H3 ALIGN=center>Common:</H3>
<TABLE ALIGN=center WIDTH=70% BORDER=0 CLASS=table_border CELLPADDING=2 CELLSPACING=1>
<TR><TD>
<FIELDSET>
<LEGEND><B>Applicant</B></LEGEND>
<TABLE ALIGN=center WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>
<TR>
<TD ALIGN=right>Fullname:<FONT COLOR=red>*</FONT></TD>
<TD><INPUT TYPE="text" NAME="name" READONLY SIZE=50 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["fullname"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Address:</TD>
<TD><INPUT TYPE="text" READONLY NAME="address" SIZE=50 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["address"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>City:<FONT COLOR=red>*</FONT></TD>
<TD><INPUT TYPE="text" READONLY NAME="city" SIZE=40 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["city"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>State:</TD>
<TD><INPUT TYPE="text" READONLY NAME="state" SIZE=40 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["state"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>zip-code:</TD>
<TD><INPUT TYPE="text" NAME="zip" SIZE=40 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["zip"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Phone:</TD>
<TD><INPUT TYPE="text" READONLY NAME="phone" SIZE=40 CLASS=fields MAXLENGTH=60 VALUE="<?=$row["phone"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>Fax:</TD>
<TD><INPUT TYPE="text" READONLY NAME="fax" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["fax"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>Cell:</TD>
<TD><INPUT TYPE="text" READONLY NAME="cell" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["cell"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>E-mail:<FONT COLOR=red>*</FONT></TD>
<TD><INPUT TYPE="text" NAME="email" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["email"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>web-site:</TD>
<TD><INPUT TYPE="text" NAME="website" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["website"]?>"></TD>
</TR>
</TABLE>
</FIELDSET>
</TD>
</TR>
<TR>
<TD>
<FIELDSET>
<LEGEND><B>Wishful positions:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT p.position_name AS name FROM positions p, applicant_position ap WHERE p.id=ap.positions_id AND ap.applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI>".$row["name"];
  }
?>
</UL>
</FIELDSET><BR>
<FIELDSET>
<LEGEND><B>Skills:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT skill, expertise FROM skills WHERE applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_array($result))
  {
    echo "<LI>".$row["skill"]."; Expertise:".$row["expertise"];
  }
?>
</UL>
</FIELDSET><BR>
<FIELDSET>
<LEGEND><B>Projects:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT url, responsibilities, comments FROM portfolio WHERE applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI><B>URL:</B><A HREF="".$row["url"]."">".$row["url"]."</A>;<BR><B>Responsibilities:</B> ".$row["responsibilities"].";<BR><B>Comments:</B> ".$row["comments"]."<P>";
  }
?>
</UL>
</FIELDSET><BR>
<FIELDSET>
<LEGEND><B>Questions to employer:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT a_date, q_text FROM answers WHERE applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI><B>Date:</B> ".date("d.m.Y", strtotime($row["a_date"]))."<BR><B>Text:</B> ".$row["q_text"]."<P>";
  }
?>
</UL>
</FIELDSET>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
?>
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

try:
SELECT p.position_name AS name FROM positions p, applicant_position ap WHERE p.id=ap.positions_id AND ap.applicant_id='$user_id';
surforever
Forum Newbie
Posts: 6
Joined: Tue Apr 20, 2004 12:45 am

Post by surforever »

unfortunately that didn't work
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Well best bet then is to test your SQL queries directly, instead of within PHP. I always do this anyway before putting them into my documents, just to be sure they work how I intended.
Post Reply