Jump to content

thefortrees

Members
  • Posts

    88
  • Joined

  • Last visited

    Never

Everything posted by thefortrees

  1. you shouldn't have to select a db in mysql_connect query.
  2. Hi all - I have information in a form that I use GET to retrieve the form data. However, some of the data has spaces (ie: Restaurant - Fast Food) and the spaces can not be stored in the URL. How can I put all of that information into the URL via GET? Maybe implode()?
  3. Show the part of the code that is giving you the problem.
  4. Hi all - This query works when I execute it from mysql command line, but it doesn't work when the PHP script is executing. The error it is giving me is Not unique table/alias: 'companies'. I would appreciate any help you can give. if ($lob == 'all'){ $query = "SELECT company, lob FROM companies, businesses" . "WHERE companies.businesses_businesses_id = businesses.businesses_id;"; $result = mysql_query($query) or die(mysql_error()); echo $result; return $result; } My businesses table has the following fields: businesses_id lob My companies table has several fields, some including: company businesses_businesses_id
  5. I was having the same problem a month ago when I first started learning PHP. I spent a lot of time trying to figure out what the issue was - I had the form processed by a separate script to fix the issue. Don't know why that worked, but it did.
  6. The first problem I see is with the if statement: $query = ("SELECT * FROM email WHERE email = $email"); if (($query['email'] == $email) && ($query['no'] == $id)) { } That will not work. You haven't queried the database to check those fields in the table. You need to do like you did in the else statement. Read up on mysql queries. To keep generating another random $id, you can use a loop . Read up on those. http://hudzilla.org/phpwiki/index.php?title=Loops $id = rand(1, 14); $query = "SELECT * FROM email WHERE email = '$email'"; $result = mysql_query($query); $row = mysql_fetch_array($result); if ($row['email'] == $email){ while ($row['no'] == $id){ $id = rand(1, 14); } } Hope that helps.
  7. Hi all - I am trying to figure out if there is anyway to combine the 2 queries in my code. In the second query, I want to insert the businesses_id I retrieve from the first query into the table. Is there any way to select businesses_id and insert it with a text field in the form in one query? Thanks! My two tables are as follows: businesses ---------- Fields: businesses_id lob (type of business) ---------- questions --------- questions_id businesses_businesses_id (obviously, businesses_id from business table) question (text) //Add a question - get businesses_id from businesses where posted lob = lob in businesses table. Then add //businesses_id and question to questions. $query = "SELECT businesses_id FROM businesses WHERE lob = '$_REQUEST['lob']"; $result = mysql_query($query); $row = mysql_fetch_array($result); $businessid = $row[0]; $question = $_REQUEST['question']; $query = "INSERT INTO questions (businesses_businesses_id, question) VALUES ('$businessid', '$question')";
  8. If you want to use double quotes throughout the whole thing, you have to escape the " with \ so that when the code is parsed, the query string is interpreted as a whole, complete string. Or just use ' around the values instead of " like akitchin said. Example: $query = mysql_query("INSERT INTO tech_articles(authorID,headline,articleContent) values(1, \"Welcome to TechNews!\", \"Congratulations! You have completed the installation process and you may now start creating news articles!\")") or die("Error: ".mysql_error()); OR $query = mysql_query("INSERT INTO tech_articles(authorID,headline,articleContent) values(1, 'Welcome to TechNews!', 'Congratulations! You have completed the installation process and you may now start creating news articles!')") or die("Error: ".mysql_error());
  9. so this might work... function subtopic(){ $terms = array($terms[0], $terms[1],$terms[2],$terms[3],$terms[4],$terms[5],$terms[6],); $bgcolor = "yellow"; foreach($terms as $value) { $count++; if(!empty($value)) { $replaceWith = "<span style=\"background-color:$bgcolor;\">" . $value . "</span>"; if($count==1) { $result = eregi_replace($value, $replaceWith, $string); } else { $result = eregi_replace($value, $replaceWith, $result); } } return $result; } Then whenever you want to call the function create a variable that is assigned the return value of the function subtopic() and echo it.... while ($row = mysql_fetch_assoc($queryResult){ $sub = subtopic(); } I can't guarantee this will work or that it is exactly what you want.
  10. all i can think of is that you haven't declared a form action... maybe try <form action = 'filename.php'> where filename is the name of the form handler.
  11. http://weblogtoolscollection.com/regex/regex.php
  12. Seems to me that every time you echo $subtopic, you are just echoing the one value that it was assigned from the code you displayed. If you want $subtopic to display a different $subtopic multiple times in the page, I would create a function that returns $subtopic and call that in the portion of the script that generates the tables. ex: <?php function subtopic(desired parameters){ //desired code here.... //...... return $subtopic; } //Run a query.... //...... echo "<table>" ."<th>Water</th><th>Subtopic</th>"; while ($row = mysql_fetch_assoc($result)){ $sbtopic = subtopic(desired params); echo "<tr><td>".$sbtopic."</td></tr>"; } ?> With the way you had it before, I think $subtopic was being assigned a value only once per script. If, every time you escape back into PHP, you call the subtopic function with new parameters, it will assign a new value to subtopic.
  13. Thanks! I caught it just as you posted that. Appreciate your help.
  14. Arg! I'm getting unexpected T_INC on line 73, expecting ')'. (The error is in the line where the for loop is initiated in the 2nd function). But I can't see where I left out any parentheses, semi colons, or anything else... I'd appreciate any help!!! //Queries clients and tracker table to see which companies haven't filled out the table. function notFilledout(){ $query = "SELECT clients.company FROM clients WHERE clients.company NOT IN(SELECT tracker.company FROM tracker);"; $result = mysql_query($query) or die("Query failed" . mysql_error()); echo "<br><br><br>" ."<h1>Companies - not filled out</h1>" ."<br><table class = \"table\" border cellpadding = 4 align = \"center\">" . "<tr><th>Company</th></tr>"; //While still rows in result set, fetch current row into array $row. while ($row = mysql_fetch_assoc($result)){ echo "<tr><td>".$row['company']."</td></tr>"; } echo "</table>"; } //Queries answers and clients table to see who answered questionIDs 7-14 with 3 or less. function rateService(){ echo "<table class = \"table\" border cellpadding = 4 align = \"center\">"; for ($i = 7; $i < 15; i++){ $query = "SELECT answers.answer, clients.company FROM answers, company WHERE questionID = '$i' AND answers.passcode = clients.passcode;"; $result = mysql_query($query); $int = (int) $result['answer']; //if ($int <= 3) } }
  15. nevermind - one field was missing in my table.
  16. Hi all - this insert query isn't working. I'd appreciate a second pair of eyes to check it over and see if there is anything I missed. Thanks! if ( empty($message) ){ $query = "INSERT INTO users (lastName, firstName, email, password, phone, fax, address1, address2, city, state, zip, ssn, company, empid, nameoncert, registerDate) VALUES ('$lname', '$fname', '$email', '$password', '$phone', '$fax', '$address1', '$address2', '$city', '$state', '$zip', '$ssn', '$company', '$empid', '$nameoncert', '$date');"; $result = mysql_query($query); } Could it be that some of my variables have empty string values?
  17. There are two things, but I'm not totally sure about the second one. 1) Why have if($_POST['actions'] right before a foreach($_POST['actions']? This is extremely redundant - remove the if statement and if $_POST['actions'] is not set, then it will never enter the loop. 2) Are you defining a two dimensional array with value="actions[stock][' . $row['itemid'] . ']"? I don't think you can define two dimensional arrays with HTML, just one dimensional. So maybe try removing [' . $row['itemid'] . '] from value and see if that works? Hope any of that helps
  18. whats this part right here? if($_GET['action'] == "multiple"){
  19. Ah yes, the good old PHP learning curve. Thanks both of you!
  20. The foreach loop is throwing the error "invalid argument supplied for foreach()" even though I defined the array right before it. Any ideas? $required = array ('email', 'password1', 'password2', 'fname', 'lname', 'phone', 'address1', 'city', 'state', 'zip', 'nameoncert'); function checkData(){ foreach($required as $index){ $value = $_POST[$index]; if (empty($value) ){ $msg = 'Please fill out all required fields.'; return $msg; } } if ($_POST['password1'] != $_POST['password2']){ $msg = 'Password does not match.'; return $msg; } if ( !checkEmailAddress($_POST['email']) ){ $msg = 'Invalid e-mail address.'; return $msg; } }
  21. $query = "SELECT tshirt FROM brothers WHERE user_id = '$id';"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); <input type="radio" name="tshirt" value="XXL" <?php if ($row['tshirt'] == 'XXL') echo 'checked';?> /> Also, if you want to condense your code (the portion that checks to see if all the fields are filled out), you can do something like this: foreach($_POST as $value){ if ( empty($value) ){ $msg = 'Please fill out all required fields.'; return $msg; } }
  22. all i can think of is that your parameters are possibly wrong.
  23. You can use cookies. With cookies you can set the expire time. http://us.php.net/manual/en/features.cookies.php
  24. you can set a cookie or use sessions. http://us.php.net/manual/en/features.cookies.php If you want to use cookies, just read up on the setcookie function... setcookie("cookiename", $_POST['whatever]', other parameters ......) Then when you want to use the post data from your first page, you can just do: $postdata = $_COOKIE['cookiename']; and that should do it. Be sure that you set your cookies before anything is sent to the browser, wont work otherwise. Sessions work too.
×
×
  • 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.