Jump to content

[SOLVED] Where Clause Help


hank9481

Recommended Posts

I have a table of 30 different ID's. I have data in each row related to a particular ID, and based on a sort menu, I want to be able to jump to each where I have a page showing the data describing the selected ID.

 

Such as = /2018/previews.php?abbr=atl.php

 

The problem is, I cannot figure out how to make it work. For example, when I select something in my menu, it does nothing. Here's the code. Help me!

 

$result = mysql_query("SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE A.abbr=".$abbr." LIMIT 1") or die(mysql_error());

while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) {

 

Link to comment
Share on other sites

ok.. jesus christ that is 1 seriously extended sql.. but you don't have single quotes encasing your abbr

 

do:

 

'{$abbr}'

 

instead of

 

".$abbr."

 

and I'm not sure if u can do all those joins :S but if u can than go for it..but u prolly dun rly need to join all those tables =\

Link to comment
Share on other sites

Having another issue, hoping to get help.

 

My page above now works, but I am working on creating a webform to input data. Here's the PHP Info-

 

//ASSIGN FORM VALUES

$team_id=$_POST["team_id"];

$review=$_POST["review"];

$outlook=$_POST["outlook"];

$x_player=$_POST["x_player"];

$x_text=$_POST["x_text"];

$bo_player=$_POST["bo_player"];

$bo_text=$_POST["bo_text"];

$year=$_POST["year"];

$spec_hit=$_POST["spec_hit"];

$spec_hit_text=$_POST["spec_hit_text"];

$spec_pitch=$_POST["spec_pitch"];

$spec_pitch_text=$_POST["spec_pitch_text"];

$proj=$_POST["proj"];

$in=$_POST["in"];

$out=$_POST["out"];

$l1=$_POST["l1"];

$l2=$_POST["l2"];

$l3=$_POST["l3"];

$l4=$_POST["l4"];

$l5=$_POST["l5"];

$l6=$_POST["l6"];

$l7=$_POST["l7"];

$l8=$_POST["l8"];

$l9=$_POST["l9"];

$sp1=$_POST["sp1"];

$sp2=$_POST["sp2"];

$sp3=$_POST["sp3"];

$sp4=$_POST["sp4"];

$sp5=$_POST["sp5"];

$rp=$_POST["rp"];

$grade=$_POST["grade"];

$question=$_POST["question"];

 

//INSERT DATA

mysql_query("UPDATE previews SET team_id='$team_id', review='$review', outlook='$outlook', x_player='$x_player', x_text='$x_text', bo_player='$bo_player', bo_text='$bo_text', year='$year', spec_hit='$spec_hit', spec_hit_text='$spec_hit_text', spec_pitch='$spec_pitch', spec_pitch_text='$spec_pitch_text', proj='$proj', in='$in', out='$out', l1='$l1', l2='$l2', l3='$l3', l4='$l4', l5='$l5', l6='$l6', l7='$l7', l8='$l8', l9='$l9', sp1='$sp1', sp2='$sp2', sp3='$sp3', sp4='$sp4', sp5='$sp5', rp='$rp', grade='$grade', question='$question' WHERE team_id='{$team_id}'");

 

//CLOSE OUT CONNECTION

mysql_close($dbh);

?>

 

Can someone help me?

Link to comment
Share on other sites

It looks to me like you are using some reserved keywords. I think in and out are both reserved keywords (google mysql reserved keywords and the first on the list will take you to a mysql page showing a list of such). The simple solution is to put backwards quotes ( ` ) around each field name ie( instead of review='$review' have `review`='$review' ).

 

Also, as an aside, I sure hope you are validating your input, because else, you're leaving your db wide open.

 

I hope that my above comments about reserved keywords help you out.

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.