• 0

[php & mySQL] Can't figure it out!


Question

Hi guys, i really need your help on this one. I am at this moment an intern at a ICT company and I am supposed to make a website for online shopping. The actual website and coding is actually allready done by other interns, but i am supposed to do the styling and design. Also i need to expand some parts of the websites with php.

So lets get to my problem.

I am trying to get information out of 2 tables. The first one is tblorder and second one is tblcustomer. Here are the tables:

tblorder

pkorderid (primary key)

fkklantid

date

excTotal

incTotal

status

tblcustomer

pkklnr (primary key)

klname

....

username

password

In the browser, when it goes to the detail page, it passes the pkorderid through URL and there you get the info all about the order. BUT I am supposed to add also the information of the customers. So what I need to do is to equal fkklantid (tblorder) to pkklnr (tblcustomer) and show the information of the customer.

At this moment (after a lot of trial and error) I have this:

$query3="SELECT * FROM tblklant, tblorder WHERE tblklant.pkklnr = tblorder.fkklantid ORDER BY '" . $HTTP_GET_VARS["pkorderid"] . "'";

$resultq3 = mysql_query($query3) or die ("ERROR: " . mysql_error());

But this is not right. I get only 1 customer and everytime I select an other pkorderid, I still get the same customer. I just don't get it, how am I supposed to do the sql query here????????

Link to comment
https://www.neowin.net/forum/topic/155009-php-mysql-cant-figure-it-out/
Share on other sites

8 answers to this question

Recommended Posts

  • 0

oh no, thats not it. klant = customer in dutch. i translated it for you that you could easily understand. but srry, it got mixed up :unsure:

so i tried it, but it didn't work...

btw, i tried the query on phpMyAdmin, and it worked fine there! :s i just don't understand, why it is not selecting the right information. I think it has to do something with the id wich is passed through URL, the pkorderid. but what???

  • 0

let me show you the whole code:

?$query="SELECT * FROM tblorder WHERE pkorderid='" . $HTTP_GET_VARS["pkorderid"] ."'";
 ?$resultq = mysql_query($query) or die ("FOUT: " . mysql_error());

 ?$query2="SELECT * FROM tblorderregels WHERE fkorderid='" . $HTTP_GET_VARS["pkorderid"] ."'";
 ?$resultq2 = mysql_query($query2) or die ("FOUT: " . mysql_error());

 ?$query3="SELECT * FROM tblklant, tblorder WHERE tblklant.pkklnr = tblorder.fkklantid ORDER BY '" . $HTTP_GET_VARS["pkorderid"] ."'";
 ?$resultq3 = mysql_query($query3) or die ("FOUT: " . mysql_error());

 ?
?>


<?php
while (list($pkorderid, $fkklantid, $datum, $excTotaal, $incTotaal, $status) = mysql_fetch_row($resultq))
	{
	$ud=$pkorderid;
	$vn=$fkklantid;
	$an=$datum;
	$un=$excTotaal;
	$pw=$incTotaal;
	$em=$status;
	}
?>

<?php
while (list($pkklnr, $klnaam, $anaam, $kladres, $pcode, $klwpl, $kltel, $klemail, $banknr) = mysql_fetch_row($resultq3))
	{
	$pkkln=$pkklnr;
	$klnaa=$klnaam;
	$anaa=$anaam;
	$kladre=$kladres;
	$pcod=$pcode;
	$klwp=$klwpl;
	$klte=$kltel;
	$klemai=$klemail;
	$bankn=$banknr;
	}
?>

and in the form I use this to print out the information:

<form action="<?php echo($_SERVER["PHP_SELF"]);?>" method="post">

<input type="hidden" name="bevestiging" value="1">

<input type="hidden" name="pkorderid" value="<?php echo($HTTP_GET_VARS["pkorderid"]);?>">

<table width="60%" border="0">

?<tr>

? ?<td>pkorderid ?: </td>

? ?<td><?php echo($ud);?></td>

?</tr>

?<tr>

? ?<td>Klant id:</td>

? ?<td><?php echo($vn);?></td>

?&lt<?php echo($ud);?>($ud);?> etc.

  • 0

This is unrelated to the original question, but I noticed you're using values right from $_GET without validation in your query. You might want to think about tweaking on that later. If for example your script runs on a server where magic_quotes are disabled then you run the risk of SQL injection attacks.

Googling for php/mysql security and escapequotes would be a good starting place.

  • 0

oh, thx the evn show!! although i didn't made al those codes, an other intern did, and it is not my assignment to secure it better :)

and guys, i got great news!!!!! I GOT IT SOLVED!!!!!! :D :D :D

