
mcc_22ri
Members-
Posts
26 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
mcc_22ri's Achievements

Member (2/5)
0
Reputation
-
Can't account for spaces in my database when echoing out data?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
I thought maybe it was a leprechaun because I'm a mick .... guess not ... haha -
Can't account for spaces in my database when echoing out data?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
Thanks Josh, That's brillant! I just have one quick question for you. How did you go about figuring that out? What was your thought process behind what you did? Thanks again! -
Can't account for spaces in my database when echoing out data?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
Hi jesirose and everyone! I appreciate the reply. I changed things up a little bit and the code seems is working. The below code isn't very secure so I figured out a way to make it so (or so I think. Look at the code in this forum post). I'm still trying to figure out how to add a - in between city names. For example, instead of Las%20Vegas las-vegas would be better but I'm a little confused on how to do that? Any pointers anyone? http://whatsmyowncarworth.com/auto/Las%20Vegas <?php include('init.php'); // connection to database if (isset($_GET['u'])) { $city = mysql_real_escape_string(urldecode($_GET['u'])); // protection against mysql injection if (ctype_alnum(str_replace(' ', '', $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"]; } } } } ?> -
Can't account for spaces in my database when echoing out data?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
Brillant! It's now working! I just have to work on making the URL prettier. I'm assuming I would have to edit my .htaccess to fix the spacing issue? http://whatsmyowncarworth.com/auto/Las%20Vegas <?php include('init.php'); // connection to database if (isset($_GET['u'])) { $city = mysql_real_escape_string(urldecode($_GET['u'])); // protection against mysql injection if ($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 $_GET['u']; } } } } ?> -
Can't account for spaces in my database when echoing out data?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
Hey Josh, Thanks for the reply. My mistake, I wasn't quite sure what you meant. Below are a few examples of what my current php syntax outputs. Everything currently works besides "Las Vegas". What do you think? http://whatsmyowncarworth.com/auto/miami http://whatsmyowncarworth.com/auto/providence http://whatsmyowncarworth.com/auto/albany http://whatsmyowncarworth.com/auto/boston http://whatsmyowncarworth.com/auto/las-vegas <--- not echoing city name http://whatsmyowncarworth.com/auto/Las%20Vegas <--- not echoing city name -
Can't account for spaces in my database when echoing out data?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
Hi Josh and Jesirose, I appreciate the replies. Josh, I echoed out your above code and I the results didn't change. Jesirose, I'm a little confused at your explantation. What in the syntax would I need to edit? Thanks! -
Hi Everyone, What I'm trying to do is echo out information from a mysql database into my URL. I have done that (please see below code) but what I haven't figured out yet is for the code to handle spaces or two words. For example, if you visit the below URLs the page will echo out the city name (which is what I want) but I have a city called "Las Vegas" in my mysql database which is obviously two words and when I type in las vegas, las-vegas or Las Vegas etc ... at the end of the URL the code isn't echoing out anything. I also just recently added a urldecode within my code to see if that works but it appears it isn't. What am I doing wrong? What do I have to change in my syntax? Thanks everyone! http://whatsmyowncarworth.com/auto/miami http://whatsmyowncarworth.com/auto/providence http://whatsmyowncarworth.com/auto/albany http://whatsmyowncarworth.com/auto/boston http://whatsmyowncarworth.com/auto/las-vegas <--- not echoing city name http://whatsmyowncarworth.com/auto/Las%20Vegas <--- not echoing city name <?php include('init.php'); // connection to database if (isset($_GET['u'])) { $city = mysql_real_escape_string(urldecode($_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"]; } } } } ?> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> .htaccess RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /auto/cars.php?u=$1 [NC]
-
Getting Mysql Error when I echo data from my database?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
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"]; } } } } ?> -
Getting Mysql Error when I echo data from my database?
mcc_22ri replied to mcc_22ri's topic in PHP Coding Help
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"]; } } } } ?> -
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 Everyone, I'm getting an internal server error when I add the .htaccess file. When I delete the file from my folder the URLS are working but when I add it I'm getting the below error. I'm attempting to rewrite my URLS. I'm trying to make them more SEO friendly. I'm trying to append the $city name from my MySql database onto my URL. Below is the error code and syntax for my pages. (I uploaded the .htaccess so you can view the error code) Error code As of right now I'm attempting to echo $city; to see if my coding is working but I wasn't expecting a internal servor problem. Any thoughts? Thanks for everyones help! http://whatsmyowncarworth.com/auto/cars.php http://whatsmyowncarworth.com/auto/Albany <<--- I'm trying to append city names within my URLS http://whatsmyowncarworth.com/auto/Boston http://whatsmyowncarworth.com/auto/Massachusetts cars.php <?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; } } } ?> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> .htaccess file RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . * - [L] RewriteRule ^(.*)$ http://whatsmyowncarworth.com/auto/cars.php?u=$1 [NC]
-
Hi, I'm trying to use certain keywords/phrases from my mysql database and taking that information and using it in my urls/meta tags. These are the steps I've already done. 1. I've connected to my database 2. I've declared the variables 3. I tested the variables in a sentece to see if they were working. It seems they are. See links below. http://whatsmyowncarworth.com/auto/table.php (this is my data that I'm playing with) http://whatsmyowncarworth.com/auto/urls.php (this is variables that are working. I create a $city and $state variable) For me this is where the confusion starts to come into play .... Here's my question. What do I need to do next? Do I need to write a script or something along those links to create my URLS? what would that script look like? Does it have to be a different page? Thanks for everyones help! Below is the code for my website so far. http://whatsmyowncarworth.com/auto/urls.php <?php include('init.php'); $sql = "SELECT State, City FROM cars"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $state = $row['State']; $city = $row['City']; echo 'Hi, I\'m from '. $state . '. I live in the city of '. $city; ?>
-
Hi Everyone, I've have a basic outline of what I need to do to rewrite my URLS. If what I say is below false or if you think I'm missing something please let me know. I want my urls to look something like this mysite.com/cars/for-sale/albany-new-york/2002-ford-explorer 1. I have to write a mysql scrip that will "take" or "grab" the data from the mysql database. I have to save this script by itself. I'm going to call this script cars.php 2. I have to rewrite my .htaccess that will account for my URL changes. I see all of the above happening in two pages. The "cars.php" page and ".htaccess" page. What do you guys think? Am I comptely off with my assessment or does more work needed to be done? Give me your thoughts. Thanks everyone!
-
Hi noXstyle and PFMaBiSmAd. I appreciate the responses but I'm a little confused as to how they code show appear on my website? What should/shouldn't I do? Also, the code that noXstyle wrote I'm not going to use it on my website but theirs one small piece of the code I don't understand. It's this part foreach($_POST as $k=>$v) ${$k} = mysql_real_escape_string($v); Where did you get the $k and $v variables from? The rest of the code I can read/understand but that's one part that does not make any sense to me. Please advise and thanks for everyones help!
-
Hi noXstyle and everyone! I was playing around with the code and got it for a few mins but if you clicked "submit" and didn't enter any information then blank info. was being inserted into my database. I changed the code around a little bit and now it really can't work. Do I have to declare the id? or perhaps my if statement is messed up. Is that where I'm going wrong? Thanks everyone! <?php include('init.php'); $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); $address = mysql_real_escape_string($_POST['address']); $state = mysql_real_escape_string($_POST['state']); $city = mysql_real_escape_string($_POST['city']); $sql="INSERT INTO customers (first_name, last_name, address, state, city) VALUES('$firstname','$lastname','$address','$state','$city')"; if (!mysql_query ($firstname && $lastname && $address && $state && $city)) { } else echo "You must fill the entire form!"; ?>