kenrbnsn
Staff Alumni-
Posts
8,234 -
Joined
-
Last visited
Everything posted by kenrbnsn
-
I'm not a moderator and didn't mark it solved, so I guess only moderators can do that, although I think I've seen references that the original poster can change the the title. Ken
-
Article name, with article url as its underlying link not appearing
kenrbnsn replied to ger_mac74's topic in PHP Coding Help
Since your making an ordered list, you should use the <ol> and <li> HTML tags: [code]<?php echo '<ol>'; while ($row= mysql_fetch_array($result)){ $artname = $row["articlename"]; $arturl = $row["articleurl"]; echo "<li><a href='$arturl'>$artname</a></li>"; } echo '</ol>'; ?>[/code] This way you don't have to worry about it. Ken -
No it shouldn't be deleted. It should be marked resolved. It may help someone else. As for the quotes, instead of using double quotes everywhere and escaped double quotes, use single quotes to surround strings that contain double quotes: [code]<?php if($stepdone != 'done') { echo '<form id="form1" name="form1" method="post" action="step_5.php?username=' . $username . '&filename=' . $filename . '&stepdone=' . $stepdone . '"> <p align="center">If you had made any changes be sure to save changes before continuing. </p> <p align="center"> <input type="submit" name="Submit" value="Continue" /> </p> </form>'; } ?>[/code] Ken
-
You do not use PHP to create how the data is displayed. PHP is ued to get the data. PHP doesn't know or care how the data is displayed or even if it is. How it is displayed is up to you and the tools you use. I would recommend learn CSS so you can customize the display or your data. Ken
-
Instead of multiple "if" statements, you could try using a "switch" statement: [code]<?php foreach ($_POST as $k => $v) switch ($k) { case 'first_name': // here are all the fields that can't be blank case 'last_name': case 'mailing_street': case 'mailing_city': case 'mailing_zip': if (strip_tags(trim($v)) == '') header('location: profile.php?reason=info'); break; case 'password1': if ($v != $_POST['password2']) header('location: profile.php?reason=password'); break; case 'email': if (strip_tags(trim($v)) == '') header('location: profile.php?reason=info'); if (!check_email_address($v)) header('location: profile.php?reason=email'); break; case 'mailing_state': if (strip_tags(trim($v)) == '' || $v == 'XX') header('location: profile.php?reason=info'); break; } ?>[/code] Ken
-
Counting up correct answers in a quiz - help please.
kenrbnsn replied to gerrydewar's topic in PHP Coding Help
Are you trying to make the names of the radiobuttons the same as your the contents of your varible "$ID"? If so, your script is wrong. Try this instead: [code]<?php echo '<tr><td align="left"><li>' . $questions . '</td></tr> <tr> <td align="left"><input type="radio" name="choice[' . $id . ']" value="' . $opt1 .'"/>' . $opt1 . '</td></tr> <tr> <td align="left"><input type="radio" name="choice[' . $id . ']" value="' . $opt2 .'"/>' . $opt2 . '</td></tr> <tr> <td align="left"><input type="radio" name="choice[' . $id . ']" value="' . $opt3 .'"/>' . $opt3 . '</td></tr> <tr> <td align="left"><input type="hidden" name="rightanswer[' . $id . ']" value="' . $answer . '"/></td></tr>' . "\n"; }?>[/code] Then in your processing code: [code]<?php $score = 0; foreach($_POST['choice'] as $id => $ans) if($_POST['rightanswer'][$id] == $ans) $score++; ?>[/code] The way you have it scripted all of your radio buttons were named "$id" so if you had more than one question only the last choices would be returned. The same with the right answer. Ken -
"by" is a reserved word to MySQL, so surround it with backticks: [code]<?php mysql_query("insert into news(type, title, month, day, year, body, `by`) values('$type', '$title', '$month', '$day', '$year', '$body', '$by')") or die("Insert error : ". mysql_error()); ?>[/code] Ken
-
Arrays in PHP are dynamic. You can write this: [code]<?php $UserData = Array ($x => $rs); ?>[/code] as [code]<?php $UserData[$x] = $rs; ?>[/code] Read [a href=\"http://www.php.net/array\" target=\"_blank\"]this section[/a] in the fine manual for more information. Ken
-
It's amazing you didn't get a syntax error on this line: [code]<?php mysql_query("insert into news(type, title, month, day, year, body, by) values("$type", "$title", "$month", "$day", "$year", "$body", "$by")") or die("Insert error:" . mysql_error()); ?>[/code] You have too many double quotes, you should change it to: [code]<?php mysql_query("insert into news(type, title, month, day, year, body, by) values('$type', '$title', '$month', '$day', '$year', '$body', '$by')") or die("Insert error:" . mysql_error()); ?>[/code] or [code]<?php $ q = "insert into news(type, title, month, day, year, body, by) values('$type', '$title', '$month', '$day', '$year', '$body', '$by')"; $ mysql_query($q) or die('Problem with query: ' . $q . '<br />' . mysql_error()); ?>[/code] Ken
-
*SOLVED* Checkbox ticks not counting using php count function
kenrbnsn replied to fohanlon's topic in PHP Coding Help
Re-write this line [code]<?php $deldets = explode("*", $_POST["$deleteitem[$i]"]); ?>[/code] as [code]<?php $deldets = explode("*", $_POST['deleteitem'][$i]); ?>[/code] The array is "[b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$_POST['deleteitem'][!--colorc--][/span][!--/colorc--][/b]" so you need to index the entire name. Ken -
*SOLVED* Checkbox ticks not counting using php count function
kenrbnsn replied to fohanlon's topic in PHP Coding Help
You should be looking in the $_POST array here. Your code: [code]<php f($task == "remove_items") { echo "Count is " . count($deleteitem); // HERE IS WHERE ISSUE IS if (count($deleteitem) >= 1) ?>[/code] change to [code]<?php f($task == "remove_items") { echo "Count is " . count($_POST['deleteitem']); // HERE IS WHERE ISSUE IS if (count($_POST['deleteitem']) > 0) ?>[/code] Ken -
I absolutely hate seeing escaped quotes in a PHP source, since it makes the source so hard to read. and there are many ways to aviod using them. In this case just replace the first and last doube quotes with single quotes. [code]<?php echo '<a href="menu.htm" target="mainwindow">Return to main menu</a><br><br>'; ?>[/code] And now you have a syntacally correct "echo" statement that is easy on the eyes. Ken
-
What are you trying to accomplish? [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Sorry to post back so soon, but I have a follow-up question regarding my script [above]. Let's say, for example, that the file was view.php?id=3 The above code will only display view.php . How do I resolve this?[/quote] The filename part is still "view.php" the "?id=3" is not part of the file. That is a parameter on the URL and will reside in the $_GET superglobal array: [code]<?php echo $_GET['id']; ?>[/code] Ken
-
A few questions on your code. Look for the comments I've added below: [code]<?php include ('connect.php'); $most = urlencode($most); // why are you doing a urlencode? echo $most; // just to test $most = explode(" ", $most); // what does the string coming in look like? It almost looks as though you expect spaces between each character. $B = 0; $T = 0; $S = 0; $N = 0; $Z = 0; foreach($most as $value) // Please indent your code... { switch($value) { case 'B': $B++; break; case 'T': $T++; break; case 'S': $S++; break; case 'N': $N++; break; break; case 'Z': $Z++; break; } } ?>[/code] Now for a possible solution: [code]<?php $str = ';lkdjg kljklJ;J;;FJGKLJEGJREKJG LKJSKDKLKLDJGJGKLJ'; $tmp = array(); for ($i=0;$i<strlen($str);$i++) { if (array_key_exists($str{$i},$tmp)) $tmp[$str{$i}]++; else $tmp[$str{$i}] = 1; } ksort($tmp); echo '<pre>' . print_r($tmp,true) . '</pre>'; ?>[/code] Adapt the above code to your needs. Ken
-
Yes, it's possible: [code]<?php $dir_tmp = glob('*.txt'); foreach ($dir_tmp as $filename) { echo $filename . ' size ' . filesize($filename) . "<br />\n"; } echo 'There are ' . count($dir_tmp) . ' files in this directory<br>'; ?>[/code] Ken
-
Please post some code.... Ken
-
Besides the basename() function, you should look at the [a href=\"http://www.php.net/pathinfo\" target=\"_blank\"]pathinfo[/a]() function. Ken
-
Counting up correct answers in a quiz - help please.
kenrbnsn replied to gerrydewar's topic in PHP Coding Help
When you press submit, your script is started again, so you have to do all of the preliminary database stuff again. Also instead of [code]<?php if($_SERVER['REQUEST_METHOD'] == 'POST') ?>[/code] you probably want to use [code]<?php if (isset($_POST['submitted'])) ?>[/code] Ken -
Look at the [a href=\"http://www.php.net/glob\" target=\"_blank\"]glob[/a]() function. Ken
-
Remove the second "where": [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]activity[/color] [color=green]WHERE[/color] userID [color=orange]=[/color] 2 [color=blue]AND[/color] time BETWEEN 19700101020000 [color=blue]AND[/color] 20060606000000 [!--sql2--][/div][!--sql3--] Ken
-
The code looks fine (almost*), although I would use "mysql_fetch_assoc" instead of "mysql_fetch_array". (*) In the "or die" clause, you have mysql_error, it should be mysql_error(). Dumb question ... is there any data in the database? You can put a debug print statement in to see what data the script is finding: [code]<?php $q = "SELECT * FROM `competitions`"; $result = mysql_query ($q) or die('Problem with query: ' . $q . '<br />' . mysql_error()); while ($row = mysql_fetch_assoc($result)){ echo '<pre>' . print_r($row, true) . '</pre>'; // debug statement $id=$row['ID']; $name=$row['name']; $races=$row['races']; $qualify=$row['qualify']; $discards=$row['discards']; $type=$row['type']; echo "<p><b> " . $name . "</b>" . "<br><i>Races: <b>" . $races . "</b> Number to qualify: <b>" . $qualify . "</b> Discards: <b>" . $discards . "</b> Type: <b>" . $type . "</p></i>"; echo " <a href='$PHP_SELF?deleteme=$id'>Delete Competition</b></a></p>"; } ?>[/code] Ken
-
Try this: [code]<?php $q = "select * from tablename"; $rs = mysql_query($q) or die('problem with query: ' . $q . '<br />' . mysql_error()); while ($rw = mysql_fetch_assoc($rs)) foreach ($rw as $key => $value) if ($value == 'abcdef') echo 'The field ' . $key . " holds the value<br />\n"; ?>[/code] Ken
-
You need to specify the same "salt" to the crypt function if you want the same encryption to take place. Ken
-
Generate a random number & check DB to see it is unique
kenrbnsn replied to playaz's topic in PHP Coding Help
I would get all of the current id numbers in the database, store them to a temporary array, then generate the random numbers until you find one not in the temporary array. Something like: [code]<?php $q = "select acct_num from your_table"; $rs = mysql_query($q); $tmp = array(); while ($rw = mysql_fetch_assoc($rs)) $tmp[] = $rw['acct_num']; $new_acct_num = rand(10000000,99999999); while (in_array($new_acct_num,$tmp)) $new_acct_num = rand(10000000,99999999); echo $new_acct_num; ?>[/code] There is a slim possibility that this code will produce a duplicate number if more than one new account is processed at the same time (before the database is updated with the new number). Is there any reason why you can't use an autoincrement field? Ken -
Look at the [a href=\"http://www.php.net/date\" target=\"_blank\"]date[/a]() and [a href=\"http://www.php.net/strtotime\" target=\"_blank\"]strtotime[/a]() functions: [code]<?php $dt = '7/3/2006'; echo date('m-d-Y \i\s \a l',strtotime($dt)); ?>[/code] Ken