php/MySQL query

software development

#1

we’ve inherited a website which queries a database to display the data on a web page. There are no database connection errors but the webpage does not display any data at all. The same query run directly against the database produces the desired result.

here’s the code:

<?php switch ($jobtype) { Case "c": $jobheader = "Agency Creative"; break; Case "d": $jobheader = "Design"; break; Case "m": $jobheader = "Account Management"; break; Case "p": $jobheader = "Production"; break; Case "s": $jobheader = "Studio/Mac"; break; Case "o": $jobheader = "New Media"; break; Case "n": $jobheader = "News"; break; } $connection = mysql_connect("database fqdn", "database user","database password") or die ("Couldn't connect to server(1)"); $db = mysql_select_db("database name",$connection) or die ("Couldn't select database(1)"); $sql = "SELECT * FROM jobs WHERE jobtype = \"$jobtype\" order by jobnum DESC" or die ("Search error(1)"); $sql_result = mysql_query($sql,$connection) or die ("Couldnt query database(1)"); echo '
'; echo $jobheader; echo '
'; while ($row = mysql_fetch_array($sql_result)) { $jobnum = $row["jobnum"]; $jobtype = $row["jobtype"]; $jobdesc = $row["jobdesc"]; $jobdate = $row["jobdate"]; $jobsalary = $row["jobsalary"]; $joblocation = $row["joblocation"]; $jobtitle = $row["jobtitle"]; echo '
'; echo $jobtitle; echo ' '; echo $jobdesc; echo ' '; if ($jobtype != n) { echo$jobsalary; echo ' , '; echo $joblocation; echo ' Click here to apply for this position
'; } else {echo ' ';} } echo ' '; Any help appreciated. Thanks

#2

I am guessing that your script is expecting register_globals to be enabled, so it doesn’t know what $jobtype is. At first glance, there are a number of other potential problems with the script, such as the lack of a default value in the switch() function and the potential for SQL injection. Also, you could replace these lines:$jobnum = $row["jobnum"]; $jobtype = $row["jobtype"]; $jobdesc = $row["jobdesc"]; $jobdate = $row["jobdate"]; $jobsalary = $row["jobsalary"]; $joblocation = $row["joblocation"]; $jobtitle = $row["jobtitle"]; with this:extract($row);--------
Simon’s website
Save $100 on 1-year plans with promo code [color=#CC0000]SCJESSEY100[/color] (details)


#3

Cheers Simon but all sorted. Had to drop php from v5 to 4 and it all worked.


#4

Good to hear. That pretty much confirms Simon’s belief that register_globals were the culprit; DH PHP4 has register globals set “on”, while PHP5 has it set “off”. That said, the “fixes” Simon suggested are well advised anyway - register_globals set “on” presents a pretty significant security exposure. At any rate, I’m glad you have it working! :wink:

–rlparker


#5

cheers both - will pass your comments back to the web site developer. We merely host the thing… I would give you the URL but the site is a pile of kak and I wouldn’t want to offend your eyes!


#6

Well look who just got himself a fancy new name:- DH DreamMaster!


Simon’s website
Save $100 on 1-year plans with promo code [color=#CC0000]SCJESSEY100[/color] (details)


#7

Woa! I’d never seen that before…looks like the 2000th post triggers it. I suspect that very soon there will be more (Simon, Matttail, Raz, etc.) :wink:

–rlparker


#8

That’s pretty sad, really. I’m half hoping I never make it LOL.


Simon’s website
Save $100 on 1-year plans with promo code [color=#CC0000]SCJESSEY100[/color] (details)


#9

I just had a look at my post count, have I really made that many posts?? :s

Hey rlparker, did you receive your bonus big-screen TV when you reached ‘DreamMaster!’? :stuck_out_tongue:

Mark


Save [color=#CC0000]$50[/color] on DreamHost plans using [color=#CC0000]PRICESLASH[/color] promo code (Click for DreamHost promo code details)


#10

I think I’ve actually had more Wiki edits than posts. Do I qualify for the TV too?


Simon’s website
Save $100 on 1-year plans with promo code [color=#CC0000]SCJESSEY100[/color] (details)


#11

Nope. As far as I can tell, the only “awards” one receives upon reaching these “title” status changes is an increase in being accused of being either a DH employee, a fanboy, or a shill by the occasional rantmeister who can’t understand why one would participate in a forum at that level! :slight_smile:

Of course, YMMV - let me know if any “awards” show up upon your “promotion”! :wink:

–rlparker


#12

I agree…

I don’t think any of us would actually post that much if we stopped to realize what a time-sink it can become. Think of all the whiskey I could have drunk, cigarettes I could have smoked, and women I could have chased in that amount of time…Damn! I have to get my priorities straightened out! :open_mouth:

–rlparker


#13

(.)(.)
…O…

That’s why my life sucks.

Wholly


#14

Considering all the work you do on the wiki, I think you qualify for the TV and a ride in Josh’s Ferrari (all hosting moguls have a Ferrari, right?) :stuck_out_tongue:

Damn, I’ve already cleared a spot for my big-screen too. :frowning:

Mark


Save [color=#CC0000]$50[/color] on DreamHost plans using [color=#CC0000]PRICESLASH[/color] promo code (Click for DreamHost promo code details)