Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-14-2011, 04:37 PM   PM User | #1
garevn
New Coder

 
Join Date: Apr 2011
Posts: 95
Thanks: 13
Thanked 1 Time in 1 Post
garevn is an unknown quantity at this point
my query seems its wrong

Hello i am trying to make a simple ajax database search like it explain Here
http://www.w3schools.com/php/php_ajax_database.asp
But when i am trying to display records it pops that i have an error on my query line which is this:
Code:
"SELECT * FROM products WHERE productid = '".$q."'"
The 'q' is the user option.
Did i use an invalid format or what?
Soz i am new in programming
garevn is offline   Reply With Quote
Old 04-14-2011, 07:17 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Your missing and end ;

Otherwise it look ok.


I hope your query looks like this in its entirety.

$query = "SELECT * FROM products WHERE productid = '" . $q . "'";
$result = mysql_query($query);

Last edited by sunfighter; 04-14-2011 at 07:20 PM..
sunfighter is online now   Reply With Quote
Old 04-14-2011, 08:20 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
And if sunfighter's guess isn't right, then show your *REAL* code. The whole thing. Not a fragment.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 04-14-2011, 08:26 PM   PM User | #4
garevn
New Coder

 
Join Date: Apr 2011
Posts: 95
Thanks: 13
Thanked 1 Time in 1 Post
garevn is an unknown quantity at this point
PHP Code:
<?php require_once('Connections/Mysitedb.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_Mysitedb$Mysitedb);
$query_Recordset1 "SELECT * FROM products WHERE productid = '" $q "'";
$Recordset1 mysql_query($query_Recordset1$Mysitedb) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table>
  <tr>
    <td width="132">price</td>
    <td width="138"><?php echo $row_Recordset1['price']; ?></td>
  </tr>
  <tr>
    <td>name</td>
    <td><?php echo $row_Recordset1['productname']; ?></td>
  </tr>
  <tr>
    <td>man</td>
    <td><?php echo $row_Recordset1['manufacturer']; ?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
garevn is offline   Reply With Quote
Old 04-14-2011, 08:47 PM   PM User | #5
garevn
New Coder

 
Join Date: Apr 2011
Posts: 95
Thanks: 13
Thanked 1 Time in 1 Post
garevn is an unknown quantity at this point
oO ok i forgot to add
PHP Code:
$q=$_GET["q"]; 
at the top, it seems start working now
garevn is offline   Reply With Quote
Old 04-14-2011, 09:10 PM   PM User | #6
maniakk
New to the CF scene

 
Join Date: Apr 2011
Location: Georgia
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
maniakk is an unknown quantity at this point
Question quotes

Actually, when yo do the query, you don't actually have to do "SELECT * FROM table WHERE column='" . $request . "'". You can do "SELECT * FROM table WHERE column='$request'"..... I'm new here, but I know a lot of languages! Ask me for help sometime!
maniakk is offline   Reply With Quote
Old 04-14-2011, 09:48 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by maniakk View Post
I'm new here, but I know a lot of languages! Ask me for help sometime!
Okay: Чего должны вы сделать если вы имеете слона в вашем карманн?

Or if you meant computer languages, how do you exit early from an expression in Prolog?

[Just kidding! Welcome. But those who post here don't ask *specific* people for help. They just post a question and anybody who can answers.]
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 04-14-2011, 09:51 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by garevn View Post
oO ok i forgot to add
PHP Code:
$q=$_GET["q"]; 
at the top, it seems start working now
LOL! It's always the really HUGE elephants that seem to vanish when you look for them.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 04-15-2011, 12:06 AM   PM User | #9
munkeyboy
New Coder

 
Join Date: Apr 2011
Posts: 36
Thanks: 0
Thanked 3 Times in 3 Posts
munkeyboy is on a distinguished road
Quote:
Originally Posted by garevn View Post
oO ok i forgot to add
PHP Code:
$q=$_GET["q"]; 
at the top, it seems start working now
You should run $q through the mysql_real_escape_string function before using it in the select statement. Otherwise you leave yourself wide open to a SQL Injection attack.
munkeyboy is offline   Reply With Quote
Old 04-15-2011, 12:42 AM   PM User | #10
maniakk
New to the CF scene

 
Join Date: Apr 2011
Location: Georgia
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
maniakk is an unknown quantity at this point
What should you do if you have an elephant in your pocket?!?!?!?!? cpu languages. and i think either return or break.?...
maniakk is offline   Reply With Quote
Old 04-15-2011, 12:58 AM   PM User | #11
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
LOL! Xorosho!

No, Prolog is a weird language. No such thing as return or break. The answer is: You don't. But you don't need to, if you wrote the code right. <grin/>

*******

Postscript: I admit to using Babelfish to do that translation simply because I didn't want to hunt and peck the Cyrillic characters.

If I'd written it myself I would have said Что должно делать если у вас слон в кармане?

And Babelfish translates that as "What must make if in you elephant in the pocket?"

Which tells me that Babelfish doesn't understand idiomatic language. My Russian is rusty, but I think "у вас" clearly means "you have" in normal speech.

Ahhh...interesting. If you reverse the condition (which probably is more common speech) to "если у вас слон в кармане, Что делать ?" then Babelfish comes up with "if you have elephant in the pocket, what to make?" which I'd accept as close enough. Fun stuff!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 04-15-2011 at 01:10 AM..
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:25 PM.


Advertisement
Log in to turn off these ads.