Jump to content

dawsba

Members
  • Posts

    180
  • Joined

  • Last visited

    Never

Everything posted by dawsba

  1. you could try this $result1 = $db->query('ALTER TABLE `'.$db->prefix.'users` DROP `id`;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error()); $result2 = $db->query('ALTER TABLE `'.$db->prefix.'users` AUTO_INCREMENT = 1;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error()); $result3 = $db->query('ALTER TABLE `'.$db->prefix.'users` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error()); $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error()); $stats['total_users'] = $db->result($result);
  2. not 100% sure what you mean are you looking to have an add qty button to add multiple items, perhaps ajax? or a refresh each time they click add item: in which case i would structure your session array alittle different and add qty to the fields ie: if (!isset($_session['cart'])) $_SESSION["cart"]= '$id' ; if (isset($_POST['id']) &&!empty($_POST['id']) && isset($_POST['cost']) &&!empty($_POST['cost'])) { $id = $_POST['id']; $cost = $_POST['cost']; if($_SESSION['cart'][$id][qty]>0) { $_SESSION['cart'][$id][qty]++; } else { $_SESSION['cart'][$id][cost]=$cost); $_SESSION['cart'][$id][qty]=1; } foreach($_SESSION['cart'] as $key => $arr){ echo $key . ' '. $arr[cost].' '.$arr[qty].' TOTAL:$pound;'.number_format($arr[qty]*$arr[cost],2)); } } echo '<pre>'; print_r($_SESSION); echo '</pre>';
  3. you could try add ing limit 1 to the end of your sql $query = "SELECT id, firstname FROM `Members` WHERE id={$_SESSION['id']} LIMIT 1"; also are you actually getting the session variable correctly, can you echo the value to check against the id's
  4. <?php $search_chars = array(); for($i=128;$i<=255;$i++){array_push($search_chars,$i);} $string = "the lazy brown d..…"; $orig = $string; function strpos_chararray($haystack, $needles) { if(is_array($needles)) { foreach($needles as $key => $str) { if(is_numeric($str)){$str = chr($str);} if(is_array($str)) { $pos = strpos_array($haystack, $str); } else { $pos = strpos($haystack, $str); } if ($pos !== FALSE) { return $pos; } } if ($pos === FALSE) { return FALSE; } } else { return strpos($haystack, $needles); } } function rebuild($string) { global $search_chars; $str = explode(' ',$string); foreach($str as $str_bit) { $chk = strpos_chararray($str_bit, $search_chars); if($chk === FALSE) { $new_str .= ' '.$str_bit; } else{break;} } return $new_str; } if(strpos_chararray($string, $search_chars)) { $string = rebuild($string); } echo "ORIGINAL >> ".$orig."<br>"; echo "NEW >> ".$string."<br>"; ?>
  5. <?php function q($query,$assoc=1) { $r = @mysql_query($query); if( mysql_errno() ) { $error = "<script>window.location='?ref=0'</script>";//'MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). '</small><br><VAR>$query</VAR>'; echo($error); return FALSE; } if( strtolower(substr($query,0,6)) != 'select' ) return array(mysql_affected_rows(),mysql_insert_id()); $count = @mysql_num_rows($r); if( !$count ) return 0; if( $count == 1 ) { if( $assoc ) $f = mysql_fetch_assoc($r); else $f = mysql_fetch_row($r); mysql_free_result($r); if( count($f) == 1 ) { list($key) = array_keys($f); return $f[$key]; } else { $all = array(); $all[] = $f; return $all; } } else { $all = array(); for( $i = 0; $i < $count; $i++ ) { if( $assoc ) $f = mysql_fetch_assoc($r); else $f = mysql_fetch_row($r); $all[] = $f; } mysql_free_result($r); return $all; } } $sql = "SELECT * FROM `calendar`"; $result2 = mysql_db_query(YOURDATABASE,$sql,YOURLINK) or die("Invalid Query<br>". mysql_error()); while ($r3 = mysql_fetch_array($result2)) { $new_id = q("INSERT INTO `games` (game_id,sport,day,visitor,home,start,field,notes,level)VALUES('','".$r3[sport]."','".$r3[date]."','".$r3[visitor]."','".$r3[home]."','$r3[time]','".$r3[field]."','".$r3[notes]."','".$r3[level]."')"); $new_id = $new_id[0]; for($i=1;$i<=5;$i++) { q("INSERT INTO `scheduled_umps` (row,game_id,ump)VALUES('','".$new_id."','".$r3['ump'.$i]."')"); } } ?>
  6. your bouncing away with the header, try using sessions session_start(); //must be the first item on script! and on every script!!!!!! $_SESSION['mytext']=$_POST['text']; //before your header bounce :inplace of $text=$_POST[text]; <?php session_start(); include_once('../index.html'); echo "Hello, your text was " . $_SESSION['mytext'] . "!"; ?>
  7. are you asking for the data to dynamically appear on the page? if so you will need to include elements of javascript/ajax create the list as normal, in the select add onChange with your js function have the ajax bounce to anouther script to gather the data about the car etc and display in a hidden div have a look here, this should help you loads http://www.switchonthecode.com/tutorials/simple-ajax-php-and-javascript
  8. you should read alittle about understanding arrays ie:http://www.howtoforge.com/php_arrays <?php $users=array(); $users['user1']=array('email'=>'bob@bob.com','password'=>'mypass'); $users['user2']=array('email'=>'bob2@bob2.com','password'=>'mypass2'); //so if you get a new user $newusername = 'user3'; $newemail = 'user@bob.com'; $newpassword = 'ilikesprouts'; $users[$newusername]=array('email'=>$newemail,'password'=>$newpassword); ?>
  9. heres some code i wrote awhile ago, it'll need some cleaning and you'll have to work some bits out html: <? if(!isset($iiX)){$iiX=1;} ?> <form name="memnum" action="?ref=<?= $iiX; ?><?= $eXtra; ?>" enctype="multipart/form-data" method="post"> <table align="center"> <tr> <td colspan="3"><center><p><?= $title; ?></p></center></td> </tr> <tr> <td colspan="3"> <? if(strtolower($kspecial) != 'password'){$kspecial = 'text';} ?> <input type="<?= $kspecial; ?>" name="pad" id="rfid" class="memnumfield" width="32" height="30"/> </td> </tr> <script> document.memnum.pad.focus(); document.memnum.pad.select(); </script> <? for($i = 1; $i <= 10; $i++) { if($i == 10 || $i == 7 || $i == 4 || $i == 1) { echo "<tr>"; } if($i == 10) { echo " <td> <input name=submitmem type=\"submit\" class=\"keypad_button\" value=\"ENTER\"> </td> <td align=center> <input type=\"button\" class=\"keypad_button\" name=\"0\" value=\"0\" onclick=\"document.memnum.pad.value = document.memnum.pad.value+'0'\" onclick=\"goCheck(this)\"> </td> <td> <input type=\"button\" class=\"keypad_button\" value=\"RESET\" onclick=\"document.memnum.pad.value = ''\"> </td> "; } else { echo " <td> <input type=\"button\" class=\"keypad_button\" size=\"22\" name=\"".$i."\" value=\"".$i."\" onclick=\"document.memnum.pad.value = document.memnum.pad.value+'".$i."'\" onclick=\"goCheck(this)\"> </td> "; } if($i == 9 || $i == 6 || $i == 3 || $i == 10){echo "</tr>";} } echo " <td colspan=\"3\"> <input type=\"button\" class=\"keypad_button\" size=\"66\" name=\"Cancel\" value=\"Cancel\" style=\"width:335px; height:35px;\" onclick=\"window.location='?ref=0'\"> </td> "; ?> <tr><td colspan="3"> </td></tr> </table> </form>
  10. at the top of the script just add $count=0;
  11. set it to a html array and on post spin through the keys <?php if (isset($_POST['submitted'])) { include('connect1.php'); $category = $_POST['category']; $criteria = $_POST['criteria'] ; $query = ("SELECT name, badges, rank, userid FROM members WHERE $category LIKE '%".$criteria."%'"); $result = mysqli_query($dbcon, $query) or die('error getting data'); $num_rows = mysqli_num_rows($result); echo "$num_rows results found"; echo "<table width=\"896\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr bgcolor=\"#F7E496\"><td bgcolor=\"#F7E496\"><strong>name</strong></td><td bgcolor=\"#F7E496\" ><strong>Merit Badges</strong></td><td bgcolor=\"#F7E496\"><strong>Rank</strong></td><td bgclor=\"#F7E496\"></td></tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {$color = ($color == 'white')?'#fffccc':'white'; echo "<tr bgcolor='$color'><td> <input type=\"text\" name=\"userid\" id=\"userid\" value='".$row['userid']."'>"; echo $row['name']; echo " </td><td> <form action=\"scout.php\" method=\"post\"> <textarea name=\"badges[color=red][".$row['userid']."][/color]\" id=\"badges\" cols=\"40\" rows=\"3\" type=\"textarea\">".$row['badges']."</textarea></td><td> <span class=\"adfa\"> </span> <select name=\"rank[color=red][".$row['userid']."][/color]\" id=\"rank\"> <option value=\"Scout\">Scout</option> <option value=\"Tenderfoot\">Tenderfoot</option> <option value=\"Second Class Scout\">Second Class Scout</option> <option value=\"First Class Scout\">First Class Scout</option> <option value=\"Star Scout\">Star Scout</option> <option value=\"Life Scout\">Life Scout</option> <option value=\"Eagle Scout\">Eagle Scout</option> <option value=\"\" selected=\"selected\">".$row['rank']."</option> </td><td>"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Save\" /> "; echo "</form>"; } echo "</table>"; echo "</td></tr>"; } ?> and on the post side <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ [url=http://'http://www.flashbuilding.com/']www.flashbuilding.com[/url] -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display // Process the form if it is submitted if ($_POST['submit']) { $PS = $_POST['submit']; if(is_array($PS)) { foreach($PS as $user_id=>$type) { $badges=$type[badges]; $rand = $type[rank]; //user_id is now defined spin sql $sql = mysql_query("UPDATE members SET badges='$badges', rank='$rank' WHERE userid='".$user_id."'"); printf("Records updated: %d\n", mysql_affected_rows()) } } exit(); } // close if post ?> not tested but should give u a start
  12. foreach($users_associates as $is_associate) { if (($is_associate['user_id'] != $user_info['uid'])&&$count<=0) { $count++; ?> <li class="bass"> <a href="" title="Become Associates" id="becomeassoc" class="mll"> <span class="f_right">Become Associates</span><img src="../assets/img/becomeassoc.jpg" class="mrs vmiddle" alt="Become Associates" /> </a> </li> <?php } }
  13. Learn the language, then you wont need to frankenstein code in places; i buy this book for my students: http://www.amazon.co.uk/Sams-Teach-Yourself-MySQL-Apache/dp/0672328739 good luck
  14. i have no idea why you would want to, but hey cool lol i think youd be better using sessions as they transcend the refresh <?php session_start(); $urna=array(0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"); $cs="#"; if($_SESSION['hit']>=4) { for ($i=1; $i<=6; $i++) { $b .= $urna[rand(0,15)]; } $_SESSION['culoare'] = $cs.$b; } else { $_SESSION['hit']++; } ?> <body bgcolor="<?php echo $_SESSION['culoare']; ?>"> <form method=post> <input type="submit" name="submit" value="Schimba culoarea" /> </form>
  15. your forgetting enctype="multipart/form-data" in your form html
  16. you can have a random id if you really want you just have to parity check it $check = 0; while($check<=0) { $check = rand(10000,99999); $sql = "SELECT COUNT(*) FROM `project`.`rma` WHERE `rmanumber` = '".$check."'"; if(mysql_query($sql)>0){$check=0;}else{$rmanumber=$check;} }
  17. rough and not tested, there is a better way of sorting a multiD array, but im too tired lol also i tidied up your html <? $i=1; $w=1; $data = array(); $result = mysql_query("SELECT team_name, owner FROM teams "); while ($row = mysql_fetch_array($result)) { $result1 = mysql_query("SELECT SUM(`owner_pts`) as total FROM `schedule` WHERE `team` = '$i' ORDER BY total ASC"); while ($row1 = mysql_fetch_array($result1)) { $data[][$row1['total']]['teamname']=$row['owner']; } } foreach($data as $k=>$v) { foreach($v as $k2=>$v2) { $rowd[$k]['owner']; $rowd[$k]['team_name']; } } ?> <table> <? foreach($rowd as $k=>$row) { ?> <tr> <td> <?= $row['owner']; ?> </td> <td> <?= $row['team_name']; ?> </td> </tr> <tr> <td colspan="2"> <table> <tr> <? $result1 = mysql_query("SELECT bye, owner_pts FROM schedule WHERE team = $i"); $num_rows = mysql_num_rows($result1); while ($row1 = mysql_fetch_array($result1)) { ?> <td> <? $totalpts = $totalpts + $row1['owner_pts']; if (empty($row1['bye'])) { echo $row1['owner_pts']; } else { echo "0"; } ?> </td> <? } while ($num_rows<=16) { echo "<td> </td>"; $num_rows++; } ?> <td><?= $totalpts; ?></td> <? $totalpts=0; $w++; $i++; ?> </table> </td> </tr> <? } ?> </table> <? mysql_close($con); ?>
  18. set your rmanumber to autoincrement in the db, your probably getting conflict in your index
  19. on your post handler script have something similr to this: <? function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { $isValid = false; } else if (preg_match('/\\.\\./', $local)) { $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { $isValid = false; } else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { $isValid = false; } } return $isValid; } function dcheck($email,$domains=NULL) { if(validEmail($email)) { $tld = explode('@',$email); if($domains==NULL){return true;} if(in_array($tld[1],$domains)){return true;} } return false; } $allowed_domains = array('hotmail.com','msn.com'); $emailok = dcheck('bob@bob.com',$allowed_domains); if($emailok) { echo "EMAIL EXISTS AND IS IN ALLOWED LIST"; } else { echo "EMAIL DOES NOT EXISTS OR NOT IN ALLOWED LIST"; } ?>
  20. no so true pikachu, what if the user has JS disabled or a JS bug exists further in the head, although i use jquery calenders all the time, if you want pure and simple use dropdowns <select name="day"> <? for($i=1;$i<=31;$i++) { ?> <option value="<?= $i; ?>"><?= $i; ?></option> <? } ?> </select> <select name="month"> <? for($i=1;$i<=12;$i++) { ?> <option value="<?= $i; ?>"><?= $i; ?></option> <? } ?> </select> <select name="Year"> <? for($i=2010;$i>=1930;$i--) { ?> <option value="<?= $i; ?>"><?= $i; ?></option> <? } ?> </select> mash it up in php before injecting into sql $birthdate = trim($_POST['Year'].'-'.$_POST['month'].'-'.$_POST['day']); just for kicks
  21. in the array build, inject in place of array('name' => 'Website:', 'type' => 'input', 'require' => 1), array('name' => 'Website:', 'type' => 'input', 'require' => 1, 'pre' => 'http://', 'post' => '.com'), now in the contact-form replace ?> <div class="input"><input name="<?=$i;?>" type="text" value="<?=contact_form_post($i);?>" <?=$slash;?>></div> <?php if(isset($x['pre'])||isset($x['post'])) { $str = contact_form_post($i); if(isset($x['pre'])&&substr($str,0,strlen($x['pre']))==$x['pre']) { $str=substr($str,strlen($x['pre'])); } if(isset($x['pre'])&&substr($str,(strlen($str)-strlen($x['post'])))==$x['post']) { $str=substr($str,0,(strlen($str)-strlen($x['post']))); } $_POST[$i]=$str; } ?> <div class="input"><input name="<?=$i;?>" type="text" value="<?= $x['pre']; ?><?=contact_form_post($i);?><?= $x['post']; ?>" <?=$slash;?>></div> <?php run a quick test and looks ok
  22. if your outputting the date into the sql with hyphens, then the rule applied has to contain the map so if your DOB is : 16/05/1979 then the SQL is STR_TO_DATE('16/05/1979','%d/%m/%Y') so if your DOB is : 16-05-1979 then the SQL is STR_TO_DATE('16-05-1979','%d-%m-%Y') so if your DOB is : 16?05?1979 then the SQL is STR_TO_DATE('16?05?1979','%d?%m?%Y') so if your DOB is : 16_05_1979 then the SQL is STR_TO_DATE('16_05_1979','%d/%m/%Y') so if your DOB is : 05/16/1979 then the SQL is STR_TO_DATE('05/16/1979','%m/%d/%Y') so if your DOB is : 05-16-1979 then the SQL is STR_TO_DATE('05-16-1979','%m-%d-%Y') so if your DOB is : 05?16?1979 then the SQL is STR_TO_DATE('05?16?1979','%m?%d?%Y') and so on and so on have fun
  23. lol @ my spelling The hyphen ( ‐ ) is a punctuation mark used to join words and to separate syllables of a single word. It should not be confused with dashes ( –, —, ― ), which are longer and have different uses, and with the minus sign ( − ) which is also longer. The use of hyphens is called hyphenation. In environments that are restricted to ISO 646 the hyphen-minus is used as a replacement. http://en.wikipedia.org/wiki/Hyphen
  24. can you do a <pre> <?= var_dump(get_defined_vars()); ?> </pre> and see if the file name your calling is correct upload the dump if you can, obviously without your sensitive bits
×
×
  • 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.