Jump to content

ddubs

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

About ddubs

  • Birthday 01/18/1981

Contact Methods

  • Website URL
    http://derekwright.me

Profile Information

  • Gender
    Male
  • Location
    Rochester, NY

ddubs's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. mysql_query will return false on error. False is a boolean value. Therefore if say $output = mysql_query($sql); SQL query fails and you don't check properly and just pass it to mysql_num_rows(); then it will yell about getting a boolean value (the value: false, because the query failed). Perhaps the DB table "address_data" doesn't contain any data?
  2. If this is before any output is sent then you can just use: header('location: '.$beginurl); Instead of that Javascript redirect (which will break if JS is disabled on the client).
  3. When I get to something like this its best to use an anchor tag (which you can style to look like a button or icon). Basically in your table you'd generate a <td><a href="?action=delete&id=13">Delete</a></td> cell and you click this link to delete the id from the database. This can redirect back to itself or a seperate script for deletion (where you confirm, etc..). Anyways, hope this helps!
  4. PHP is dynamic only on the server back end (before presented to the user). It doesnt do to well with "on-the-fly user-input oriented" dynamic. That is more JavaScript's domain.
  5. Correct, just put your try {} catch(Exception $e) {} block within your infinite loop when you try to execute your SOAP calls. Then you can either echo out $e->getMessage(); to see the error or I'm sure you can just continue; and throw the error out the window.
  6. Correct, they save the BB-code and re-parse using templates when the data is recalled out of the DB. Infact, you'd probably only want to allow BB-style code and strip HTML from posts/comments to prevent XSS.
  7. Since you are working with object libraries you should use try/catch. This way if you catch an exception you can handle it properly and continue script execution. Uncaught exceptions are fatal and your script will die().
  8. You need to loop through your DB results: <?php $profile = "SELECT questions.questionid, questions.question, u_profile.answer, questions.q_order " . "FROM questions, u_profile WHERE u_profile.username = '" . $_SESSION['username'] . "'" . "AND questions.questionid = u_profile.questionid AND questions.q_order IS NOT NULL " . "ORDER BY questions.q_order ASC"; $data = mysqli_query($dbc, $profile) or die("Connection Error3" . mysqli_error($dbc) ) ; // like this while($row = mysql_fetch_assoc($data)) { $results[] = $row; } for($i=0; $i < count($results); $i++) { echo "<span>{$results['question']}</span><input type=\"text\" value=\"{$results['answer']}\" name=\"answer\"></input><br />"; } // OR... to simplify, change the loop to: while($results = mysql_fetch_assoc($data)) { echo "<span>{$results['question']}</span><input type=\"text\" value=\"{$results['answer']}\" name=\"answer\"></input><br />"; } ?> mysql_fetch_assoc only returns one row at a time from the query. Look into using a DB library like MDB2 for more robust DB handling. (things like fetch_all which returns all results, etc...)
  9. I'd need to see how you implemented it into your code, can you post some including some of the DB query/fetching.
  10. <?php // Assuming $hashes is an array of 5 hashed passwords for($i=0;$i<10000;$i++) { $test = md5('m'.$i); for($c=0;$c<count($hashes);$c++) { if($test == $hashes[$c]) { $passwords[] = $test; } } } var_dump($passwords); ?> When the code finishes, all 5 passwords will be in the $passwords array. Edit: That last part of the problem with the snippet seems to serve 2 purposes. 1 - Remind you of how a for loop is constructed. 2 - distract you into thinking the actual code itself was somehow useful for this application.
  11. Thats the identifier for the query you just ran. Now you need to fetch the results... mysql_fetch_assoc
  12. A tables id is usually its primary key and should be unique across that entire table. Some tables may contain an id as a reference back to a "foreign" table, these are foreign keys. So in your case you would have something kinda of like this: table: groups ----------------- id | group ----------------- 0 | root 1 | wheel 2 | nobody table: users ---------------- id | username | group_id ------------------------ 0 | root | 0 1 | admin | 1 2 | michael | 1 3 | gob | 1 4 | buster | 2 So as you can see in users table, group_id can be repeated (and thats fine). To query the DB and return username and groupname of the user, you would do: SELECT group.groups, username.users FROM groups, users WHERE group_id.users = id.groups
  13. It runs, it just doesn't have the data since you are navigating directly to it instead of POSTing data to it from a form submission.
  14. So if you have a table questions with fields (question_id, question) and another table answers with (answer_id, answer, question_id, user_id). You would do: SELECT question_id.questions, question.questions, answer.answers FROM questions, answers WHERE user_id.answers = $user_id AND question_id.answers = question_id.questions ORDER BY question_id.questions Then loop over the results you get back from the DB: for($i=0;$i<count($results);$i++) { echo "<span>{$results['question']}:</span><input type=\"text\" value=\"{$results['answer']}\" name=\"answer\"></input>\n"; } SQL has its own built in logic. Utilizing it is waaaay more efficient that trying to keep the logic in PHP.
×
×
  • 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.