-
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 (1/5)
0
Reputation
-
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?
-
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!
-
Tell the script to restart from the beginning if it encounters any error
ddubs replied to phpchick's topic in PHP Coding Help
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. -
This is a long shot...but here it goes
ddubs replied to son.of.the.morning's topic in PHP Coding Help
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. -
Tell the script to restart from the beginning if it encounters any error
ddubs replied to phpchick's topic in PHP Coding Help
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(). -
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...)
-
I'd need to see how you implemented it into your code, can you post some including some of the DB query/fetching.
-
<?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.
-
Couting how many records have the same id.
ddubs replied to son.of.the.morning's topic in PHP Coding Help
Please post the error text. -
Couting how many records have the same id.
ddubs replied to son.of.the.morning's topic in PHP Coding Help
Thats the identifier for the query you just ran. Now you need to fetch the results... mysql_fetch_assoc -
Couting how many records have the same id.
ddubs replied to son.of.the.morning's topic in PHP Coding Help
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 -
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.
-
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.