my teacher came by our company and i tolled him my problem and he just solved it, so easily!!!!!

the code needed an AND statement!!!

this is how it has to be like:

$query3="SELECT * FROM tblklant, tblorder WHERE tblklant.pkklnr = tblorder.fkklantid AND pkorderid = '" . $HTTP_GET_VARS["pkorderid"] ."'";

i love my teacher!! and you to guys!!! THX FOR YOUR HELP TIMDORR

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • How did they source that "small seed of randomness" I wonder.
    • Malwarebytes 5.3.6.205 by Razvan Serea Malwarebytes is a high performance anti-malware application that thoroughly removes even the most advanced malware and spyware. Malwarebytes version 5.xx brings comprehensive protection against today’s threat landscape so that you can finally replace your traditional antivirus. You can finally replace your traditional antivirus, thanks to a innovative and layered approach to prevent malware infections using a healthy combination of proactive and signature-less technologies. While signatures are still effective against threats like potentially unwanted programs, the majority of malware detection events already come from signature-less technologies like Malwarebytes Anti-Exploit and Malwarebytes Anti-Ransomware; that trend will only continue to grow. For many of you, this is something you already know, since over 50% of the users already run Malwarebytes as their sole security software, without any third-party antivirus. What's new in Malwarebytes 5.xx: Unified user experience - For the first time, Malwarebytes now provides a consistent experience across all of our desktop and mobile products courtesy of an all new and reimagined user experience powered by a faster and more responsive UI all managed through an intuitive dashboard. Modern security and privacy integrations - Antivirus and ultra-fast VPN come together seamlessly in one easy-to-use solution. Whether you’re looking for a next-gen VPN to secure your online activity, or harnessing the power of Browser Guard to block ad trackers and scam sites, taking charge of your privacy is simple. Trusted Advisor - Empowers you with real-time insights, easy-to-read protection score and expert guidance that puts you in control over your security and privacy. Malwarebytes 5.3.6.205 changelog: Improved the onboarding experience with minor usability enhancements. Updated My subscription page design for better clarity. Added text explaining Scan notifications settings in Notifications page. Updated firewall filtering profile colors in Windows Firewall Control feature for Windows 11 users. Fixed minor UI issues with Windows Firewall Control feature for Windows 11 users. Fixed various localization and usability glitches. Download: Malwarebytes 5.3.6.205 | 403.0 MB (Free, paid upgrade available) Links: Malwarebytes Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • https://shop.royalmail.com/special-stamp-issues/monty-python
    • Microsoft disables a key graphics feature in Edge by Paul Hill Microsoft has released its new security baseline for its Edge browser version 139, it includes the addition of one setting and the removal of one other. For those that are unaware, these security baselines allow admins to set an organization’s Edge browser settings to the default that Microsoft recommends at any one time. You can download the new package from the Security Compliance Toolkit. With this update, the company is enforcing the default to disable the EnableUnsafeSwiftShader policy. This will help to mitigate potential risks as malicious web content could exploit vulnerabilities in the renderer. SwiftShader is a software-based renderer that serves as a fallback for WebGL in environments without GPU acceleration, such as virtual machines. With Microsoft’s disabling of it, it seems as though this compatibility tool is now seen as a liability. The disabled SwiftShader was the most relevant in virtual machines which are widely used in enterprises, so this change poses the risk of causing a bit of disruption. While the move is a good one for security, those who it affects may want to deviate away from Microsoft’s security baselines. The security baseline announcement also mentions a new Edge for Business security connectors feature which is designed to integrate the browser with security software for DLP and authentication. Microsoft said that these connectors can close critical gaps in enterprise security. You can learn more on the feature’s landing page. Microsoft doesn’t seem to have made the change to SwiftShader due to existing vulnerabilities, instead the move seems to be a proactive security improvement. If you rely on it with your virtual machines, feel free to deviate away from Microsoft’s security baseline, but understand you’re no longer following the company’s security advice.
  • Recent Achievements

    • One Month Later
      chiptuning earned a badge
      One Month Later
    • Week One Done
      harveycoleman123 earned a badge
      Week One Done
    • First Post
      EzraNougat earned a badge
      First Post
    • One Month Later
      westDvina earned a badge
      One Month Later
    • Community Regular
      Bern@rd went up a rank
      Community Regular
  • Popular Contributors

    1. 1
      +primortal
      667
    2. 2
      +FloatingFatMan
      196
    3. 3
      ATLien_0
      154
    4. 4
      Xenon
      132
    5. 5
      wakjak
      102
  • Tell a friend

    Love Neowin? Tell a friend!