Jump to content

DruX

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Everything posted by DruX

  1. Thanks TylerDiaz, that code worked. $food0 = $_POST['food']; $category0 = $_POST['category']; $brand0 = $_POST['brand']; $addname = $_SESSION['username']; $food = preg_replace ("/ /", " ", $food0); $category = preg_replace ("/ /", " ", $category0); $brand = preg_replace ("/ /", " ", $brand0); mysql_query("INSERT INTO foods (food, category, brand, username) VALUES ('$food', '$category', '$brand', '$addname')"); -DruX
  2. I have setup a form that adds data to a MySQL database, however I need spaces in textarea form inputs to be filled with instead of just a regular space when the data is added to the MySQL table. For example, if someone enter "Ice Cream" in the text box and clicks submit, "Ice Cream" is what actually needs to be added in the database table. I am wonder if this is possible and how to set this up. Not sure if it can be accomplished with HTML, PHP, or in MySQL. -DruX
  3. <?php $id = $_SESSION['username']; $result = mysql_query("SELECT * FROM foods WHERE username = '$id'") or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['food']. " - ". $row['category']; ?> returns "peaches - fruits" This code seems to like me...somewhat. Now I just need it to print all the rows for the username, not just the first one it finds in the DB. Like this for user "acid": peaches - fruits bananas - fruits -DruX P.S. Also tried mysql_fetch_assoc($result), but I couldn't get anything but a parse error.
  4. I think this was definitely a step in the right direction... Tried both <?php $id = $_SESSION['username']; $foods_query = mysql_query("SELECT * FROM foods WHERE username = '$id'") or die(mysql_error()); echo $foods_query; ?> and <?php $id = $_SESSION['username']; $foods_query = mysql_query('SELECT * FROM foods WHERE username = "$id"') or die(mysql_error()); echo $foods_query; ?> They both echo "Resource id #6 ". This is a new one for me :-\ I think its something more in depth, but at least its printing words now -DruX
  5. Alright, it says: I also tried to enter the username in the code, "tom": <?php $foods_query = mysql_query('SELECT food FROM foods WHERE username = acid'); echo $foods_query; ?> Returns same result, so it should not a problem with $_SESSION['username']. -DruX
  6. (MySQL version is 5.1.30) I am trying to set up a page that will show my website user's "favorite foods" to them, of which are stored in the database. I need the page to print all rows from the table that apply to the logged in user. Here is my test table, it is called "foods". For example, if "tom" is logged in, show a list of all his "food" items. I am trying to use this code to display the list in the user's page: <?php $id = $_SESSION['username']; $foods_query = mysql_query('SELECT food FROM foods WHERE username = $id'); echo $foods_query; ?> When I test, it returns blank. No message, no error. As if there is nothing in the table. Is there a specific code I have to enter in order to print to the page? Or is this code all wrong? -DruX
×
×
  • 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.