Hi All
More help required by a newbie, thx in advance...
I am trying to run a query - $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState='" . mysql_real_escape_string($_POST['b']) .
-
"'&&(bizCity='" . mysql_real_escape_string($_POST['c']) . "')';
what is the proper way to format this?
thx again
17 2183
Switch your quotes around...
First thanks Scooby for your help.
I am trying to post data from 2 different scripts to the query you see below - $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
-
'"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
the post data is coming from 2 different pages.
This one generates a drop down - <?php
-
/* Program name: buildSelect.php
-
* Description: Program builds a selection list
-
* from the database.
-
*/
-
?>
-
<html>
-
<head><title>Building info by state</title></head>
-
<body>
-
<?php
-
$user="XXXXXXXXXXt";
-
$host="XXXXXXXXXXXX";
-
$password="XXXXXXXXX";
-
$database = "XXXXXXXXXXXX";
-
-
$cxn = mysqli_connect($host,$user,$password,$database)
-
or die ("couldn't connect to server");
-
$query = "SELECT DISTINCT bizState FROM BIZ_APARTMENTS ORDER BY bizState";
-
$result = mysqli_query($cxn,$query)
-
or die ("Couldn't execute query.");
-
-
/* create form containing selection list */
-
echo "<form action='processform41.php' method='POST'>
-
<select name='b'>\n";
-
-
while ($row = mysqli_fetch_assoc($result))
-
{
-
extract($row);
-
echo "<option value='$bizState'>$bizState\n";
-
}
-
echo "</select>\n";
-
echo "<input type='submit' value='Select State in which building is located'>
-
</form>\n";
-
?>
-
</body></html>
-
and passes the info post [b] to this script - <?php
-
-
$username="XXXXXXXXX";
-
$password="XXXXXXXXXX";
-
$database="XXXXXXXXXXt";
-
$table="BIZ_APARTMENTS";
-
$column="bizState";
-
-
error_reporting(E_ALL);
-
mysql_connect("localhost",$username,$password);
-
@mysql_select_db($database) or die( "Unable to select database");
-
-
-
$query = "SELECT DISTINCT bizCity FROM BIZ_APARTMENTS WHERE bizState='" . mysql_real_escape_string($_POST['b']) . "'";
-
-
-
$result=mysql_query($query);
-
$ret = mysql_query($query) or die(mysql_error());
-
$num=mysql_numrows($result);
-
-
-
-
-
-
-
echo "<b><center>Cities in State</center></b><br><br>";
-
-
/* create form containing selection list */
-
echo "<form action='city.php' method='POST'>
-
<select name='c'>\n";
-
-
$i=0;
-
while ($i < $num) {
-
-
-
$city=mysql_result($result,$i,"bizCity");
-
-
-
echo "<option value='$city'>$city\n";
-
$i++;
-
}
-
echo "</select>\n";
-
echo "<input type='submit' value='Select City in which building is located'>
-
</form>\n";
-
print_r($result);
-
-
?>
-
-
which in turn should pass both post[b] and post[c] to this form for output - <?
-
$username="xxxxxxxxxx";
-
$password="xxxxxxxxxxx";
-
$database="xxxxxxxxx";
-
$table="xxxxxxxxx";
-
$column="bizState";
-
error_reporting(E_ALL);
-
-
mysql_connect("localhost",$username,$password);
-
@mysql_select_db($database) or die( "Unable to select database");
-
-
-
-
-
$query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
-
'"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
-
-
-
-
$result=mysql_query($query);
-
$ret = mysql_query($query) or die(mysql_error());
-
$num=mysql_numrows($result);
-
-
mysql_close();
-
-
-
-
-
echo "<b><center>Buildings in City</center></b><br><br>";
-
-
$i=0;
-
while ($i < $num) {
-
$name=mysql_result($result,$i,"bizName");
-
$address=mysql_result($result,$i,"bizAddr");
-
$city=mysql_result($result,$i,"bizCity");
-
$state=mysql_result($result,$i,"bizState");
-
$zip=mysql_result($result,$i,"bizZip");
-
$phone=mysql_result($result,$i,"bizPhone");
-
$email=mysql_result($result,$i,"bizEmail");
-
-
echo "<b>Name: $name</b><br>Phone: $phone<br>Type: $type<br>Address: $address<br>City: $city<br>State: $state<br>Zip: $zip<br>Email:$email<br>";
-
-
$i++;
-
}
-
print_r($city);
-
?>
-
-
BUT I am getting error message
Notice: Undefined index: b in /home/attorney/public_html/in-url.com/bigdump/city.php on line 15
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
thanks again, the help i have received from this forum has been priceless..
Could it be the && in the query? Try replacing that with AND..
that’s not it, there’s simply no field named "b" in the last script.
so how do I transfer data from the field [b] in the first script into the 3rd script so the query in the 3rd script can use fields 'b' and 'c'? - $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
-
'"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
you could add a hidden field to pass down the b value - echo '<input type="hidden" name="b" value="' . $_POST["b"] . '">';
First, let me say thank you again to both of you for you time and effort in helping me.
In my 3rd script, I am still getting the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
this is the script: - <?
-
$username="xxxxxxxxxx";
-
$password="xxxxxxxxx";
-
$database="xxxxxxxxxx";
-
$table="BIZ_APARTMENTS";
-
$column="bizState";
-
-
-
mysql_connect("localhost",$username,$password);
-
@mysql_select_db($database) or die( "Unable to select database");
-
-
-
-
-
$query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
-
'"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
-
-
-
-
$result=mysql_query($query);
-
$ret = mysql_query($query) or die(mysql_error());
-
$num=mysql_numrows($result);
-
-
mysql_close();
-
-
-
-
-
echo "<b><center>Buildings in City</center></b><br><br>";
-
-
$i=0;
-
while ($i < $num) {
-
$name=mysql_result($result,$i,"bizName");
-
$address=mysql_result($result,$i,"bizAddr");
-
$city=mysql_result($result,$i,"bizCity");
-
$state=mysql_result($result,$i,"bizState");
-
$zip=mysql_result($result,$i,"bizZip");
-
$phone=mysql_result($result,$i,"bizPhone");
-
$email=mysql_result($result,$i,"bizEmail");
-
-
echo "<b>Name: $name</b><br>Phone: $phone<br>Type: $type<br>Address: $address<br>City: $city<br>State: $state<br>Zip: $zip<br>Email:$email<br>";
-
-
$i++;
-
}
-
print_r($city);
-
?>
-
-
Also I am not getting any output either.
Thank you very much,
Josh
there are 2 closing parentheses missing in the SQL.
Dormilich
Dude you are awesome, thanks ever so much. It always amazes when the s*** actually works.
Danke
thinking like a parser helps. and experience.
Sorry about the profanity, it the Bronx in me that just comes out sometimes :-)
that’s why there is an "edit" link.
How many years have you been programming?
started with HTML and JS about 10 years ago and doing PHP for about 5 years. but that’s not much since I do it for a hobby.
I wish I kept up with it all from when I started.
I bought a TRS80 model1 in 1980, I was 13 and started doing BASIC.
The hard drive was a cassette recorder LOL.
Nowadays my motivation is business, and the use of php mysql to generate large dynamic sites for seo/marketing. I have five kids to feed.
Whats the best way (MAYBE THIS SHOULD BE A NEW THREAD) to convert those ugly urls with all those funky characters such as'?' into something much cleaner and seo friendly?
"?" is not a funky character … but yes, that should be asked in another thread.
Atli 5,058
Expert 4TB @riverdale1567
For Apace servers: mod_rewrite. There have been a few discussion on this here already, but you may want to start by checking this article out.
If you have any questions about this then I would appreciate it if you started a new thread. It's just better that way :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marcin Dobrucki |
last post by:
I've been having some problems with a parse error that I can't figure
out (PHP 4.3.11 on Solaris9). Sample code:
<?php
// getting strange parse errors on this
class A {
var $value;
function...
|
by: Wescotte |
last post by:
The error message Parse error: syntax error, unexpected $end in FILE on
line X is one I run into frequently and I know the cause is I missed an
ending quote.
Is there an easy way to determine...
|
by: kestrel |
last post by:
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is going on.
Heres what i have
<?php...
|
by: rhys |
last post by:
My Gurus and Angels --
Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
|
by: SilvaZodiac |
last post by:
Hi everyone,
I'm still rather new to PHP code, and I have a syntax error. I've tried several different solutions, but it won't fix. It seems to suggest that I need a new bracket somewhere in the...
|
by: Lawrence Krubner |
last post by:
Imagine a template system that works by getting a file, as a string, and
then putting it through eval(), something like this:
$formAsString = $controller->command("readFileAndReturnString",...
|
by: fburn |
last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux.
I receive an error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or...
|
by: akohistani |
last post by:
I am having Parse error problem with my newly purchased Php upload script I have uploaded the script and I get the error below
Parse error: syntax error, unexpected $end in URL/functions.php on...
|
by: paulrajj |
last post by:
hi to all,
i am getting syntax error on my code..
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\xampp\htdocs\Dummy\paulraj\matrim\exam.php on line 62
...
|
by: riverdale1567 |
last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada.
I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |