Jump to content

chriscloyd

Members
  • Posts

    488
  • Joined

  • Last visited

Everything posted by chriscloyd

  1. I do not know whats going on. I have tried two different methods of validating and email and it keeps saying invalid email I have even tried to debug it by putting errors and nothing i have tried preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $e) and fliter_var($e, FLITER_VALIDATE_EMAIL); the email i am trying to debug is a valid one. its one I use daily. I have tried different emails and still no luck.... someone help me please!
  2. I am trying to make a presentation generator, using information from my database; my str_replace is not working please help.... here is my code <?php $Sql = "SELECT * FROM csm_players WHERE uid = '{$this->Uid}'"; $Query = mysql_query($Sql); $Style = $this->UserInfo['playerstyle']; while ($p = mysql_fetch_assoc($Query)) { $name = explode(" ",$p['name']); $PlayerName = (strpbrk($Style, '{FIRSTNAME}') ? str_replace("{FIRSTNAME}",$name[0],$Style) : ""); $PlayerName1 = (strpbrk($Style, '{LASTTNAME}') ? str_replace("{LASTTNAME}",$name[1],$PlayerName) : ""); $PlayerName2 = (strpbrk($Style, '{NICKNAME}') ? str_replace("{NICKNAME}",$p['nickname'],$PlayerName1) : ""); if ($p['cl'] == 1) { if ($this->UserInfo['clba'] == 1) { $Show .= "<div>{$this->UserInfo['clstyle']} {$PlayerName}</div>"; } else { $Show .= "<div>{$PlayerName} {$this->UserInfo['clstyle']}</div>"; } } else { $Show .= "<div>{$PlayerName}</div>"; } } //$Show .= "Error"; return $Show; this is what its returning Shelton "{NICKNAME}" {LASTNAME} [CL] Lindsey "{NICKNAME}" {LASTNAME} Eitan "{NICKNAME}" {LASTNAME} Aake "{NICKNAME}" {LASTNAME} Hunter "{NICKNAME}" {LASTNAME} if i take out the firstname search then it find the nickname and if i take out the nickname and the first it shows the last one.... what do i do? i have tried to put them in an array and do a foreach with keys and val but that doesnt work either im at a standstill. it works for my other script but not for this...
  3. I guess, I am lost at what you are asking or helping with. I am trying to always show 5 Results. When I am on page one it will only show [1] 2 3 when I am on page 6 it will only show 4 5 [6]. So I guess I must just be completely confused or what.
  4. I am trying to do my own pagination script to better learn php i do need some help.. First let me explain my goal, then show you the code I have which is not working. I have 5 blogs per page; I have at least 30 blogs in the database for testing purpose; I want the pagination to go as shown if you are first viewing the blog no page selected it will show [1] 2 3 4 5 ... Last Page if you for example choose page three it will show 1 2 [3] 4 5 ... Last Page Now what is happening when you click on page 5 or 6 it does First Page... 4 5 [6] When I would like it to show First Page... 2 3 4 5 [6] or 2 3 4 [5] 6 here is my code <?php //if current page != 1 show first page link $Show .= ($this->CurPage != 1 ? "<a href=\"?module=blog&page=1\">First Page</a>... " : ""); //We need the number of start for the for statement //We need to check if the number of pages excedes three if it does then make the start minus 2 of the current page $Start = (($this->CurPage - 2) >= 1 ? $this->CurPage - 2 : 1); //We need the end page for the for statement $End = (($this->CurPage + 2) <= $this->NumOfPages ? $this->CurPage + 2 : $this->NumOfPages); //Run End Again to make sure $NewEnd = ($End <= 3 && $this->NumOfPages > 5 ? $End + 2 : $End); //Run Start again to make sure $NewStart = ($this->CurPage >= ($this->NumOfPages - 2) ? $Start - 2 : $Start); for ($i = $NewStart; $i <= $NewEnd; $i++) { $Show .= ($i == $this->CurPage ? "<a href=\"?module=blog&page={$i}\"><strong>[{$i}]</strong></a> " :"<a href=\"?module=blog&page={$i}\">{$i}</a> " ); } //If More than one page and you are not on the last page $Show .= ($this->CurPage != $this->NumOfPages && $this->NumOfPages > 1 ? " ...<a href=\"?module=blog&page={$this->NumOfPages}\">Last Page</a>" : ""); return $Show; ?>
  5. try <?php //get sql $Sql = "SELECT * FROM {$table} WHERE id = '{$id}'"; //run query $Query = mysql_query($Sql); //allowed ext $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); //input array) $input_array = array(); //$data $info = mysql_fetch_array($Query); //now start the form $Form = "<form name=\"insert_table\" id=\"insert_table\" action=\"ad_add.php\" method=\"post\" enctype=\"multipart/form-data\"> <fieldset> <legend> Table Information </legend> <input name=\"table\" type=\"hidden\" value=\"{$table}\">"; //run foreach lop now foreach ($info as $key => $val) { $header = str_replace("_"," ",$key); $Form .= ($key == 'image' ? "<p>{$header}: <input name=\"{$key}\" id=\"{$key}\" type=\"file\" /></p>" : "<p>{$header}: <input name=\"{$key}\" id=\"{$key}\" type=\"text\" value=\"{$val}\" /></p>" ); } $Form .= "<p> <input type=\"submit\" name=\"submit_mod\" id=\"submit_mod\" /> </p> </fieldset> </form>"; echo $Form; ?>
  6. Here you go <?php //get sql $Sql = "SELECT * FROM {$table} WHERE id = '{$id}'"; //run query $Query = mysql_query($Sql); //allowed ext $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); //input array) $input_array = array(); //$data $info = mysql_fetch_array($Query); foreach ($info as $val) { $input_array[] = $val; } //now start the form $Form = "<form name=\"insert_table\" id=\"insert_table\" action=\"ad_add.php\" method=\"post\" enctype=\"multipart/form-data\"> <fieldset> <legend> Table Information </legend> <input name=\"table\" type=\"hidden\" value=\"{$table}\">"; //run foreach lop now foreach ($input_array as $key => $val) { $header = str_replace("_"," ",$key); $Form .= ($key == 'image' ? "<p>{$header}: <input name=\"{$key}\" id=\"{$key}\" type=\"file\" /></p>" : "<p>{$header}: <input name=\"{$key}\" id=\"{$key}\" type=\"text\" value=\"{$val}\" /></p>" ); } $Form .= "<p> <input type=\"submit\" name=\"submit_mod\" id=\"submit_mod\" /> </p> </fieldset> </form>"; echo $Form; ?>
  7. What does your table look like where your getting your information?
  8. you could also do <?php foreach ($Info as $key => $val) { //so every row it pulled from the database can be printed at least once. echo "{$key}: {$val}"; }
  9. well do this <?php $Get = mysql_query("SELECT....."); $Info = mysql_fetch_array($Get); //that sets all the info as an array //so echoing and choosing the key is simple echo $Info['keyhere/tablename']; /*that will echo the variable for that key*/
  10. There are a couple things I was not clear about like how are you getting your level and validating the information.... Are you going through a database If you are let me know and I can tweak the code I just did for you if not hopefully you can tweak it the way you need. <?php session_start(); //First off let me state you should not make yours errors say that the username does not exist //I Would just say Incorrect Username/Password //Create Error Array $LErrors = array(); //Create Array With User Info $UserInfo = array( "Username" => $_GET['username'], "Password" => $_GET['password'] ); if (isset($_POST['submit'])) { foreach ($UserInfo as $key => $val) { $val = mysql_real_escape_string($val); if ($key == "Password") { //encrypt your password if you like //I like to use hash //${$key} = hash("SHA256",$val); } if ($val == '') { $LErrors[] = "{$key}: is not allowed to be empty!" } else { ${$key} = $val; } } //check if there are errors if (empty($LErrors)) { //check if user information is correct if ($Username == $dbusername && $Password == $dbpassword) { //check if user is an admin $_SESSION['Username'] = $Username; if ($admin != 0) { $_SESSION['Level'] = "ADMIN"; header("Location: admin.php"); } header("Location: index.php"); } else { $LErrors[] = "Incorrect Username/Password!"; } } else { foreach ($LErrors as $val) { echo "<li>{$val}</li>"; } echo "<div id=\"div-Login\"> <form action=\"\" method=\"post\" target=\"loginerror\"> <center><h2>Login Here</h2> <p> Username: <input type=\"text\" name=\"username\"><p> Password: <input type=\"password\" name=\"password\"><p> <input type=\"submit\" name=\"submit\" value=\"Login\"> </center> <a href=\"register.html\"><pre>need to register? Click Here!</pre></a> </form> </div>"; } } else { echo "<div id=\"div-Login\"> <form action=\"\" method=\"post\" target=\"loginerror\"> <center><h2>Login Here</h2> <p> Username: <input type=\"text\" name=\"username\"><p> Password: <input type=\"password\" name=\"password\"><p> <input type=\"submit\" name=\"submit\" value=\"Login\"> </center> <a href=\"register.html\"><pre>need to register? Click Here!</pre></a> </form> </div>"; }
  11. In your table you should have some sort of coloumn named like status or something so once you hit approve it will do a mysql_query update and set that as approved then just add in your code some where <?php echo ($table["status"] == "approved" ? $table["job_no"] : ""); ?>
  12. you have the code started but you are going to want a jquery or ajax function that dynamically loads your information for the next select menu
  13. Haha, my bad I forgot to add that part to the code
  14. just an attempt <?php //start out with your session session_start(); //config file include 'connect.php'; //header file include 'header.php'; //set two arrays one for info and one for errors $info = array( "username" => $_POST['username'], "password" => $_POST['password'] ); $errors = array(); foreach ($info as $key => $val) { if ($key == 'password') { $val = md5($val); } $val = mysql_real_escape_string($val); if ($val == '') { $errors[] = "The {$key} field must not be empty"; } } //now check if the errors is empty if(empty($errors)) { $sql = "SELECT `userid`,`username`,`userlevel` FROM `users` WHERE `username` = '{$info['username']}' AND `password` = {$info['password']}'"; $result = mysql_query($sql); if(!$result) { //something went wrong, display the error echo 'Something went wrong while signing in. Please try again later.'; //echo mysql_error(); //debugging purposes, uncomment when needed } else { //the query was successfully executed, there are 2 possibilities //1. the query returned data, the user can be signed in //2. the query returned an empty result set, the credentials were wrong if(mysql_num_rows($result) == 0) { echo 'You have supplied a wrong user/password combination. Please try again.'; } else { //set the $_SESSION['signed_in'] variable to TRUE $_SESSION['signed_in'] = true; //we also put the user_id and user_name values in the $_SESSION, so we can use it at various pages while($row = mysql_fetch_assoc($result)) { $_SESSION['userid'] = $row['userid']; $_SESSION['username'] = $row['username']; $_SESSION['userlevel'] = $row['userlevel']; } echo 'Welcome, ' . $_SESSION['username'] . '. <br /><a href="index.php">Proceed to the forum overview</a>.'; } } } else { echo 'Uh-oh.. a couple of fields are not filled in correctly..<br /><br />'; echo '<ul>'; foreach($errors as $value) { /* walk through the array so all the errors get displayed */ echo "<li>{$value}</li>"; /* this generates a nice error list */ } echo '</ul>'; } include 'footer.php'; ?>
  15. you use a database? You can set up a table for Votes say your link is mydomain.com/?vote=id on the page that actually does the voting create a script to insert the vote for example <?php //clean id $id = mysql_real_escape_string($_GET['id']); //check if it has been voted on already $Check = "SELECT * FROM Votes WHERE id = '$id}'"; $Query = mysql_query($Check); if ($Query) { $Update = "UPDATE Votes SET votes = votes + 1 WHERE id = '{$id}'"; mysql_query($Update); } else { $Insert = "INSERT INTO Votes (`id`,`votes`) VALUES ('{$id}','1')"; mysql_query($Insert); }
  16. you can put the questions you pull from your db into an array and have a class function or just a function make a form from the array like I did, so I dont have to keep typing out inputs. Example <?php function CreateForm($title,$action,$method,$info) { $form = "<form action=\"{$action}\" method=\"{$method}\" name=\"{$title}\">"; foreach ($info as $key => $val) { //check for submit key if ($val[0] == 'submit') { $form .= "<input type=\"{$val[0]}\" name=\"{$val[0]}\" value=\"{$val[1]}\"></div>"; } elseif ($val[0] == 'hidden') { $form .= "<div class=\"FormLine\"><input type=\"{$val[0]}\" name=\"{$val[1]}\" value=\"{$val[1]}\">"; } else { //first check if title is update if ($title == "Update") { //now we can echo their info into the values $form .= "<div class=\"FormLine\"><input type=\"{$val[0]}\" name=\"{$val[1]}\" value=\"{$val[2]}\" "; $form .= "onfocus=\"if (this.value==this.defaultValue) this.value = ''\""; $form .= "onblur=\"if (this.value=='') this.value = this.defaultValue\" />"; $form .= "</div>"; } else { $form .= "<div class=\"FormLine\"><input type=\"{$val[0]}\" name=\"{$val[1]}\" value=\"{$key}\" "; $form .= "onfocus=\"if (this.value==this.defaultValue) this.value = ''\" "; $form .= "onblur=\"if (this.value=='') this.value = this.defaultValue\" />"; $form .= "</div>"; } } } $form .= "</form>"; return $form; } $Larray = array ( "Username" => array("text","LoginUsername"), "Password" => array("password","LoginPassword"), "Hidden" => array("hidden","SecureHidden"), "Login" => array("submit","Login"), ); $CreateForm = CreateForm("Login","{$_SERVER['PHP_SELF']}","post",$Larray); echo $CreateForm; ?>
  17. Okay I made some updates to my LoginUser function I can login but it still wont show any errors here is my code for that part <?php //class.actions.php class Actions extends Database { public $Uid; //Login Vars private $Username; private $Password; //Errors Array private $Errors = array(); //get errors public function ReturnErrors($var) { //get key from var return $this->Errors[$var]; } //Login User public function LoginUser($info, $admin = NULL) { $LErrors = array(); foreach ($info as $key => $val) { $this->{$key} = mysql_real_escape_string($val); if ($val == '') { $LErrors[] = "{$key}: can no be left blank."; } } if (!empty($LErrors)) { $this->Errors["Login"] = $LErrors; return false; } $this->Password = $this->EncryptPass($this->Password); $Check = $this->select("users","`id`","username = '{$this->Username}' AND password = '{$this->Password}'"); if ($Check) { $Result = $this->getResult(); $id = $Result[id]; $this->Uid = $id; return true; } else { $LErrors[] = "Invalid Credentials!"; $this->Errors["Login"] = $LErrors; return false; } } } ?>
  18. Okay, I am having trouble. My script is not echoing the errors on the page/nor logging me in. If I check the browser source code it shows the error. here are my pages please help this is stupid ha index.php <?php session_start(); include("includes/config.php"); if($_POST['submit']) { include("includes/action/".strtolower($_POST['submit']).".php"); } if (isset($_SESSION['SecureUid'])) { echo "Welcome Member!"; } else { echo $_SESSION['SecureUid']; $Larray = array ( "Username" => array("text","LoginUsername"), "Password" => array("password","LoginPassword"), "Hidden" => array("hidden","SecureHidden"), "Login" => array("submit","Login"), ); if ($LoginErrors) { foreach ($LoginErrors as $val) { echo "{$val}<br />"; } $Site->ClearErrors(); } $CreateForm = $Site->CreateForm("Login","{$_SERVER['PHP_SELF']}","post",$Larray); echo $CreateForm; } ?> includes/config.php <?php ini_set( "display_errors", true ); date_default_timezone_set( "America/Phoenix" ); define( "CLASS_PATH", "includes/classes" ); //define( "TEMPLATE_PATH", "templates" ); define( "HOMEPAGE_NUM_ARTICLES", 5 ); function handleException( $exception ) { echo "Sorry, a problem occurred. Please try later."; error_log( $exception->getMessage() ); } set_exception_handler( 'handleException' ); include(CLASS_PATH."/class.database.php"); include(CLASS_PATH."/class.actions.php"); $Site = new Actions; $Site->connect(); $Site->setDatabase("ccloyd_rigid"); ?> includes/actions/login.php <?php //log user in if ($_POST['SecureHidden']) { $Login = $Site->LoginUser(array("Username" => $_POST['LoginUsername'], "Password" => $_POST['LoginPassword'])); if ($Login) { $_SESSION['SecureUid'] = $Site->Uid; $_SESSION['SecureLevel'] = $Site->getLevel($Site->Uid); } else { $LoginErrors = $Site->ReturnErrors("Login"); } } ?> includes/classes/class.actions.php <?php class Actions extends Database { public $Uid; //Login Vars private $Username; private $Password; //Errors Array private $Errors = array(); public function LoginUser($info, $admin = NULL) { //ugh //startover foreach ($info as $key => $val) { $this->{$key} = mysql_real_escape_string($val); } $this->Password = $this->EncryptPass($this->Password); if ($this->Username == '' || $this->Password == '') { $this->Errors["Login"] = array('Invalid Credentials!'); return false; } $Check = $this->select("users","`id`","username = '{$this->Username}' AND password = '{$this->Password}'"); if ($Check) { $Result = $this->getResult(); $id = $Result[id]; $this->Uid = $id; return true; } else { $this->Errors["Login"] = array('Invalid Credentials!'); return false; } } } ?>
  19. try this code, run it if there are any errors let us know <?php include 'connection.php'; if(!isset($_POST['submit'])) { $query = "SELECT * FROM news WHERE id = $_GET[id]"; $result = mysql_query($query); $news = mysql_fetch_array($result); $title = $_POST['title']; $body = $_POST['body']; } ?> <h1>Edit Article</h1> <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> Title:<input type="text" name="title" value="<?=$news['title'];?>" /><br /> Article:<textarea cols="35" rows="6" name="body"><?=$news['body'];?></textarea> <br /> <input type="hidden" name="id" value="<?=$_GET['id'];?>" /> <input type="image" src="/images/news/modify.png" name="submit" /> </form> <a href="admin.php"><img src="/images/news/cancel.png" border="0" /></a> <?php if(isset($_POST['submit'])) { $title = mysql_real_escape_string($_POST[title]); $body = mysql_real_escape_string($_POST[body]); $id = mysql_real_escape_string($_POST[id]); $update = "UPDATE news SET `title`='{$title}',`body`='{$body}' WHERE id='{$id}'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo "The news article has been Modified!"; header('Location: /News/admin.php'); } ?>
  20. Probably the easiest way is what TimeBomb suggested, but here is another look at it <?php $array = Array ( 0 => Array ( 'media' => 'friend' ), 1 => Array ( 'media' => 'friend' ), 2 => Array ( 'media' => 'friend' ), 3 => Array ( 'media' => 'Coming Over From Old Site' ) ); $second = array(); foreach ($array as $val) { foreach ($val as $nval) { $second[] = $nval; } } print_r(array_count_values($second));
  21. Show us your code, because as of right now. What I created and posted would work....
  22. if your fields in the table are the same you can do this <?php //include config file $old_table = ""; $new_table = ""; //get info from link like the id $id = $_GET['id']; //setup sql $Sql = "SELECT * FROM `{$old_table}` WHERE `id` = '{$id}'"; $Query = mysql_query($Sql); if ($Query){ $info = mysql_fetch_array($Query); } //set arrays for fields and values $fields = array(); $values = array(); foreach ($info as $key => $val) { $fields[] = "`{$key}`"; $values[] = "'{$val}'"; } //join fields to act as one string but seperated by , $nFields = join(",", $fields); $nValues = join(",", $values); //create sql $Copy = "INSERT INTO `{$new_table}` ({$nFields}) VALUES ({$nValues})"; $Create = mysql_query($Copy); if ($Create) { //delete old row $Delete = "DELETE FROM `{$old_table}` WHERE id = '{$id}'"; $Run = mysql_query($Delete); } else { //dont delete do something }
  23. are you moving everything to the same table layout? or will the fields be the same?
  24. what if he does not have a class <?php session_start(); //include your config file to connect to db //get id or name or how ever you set ur where statement //for example ill do a session $id = $_SESSION['MySiteUserId']; $Sql = "SELECT `gender` FROM `Users` WHERE `id` = '{$id}'"; $Query = mysql_query($Sql); if ($Query) { $info = mysql_fetch_array($Query); $gender = $info['gender']; } //set array for dropdown $DropDown = array ( "Male", "Female" ); echo "<select name=\"gender\">"; foreach ($DropDown as $val) { if ($val == $gender) { echo "<option value=\"{$val}\" selected>{$val}</option>"; } else { echo "<option value=\"{$val}\">{$val}</option>"; } } echo "</select>";
×
×
  • 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.