Jump to content

Recommended Posts

Hi Everyone,

 

I'm attempting to extract data from my mysql database and use that data in my URLS. I'm almost getting the desired result I need but I'm getting a nasty error when I try the code (the below code is below).

 

I've noticed when I leave out 

if (mysql_num_rows($data===1));

I'm not getting an error. Should I just simply leave this coding out? but if I do won't it be less secure?

 

Thanks!

 

http://whatsmyowncarworth.com/auto/Houston

http://whatsmyowncarworth.com/auto/Seattle

 

code that's not working <<-- I'm getting an error message with this code but it does echo out the desired result.

 

<?php 
ob_start(); // handle redirects

include('init.php'); // connection to database

if (isset($_GET['u']))
{
$city = mysql_real_escape_string($_GET['u']); 

if (ctype_alnum($city)) // protection against mysql injection
  {
     $data = mysql_query("SELECT State, City FROM cars WHERE City='$City'" );
     if (mysql_num_rows($data===1));
    {
      echo $city;
    }
  }
}

?>

 

>>>>>>>>>>>>

 

Code that's working

 

<?php 
ob_start(); // handle redirects

include('init.php'); // connection to database

if (isset($_GET['u']))
{
$city = mysql_real_escape_string($_GET['u']); 

if (ctype_alnum($city)) // protection against mysql injection
  {
     $data = mysql_query("SELECT State, City FROM cars WHERE City='$City'" );
    {
      echo $city;
    }
  }
}

?>

Hi thorpe,

 

I tried the below code. I'm not getting any errors but it's not echoing out the code.  I've also attached a pic of my mysql database where I'm extracting the data.

 

<?php

ob_start(); // handle redirects

include('init.php'); // connection to database

if (isset($_GET['u'])) {

$city = mysql_real_escape_string($_GET['u']); 
	// protection against mysql injection
if (ctype_alnum($city)) {
	$data = mysql_query("SELECT State, City FROM cars WHERE City='$city'" );
	if (mysql_num_rows($data) > 0) {
		while ($row = mysql_fetch_assoc($data)) {
		    echo $row["City"];
		}
	}
}
}

?>

post-104609-13482403552909_thumb.jpg

Brillant. It's working!

 

Below is my code. All I did was simply add ob_end_flush(); at the top of the page and it's working. Should I have done this another way or was I correct in how I did it?

 

Thanks again!

 

<?php

ob_start(); // handle redirects

ob_end_flush();

include('init.php'); // connection to database

if (isset($_GET['u'])) {

$city = mysql_real_escape_string($_GET['u']); 
	// protection against mysql injection
if (ctype_alnum($city)) {
	$data = mysql_query("SELECT State, City FROM cars WHERE City='$city'" );
	if (mysql_num_rows($data) > 0) {
		while ($row = mysql_fetch_assoc($data)) {
		    echo $row["City"];
		}
	}
}
}

?>

Placing ob_end_flush() immediately following ob_start() is pointless.

 

Your code, as it stands, does not require any buffering.  You can safely remove ob_start() and ob_end_flush() from your code.  Here's more info: ob_start && ob_end_flush

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.