Bad use of colname?? HELP

Reply

Join Date: Aug 2008
Posts: 24
Reputation: ocbphoto is an unknown quantity at this point 
Solved Threads: 1
ocbphoto ocbphoto is offline Offline
Newbie Poster

Bad use of colname?? HELP

 
0
  #1
Nov 18th, 2008
I am not sure what i am doing wrong, can someone help me please.

I have my DB which contains

- Manufacturer Table
- Model Table (this one contains also the year field)

I want to be able to choose Manufacturer>Model>Year will be display in the text area but nothing changes!

Thank you



  1. <?php require_once('Connections/XXXX.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  
  8. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  9.  
  10. switch ($theType) {
  11. case "text":
  12. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13. break;
  14. case "long":
  15. case "int":
  16. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17. break;
  18. case "double":
  19. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  20. break;
  21. case "date":
  22. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23. break;
  24. case "defined":
  25. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26. break;
  27. }
  28. return $theValue;
  29. }
  30. }
  31.  
  32. $editFormAction = $_SERVER['PHP_SELF'];
  33. if (isset($_SERVER['QUERY_STRING'])) {
  34. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  35. }
  36.  
  37. mysql_select_db($database_Web_dbP321, $Web_dbP321);
  38. $query_fxmanu = "SELECT * FROM manufacturer ORDER BY manufacturer_name ASC";
  39. $fxmanu = mysql_query($query_fxmanu, $Web_dbP321) or die(mysql_error());
  40. $row_fxmanu = mysql_fetch_assoc($fxmanu);
  41. $totalRows_fxmanu = mysql_num_rows($fxmanu);
  42.  
  43. $colname_fxmodel = "1";
  44. if (isset($_POST['manu'])) {
  45. $colname_fxmodel = $_POST['manu'];
  46. }
  47. mysql_select_db($database_Web_dbP321, $Web_dbP321);
  48. $query_fxmodel = sprintf("SELECT * FROM model WHERE manufacturer_id = %s ", GetSQLValueString($colname_fxmodel, "int"));
  49. $fxmodel = mysql_query($query_fxmodel, $Web_dbP321) or die(mysql_error());
  50. $row_fxmodel = mysql_fetch_assoc($fxmodel);
  51. $totalRows_fxmodel = mysql_num_rows($fxmodel);
  52.  
  53. $colname_fxyear = "-1";
  54. if (isset($_POST['model'])) {
  55. $colname_fxyear = $_POST['model'];
  56. }
  57. $colname1_fxyear = "-1";
  58. if (isset($_POST['manu'])) {
  59. $colname1_fxyear = $_POST['manu'];
  60. }
  61. mysql_select_db($database_Web_dbP321, $Web_dbP321);
  62. $query_fxyear = sprintf("SELECT * FROM model WHERE manufacturer_id = %s AND manufacturer_id = %s ", GetSQLValueString($colname_fxyear, "int"),GetSQLValueString($colname1_fxyear, "int"));
  63. $fxyear = mysql_query($query_fxyear, $Web_dbP321) or die(mysql_error());
  64. $row_fxyear = mysql_fetch_assoc($fxyear);
  65. $totalRows_fxyear = mysql_num_rows($fxyear);
  66. ?><table width="402" border="1">
  67. <tr>
  68. <td width="392" height="125"><form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  69. <label>
  70. <select onchange="document.form1.submit()" name="manu" id="manu">
  71. <?php
  72. do {
  73. ?>
  74. <option value="<?php echo $row_fxmanu['manufacturer_id']?>"<?php if (!(strcmp($row_fxmanu['manufacturer_id'], @$_POST['manu']))) {echo "selected=\"selected\"";} ?>><?php echo $row_fxmanu['manufacturer_name']?></option>
  75. <?php
  76. } while ($row_fxmanu = mysql_fetch_assoc($fxmanu));
  77. $rows = mysql_num_rows($fxmanu);
  78. if($rows > 0) {
  79. mysql_data_seek($fxmanu, 0);
  80. $row_fxmanu = mysql_fetch_assoc($fxmanu);
  81. }
  82. ?>
  83. </select>
  84. </label>
  85. <label>
  86. <select onchange="document.form1.submit()" name="model" id="model">
  87. <?php
  88. do {
  89. ?>
  90. <option value="<?php echo $row_fxmodel['manufacturer_id']?>"<?php if (!(strcmp($row_fxmodel['manufacturer_id'], @$_POST['model']))) {echo "";} ?>><?php echo $row_fxmodel['model_name']?></option>
  91. <?php
  92. } while ($row_fxmodel = mysql_fetch_assoc($fxmodel));
  93. $rows = mysql_num_rows($fxmodel);
  94. if($rows > 0) {
  95. mysql_data_seek($fxmodel, 0);
  96. $row_fxmodel = mysql_fetch_assoc($fxmodel);
  97. }
  98. ?>
  99. </select>
  100. </label>
  101. <label></label>
  102. <label>
  103. <textarea name="text" id="text" cols="45" rows="5"><?php echo $row_fxyear['year']; ?></textarea>
  104. </label>
  105. </form> </td>
  106. </tr>
  107. </table>
  108. <?php
  109. mysql_free_result($fxmanu);
  110.  
  111. mysql_free_result($fxmodel);
  112.  
  113. mysql_free_result($fxyear);
  114. ?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 854
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 138
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Bad use of colname?? HELP

 
0
  #2
Nov 20th, 2008
The problem exists because year is also a function. To make sure it uses your column name use backticks, so in the query it looks like this:

`year`
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC