Jump to content

mcc_22ri

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by mcc_22ri

  1. I thought maybe it was a leprechaun because I'm a mick .... guess not ... haha
  2. 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!
  3. 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"]; } } } } ?>
  4. 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']; } } } } ?>
  5. 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
  6. 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!
  7. 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]
  8. 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"]; } } } } ?>
  9. 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"]; } } } } ?>
  10. 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; } } } ?>
  11. 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]
  12. 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; ?>
  13. 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!
  14. 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!
  15. 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!"; ?>
  16. Hi Everyone, I'm trying to figure out why my my form isn't accepting any values I put into it. I've been trying to figure this out for the past 2 hrs and I'm stumped. Any ideas please let me know. Thanks everyone! http://whatsmyowncarworth.com/auto/form2.php <?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 ($firstname && $lastname && $address && $state && $city) { } else echo "You must fill the entire form!"; ?> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> http://whatsmyowncarworth.com/auto/form.php <html> <body> <form method="post" action="form2.php"> <table> <tr> <td>Firstname:</td> <td><input type="text" name="firstname"></td> </tr> <tr> <td>Lastname:</td> <td><input type="text" name="lastname"></td> </tr> <tr> <td>Address:</td> <td><input type="text" name="address"></td> </tr> <tr> <td>State:</td> <td><input type="text" name="state"></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city"></td> </tr> <tr> <td><input type="submit" name="submit" value="Register!"></td> </tr> </table> </form> </body> </html>
  17. Hi Everyone, I have a question regarding rewriting URLS in php while using data from your MySql database. Let's say for example I want to use certain keyword(s) from my database in my meta tags and URLS how would I go about doing that writing that in .htaccess? Would I have to create variables for certain keywords in my MySql database? For example, $product, $location etc .... and then place the above variables in my meta tags and URLS? and then reconfigure my .htaccess? Thanks for everyones help!
  18. Hi Everyone, Please excuse my lack of tech. terminology. I'm in the learning stages of php/myslq Do you know how both the below pages are very similiar. The only thing that's different is the actual location(s). My question is, is the same code being used for all of these template pages? If so, how does the code know differentiate between different states/cities/? Does each state or even city have a different template? <<--- Thinking out loud here, I don't believe so because that would defeat the purpose of php/mysql. What do you think? http://cars.oodle.com/regions/illinois/ http://cars.oodle.com/regions/indiana/ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> http://cars.oodle.com/regions/illinois/ <<--- Assuming this code is being used on the "state template" how does the php/mysql code on this page know how to show data from the Bloomington area of Illinois? (assuming it's not custom code for the above page) http://cars.oodle.com/used-cars/bloomington-il-area/ <<--- Assuming this code is being used on the "cars template" how does the php/mysql code on this page know how to show data from the Bloomington area of Illinois? (assuming it's not custom code for the above page) Thanks everyone!
  19. Thanks mrMarcus. The code is very clear, I appreciate your help!
  20. Hi Everyone, I'm trying to figure out a way to put my MySql data into a table. I'm close to getting this completed by I'm having some trouble. The data I'm inserting isn't being put into the correct tables. I'm not quite sure what I'm doing wrong. Any help? http://whatsmyowncarworth.com/practice/table.php <?php include('init.php'); $result = mysql_query("SELECT * FROM info") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Last Name</th> <th>Address</th> <th>City</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['first_name']; echo "</td><td>"; echo $row['last_name']; echo "</td></tr>"; echo "<tr><td>"; echo $row['address']; echo "</td><td>"; echo $row['city']; echo "</td></tr>"; } echo "</table>"; ?>
  21. Hi Everyone, I'm trying to convert my MySql data into variables so I can use them on my website. For example, if I want to convert a city or even first or last name into a variable. How would I go about doing that? Thanks everyone!
  22. Hi Scootstah, Thanks for the fast reply. I changed mysql to mysqli in my connect.php page. It still isn't working. Perhaps I would make the connection string into a variable and it should work? ...... Old Code <?php $connect_error = 'Sorry we\'re experiencing connection issues'; mysql_connect("localhost","myname","mypassword") or die($connect_error); mysql_select_db('mydatabase') or die($connect_error); ?> New Code <?php $connect_error = 'Sorry we\'re experiencing connection issues'; mysqli_connect("localhost","myname","mypassword") or die($connect_error); mysqli_select_db('mydatabase') or die($connect_error); ?> Thanks!
  23. Hi Everyone, This is a step by step process of what I did. My goal is to extract data from my database and display that information on my website. I'm running into some errors on how I should do that. Perhaps someone can help me out. All opinions welcome! Thanks! >>>>>>>>>>>> The database I made 5 Colums in phpMyAdmin column name user_id (INT) Primary <--Auto Increment first_name (VARCHAR) length 32 last_name (VARCHAR) length 32 address (VARCHAR) length 32 address (VARCHAR) length 32 I then pressed "save" I then inserted data into my phpmyadmin database. (below is my data) user_id first_name last_name address city 1 Bob Jackson 123 I Hope New York 2 Robert Downney 456 I'm Doing Miami 3 Ken Sorenson 789 This Right Las Vegas >>>>>>>>>>>>> I then made a folder on my website called "practice" In that practice folder I also made another folder called "database" In the database folder I made a page called connect.php In the connect.php I made a connection to my database. connect.php connection code code <?php $connect_error = 'Sorry we\'re experiencing connection issues'; mysql_connect("localhost","myname","mypassword") or die($connect_error); mysql_select_db('mydatabase') or die($connect_error); ?> http://whatsmyowncarworth.com/practice/database/connect.php http://whatsmyowncarworth.com/practice/init.php http://whatsmyowncarworth.com/practice/index.php >>>>>>>>>>>>>>>>>>>> In the practice folder I made two pages. Those two pages are called init.php and index.php (the practice folder is acting as my root folder) (I tried using this code -> <?php include 'practice/init.php';?> <- on the index.php but kept getting errors. So I switched to the below code.) index.php code <?php require 'database/connect.php'; echo 'Hello World!'; ?> >>>>>>>>>>>>>>>>>>>> init.php code <?php require 'database/connect.php'; ?> >>>>>>>>>>>>>>>>>>>> I'm assuming up until now everything is going well. Now my major concern is to be able to "pull" or "get" (my apol. for lack of terminology) data from the MySql database. This is where the confusion is starting to come into play. I'm going to give the below code a try on index.php and see if it works. My index.php page code now. How come this didn't work? What am I doing wrong? <?php include 'practice/init.php'; // get the user ID from the URL // it is a numerical ID, so cast to an integer $user_id = (int) $_GET['user_id']; // try to get the user from the database $result = $mysql->query("SELECT * FROM info WHERE id='$user_id'"); // did we find a user? if ($result->num_rows == 1) { $row = $result->fetch_assoc(); echo 'Name: ' . $row['first_name'] . '<br /> Email: ' . $row['city']; } else { echo 'Sorry, that user was not found'; } ?>
  24. Hi Everyone, Before I ask my question I would like to give everyone a background on myself. I'm currently in the learning stages of PHP and MySql. (I apol. in advance for my lack of tech. terminology) I have a question regarding how to "make" or "produce" certain pages in php code. In my past I've always manually made a pages. For example, aboutus.html, information.html, cats.html etc ... I think you get the idea. Assuming code is being used. How would one go about "making" or "producing" pages that are fully functional php pages? Where people can log in, make edits, write reviews etc ... (a few examples are below) Do the owners/programmers of the below websites manually "make" or "produce" these pages? http://cars.oodle.com/used-cars/san-jose-ca-area/ http://www.yelp.com/biz/lotus-of-siam-las-vegas http://restaurants.uptake.com/california/san_jose/509917137.html http://www.yelp.com/c/san-jose/restaurants My question is, how can I "make" or "produce" these types of pages for my website? Can anyone offer my any tips/tricks on how to do so. All opinions welcome. Thanks everyone in advance for the help.
  25. Thank you. I'm downloading php on my server now. I'll give the code a shot in a few mins.
×
×
  • 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.