Jump to content

Passing $string variable into mysql query


spangle1187

Recommended Posts

I have echoed the $query string and I was missing data so have reassembled the order:

 

	$input = "Sam";
		$string = "clientName == '$input'";


		$table_id = 'booking'; 	
		$query ="SELECT * 
				FROM booking
				WHERE. '$string' ";


		$test = mysql_query($query);	

		echo $query;

 

and this is now showing the following for the $query string:

 

SELECT * FROM booking WHERE. 'clientName == 'Sam''

 

which is correct but I still have a warning associated with

 

	$test = mysql_query($query);

so this is where I will look now

Link to comment
Share on other sites

A query that looks like

SELECT * FROM booking WHERE. 'clientName == 'Sam'' 

is not correct. Notice the "." after the WHERE and the single quote before the column name clientName and the extra single quote at the end. It should look like:

SELECT * FROM booking WHERE clientName == 'Sam' 

 

You code to create the query is wrong. It should be

<?php
$input = "Sam";
$string = "clientName == '$input'";
$table_id = 'booking'; 	
$query ="SELECT * FROM booking WHERE $string";
$test = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
?>

 

I added the "or die" clause for debugging purposes.

 

Ken

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.