PHP - Okay, I've Done My Best, I Am Truly Stuck Now.
Okay, I have a P value field in my Database ROW. It contains 0,1,2
0 is my About Me, 1 is my Signature Section 2 is my Friends section: Check this screenshot: Now you see that little green arrow? When you click on it, I have the code for it he Code: [Select] if (isset($ibforums->input['down'])){ if ($ibforums->input['down'] == "0"){ $new = '1,0,2'; } $DB->query("UPDATE ibf_members set p='$new' WHERE id={$ibforums->member['id']}"); header("Location: ?i={$ibforums->input['i']}"); } As you can see, it updates it 1,0,2. (Default is 0,1,2) for variable $p. Here is my code. Code: [Select] $p = explode(",", $member['p']); $middle=array ( "0" => array ( "section" => $aboutme, "b" => "banana", "c" => "apple" ), "1" => array ("section" => $signature, "b" => "banana", "c" => "apple" ), "2" => array ("section" => $f, "b" => "banana", "c" => "apple" ), ); $order = $p; print_r($middle); foreach ($order as $index) { $middlesection.= $middle[$index]['section']; } I echo out my $middlesection variable in my profile page, that's the screenshot that you see. My problem is, How can I check the input's when they click the green arrow button to know "not to go down anymore", I will be adding a up Arrow icon next to it... (I am very lost and little bit confused on how to check the input to make it all work) see like right now, on that screenshot it is: 1,0,2 (Signature,Aboutme,Friends) but if I click on that arrow again, how do I Dynamically make the 0 make sure it is the last one? but then see if I have to switch the 0 to 1,2,0 how would I check input on my 2 to know if it was the last one to move over to the second "," ?? It's just so confusing, (am I doing it wrong? it seems really confusing) But yeah... I appreciate your responses, hope you can guide,help me to get this done. Similar TutorialsHi all ! <?php if(!isset($_SESSION['logged_in'])) { $_SESSION['logged_in'] = false; } if($_SESSION['logged_in'] == false) { if($_SERVER["REQUEST_METHOD"] == "POST") { $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); $password2=md5($password); $sql = "SELECT * FROM users WHERE username='$username' and password='$password2'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if($count==1){ $_SESSION['logged_in'] = true; echo '<meta http-equiv="Refresh" content="0; url=profile"> '; } else { echo 'Sorry! Incorrect...'; } } } else { echo 'Hello '.$result[username].'The stuff you want to see! ;)'; } ?> I basicly just wanna make the user login and then show "hello, whatever your username is, the stuff you want to see", you get it. but something allways goes wrong, could someone help me with the code :s I've been stuck too long for my beginner brain. Here is the majority of the code: Code: [Select] mysql_connect($host, $dbusername, $password); mysql_select_db($TxQuizdb); $quizquery = mysql_query("SELECT Id, Total_Questions, Maximum_Score, Passing_Score, Correct_Answer FROM Module_1_Quiz WHERE Id = '1'"); $quizqueryresult = mysql_fetch_array($quizquery); $totalq = $quizqueryresult['Total_Questions']; $maxscore = $quizqueryresult['Maximum_Score']; $passingscore = $quizqueryresult['Passing_Score']; $qvalue = $maxscore / $totalq; //scoring values $Score=0; $ansquery = mysql_query("SELECT Correct_Answer FROM Module_1_Quiz"); $QChoice_1 = $_POST['QChoice_1']; $QChoice_2 = $_POST['QChoice_2']; while ($answers = mysql_fetch_array($ansquery)) { $i++; if ($_POST['QChoice_$i'] == $answers['Correct_Answer']) { $Score = round(($Score + $qvalue), 0); } else { echo "wrong";} } The problem i am running into is trying to score this quiz with the following: Code: [Select] while ($answers = mysql_fetch_array($ansquery)) { $i++; if ($_POST['QChoice_$i'] == $answers['Correct_Answer']) { $Score = round(($Score + $qvalue), 0); } else { echo "wrong";} } I can't get the "if" statement to satisfy.....and am about to rip my eyes out... thanks! Hello, I have a mysql table and when I populate it through php i have to insert blank values into fields if not it will not work. How can I put the default value in phpmyadmin to be blank, but not null. I dont understand the null checkbox or the default value option. Please help not phpmyadmin guides found Hi guys im ben from Liverpool and im making an online store in php, and have been following a tutorial. the problem is my site so far is on wampserver. When i upload the database and php files to an online host my work just does not show. Has any1 got any advice or willing to help me? i would much appreciate it! I have a table called data which stores name and other material and there is a table called match. Match has an auto incrementing id called match_id and a row called match_1 and match_2. Ok what happens is an id which is unique from the data table is stored in match_1 and another id which is unique from the data table is stored in match_2 For example Match_id match_1 match_2 40 1 2 40 2 1 Is there any way to retrive the data of both ids for instance in this case match_1 and match_2 based on the match_id being same? I tried a few joining queries but no luck for me could some one tell me how can I achieve this thanks. Basically get name place etc details of match 1 and match 2 based on the match_id Hi all, I am kinda stuck on the return() statement in the php.net manual about control structures. (http://au.php.net/manual/en/function.return.php) All I see is notes on when not to use it and some scary examples with loads of foo and bar but, it's hard to find out when it would be nice to use it. At the moment i am thinking its another way of echo, but I bet that's wrong. If someone could enlighten me a bit on when return() is useful I would be very happy since i see it more often everyday. CHeers! Hi: I am stuck on one little glitch with an IF ELSE statement .. hoping someone with fresh eyes can see what I am missing. The checkbox will not stay checked, and I'm over looking something but fail to see it. Code: [Select] <? if ($id != "4" ) { echo "<input type='checkbox' name='myPageActive' value='Yes' <?php if($myPageActive == 'Yes') echo 'checked'; ?>> Yes"; } else { echo "<span class='myDeleteMessage'>Homepage must stay active</span>"; } ?> It seems to have something to do with this part: Code: [Select] <?php if($myPageActive == 'Yes') echo 'checked'; ?>> Yes"; Can anyone see what I am missing? Thanks! Been trying to sort this out for a while now, had an earlier post on this as well yet haven't solved it yet. Code has changed a bit since then but still giving me trouble and I have a due date for this project is is sneaking up on me. I am trying edit previously entered information from a table which contains a student's registration information into a form. The previously entered info wont display and I am having numerous errors Here is my code Code: [Select] <?php if (!isset($_POST['sno'])) { $q = "SELECT * FROM student WHERE sno = " . $_GET['sno']; $result = mysql_query($q); $person = mysql_fetch_array($result); } ?> <h1> You are editing a student </h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Course name:</p> <select name="input1"> <?php $q = "SELECT cname FROM course "; $result = mysql_query($q); WHILE ($course = mysql_fetch_array($result)) { echo "<OPTION>{$course['cname']}</option>"; } echo " </SELECT>" ?> <br> <p>Surname:</p> <INPUT TYPE = "text" name = "input2"value= " <?php echo $person['sname']; ?>" /> <br> <p>Initials:</p> <INPUT TYPE = "text" name="input3"value="<?php echo $person['init']; ?>" /> <br> <p>Full First Name:</p> <INPUT TYPE = "text" name="input4"value="<?php echo $person['fname']; ?>" /> <br> <p>Title:</p> <INPUT TYPE = "text" name="input5"value="<?php echo $person['title']; ?>" /> <br> <p>Maiden or previous surname:</p> <INPUT TYPE = "text" name="input6"value="<?php echo $person['msname']; ?>" /> <br> <p>Date of Birth:</p> <INPUT TYPE = "text" name="input7"value="<?php echo $person['dob']; ?>" /> <br> <p>Gender:</p> Male <input type="radio" name="input8" value="m" /> Female <input type="radio" name="input8" value="f" /><br/> <br> <p>Language</p> <select name="input9"> <option >English</option> <option >Afrikaans</option> </select> <br> <p>Identity Number:</p> <INPUT TYPE = "text" name="input10"value="<?php echo $person['id']; ?>" /> <br> <p>Home Telephone Code + Number:</p> <INPUT TYPE = "text" name="input11"value="<?php echo $person['telh']; ?>" /> <br> <p>Work Telephone Code + Number:</p> <INPUT TYPE = "text" name="input12"value="<?php echo $person['telw']; ?>" /> <br> <p>Cell Phone Number:</p> <INPUT TYPE = "text" name="input13"value="<?php echo $person['cel']; ?>" /> <br> <p>Fax Code + Number:</p> <INPUT TYPE = "text" name="input14"value="<?php echo $person['fax']; ?>" /> <br> <p>E-mail Address:</p> <INPUT TYPE = "text" name="input15"value="<?php echo $person['email']; ?>" /> <br> <p>Postal Address of student:</p> <textarea name="input16" COLS=50 ROWS=5 /><?php echo $person['address']; ?> </textarea> <br> <input type= "hidden" name="sno" value="<?php echo $_GET['sno']; ?>" /> <INPUT TYPE = "Submit" name="submit" VALUE = "Update"/> </form> <?php if(isset($_POST['submit'])) { $u = "UPDATE student SET `cname` = '$_POST[input1]', `sname` = '$_POST[input2]', `init` = '$_POST[input3]', `fname` = '$_POST[input4]', `title` = '$_POST[input5]', `msname` = '$_POST[input6]', `dob` = '$_POST[input7]', `sex` = '$_POST[input8]', `lang` = '$_POST[input9]', `idno` ='$_POST[input10]', `telh` = '$_POST[input11]', `telw` = '$_POST[input12]', `cel` = '$_POST[input13]', `fax` = '$_POST[input14]', `email` = '$_POST[input15]', `address` = '$_POST[input16]' WHERE ID = $_POST[sno]"; mysql_query($u) or die(mysql_error()); echo "User has been modified!"; header("Location: index.php"); } ?> The errors are ad followed. When I open the form I get these erros and the fields are blank: Notice: Undefined index: sno in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 27 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 29 When i enter new info and submit it I get these errors: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Notice: Undefined index: sno in C:\Program Files\EasyPHP-5.3.' at line 19 And my fields contain random code e.g "<br /> <b>Notice</b>: Undefined variable: person in <b>C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php</b> on line <b>97</b><br />" Also I dont know if this would help at all but here's the previous page which contains the code for displaying the students information and allowing to edit it, which links to the edit page Code: [Select] <?php while ($rows = mysql_fetch_array($query)): echo "<a href=\"editstudent.php?id=" . $rows['sno'] ."\" > edit </a>"; $sno=$rows['sno']; $cname=$rows['cname']; $sname=$rows['sname']; $fname=$rows['fname']; echo " <table border=1px> <tr> <td>$sno</td> <td>$cname</td> <td>$sname</td> <td>$fname</td> </tr> </table>" ; endwhile; ?> Any help would be greatly appreciated. Thanks in advance for your time and effort. Hi all,
I have 3 files, namely, [custom.js / allitem.php / fetch_pages.php]. where i have been compiling, studying and at the same time create a website of my own. I am a total newbie, so i gather examples from the entire web and try to put it together. But right now, I am stuck for 3 long days going 4 days tomorrow in a single problem whereas my head is banging on how to do it. Also been searching in internet of the same problem this has. but unfortunately, i find similar but still cant get it to work.
The codes below are currently working as I want it to be. Except from starting at this location, at [fetch_pages.php] -->
<span class="page_name"><a class="show-popup" href="#?id='.$row['id'].'">'.$row['name'].'</a></span>
Where I dont know how to retrieve the value of id='.$row['id'].' and passed it to below location and use it to query the products where id=$id.
<div class="overlay-bg" id="overlay-bg"> <div class="overlay-content"> $result = mysql_query("SELECT * FROM products WHERE id=$id", $mysqli); </div> </div> Can anyone help me code it out from this. Please.... ---------------------------------------------------------------------------------------- custom.js $(document).ready(function(){ // show popup when you click on the link $('.show-popup').click(function(event){ event.preventDefault(); var docHeight = $(document).height(); var scrollTop = $(window).scrollTop(); $('.overlay-bg').show().css({'height' : docHeight}); $('.overlay-content').css({'top': scrollTop+20+'px'}); }); $('.close-btn').click(function(){ $('.overlay-bg').hide(); // hide the overlay }); $('.overlay-bg').click(function(){ $('.overlay-bg').hide(); }) $('.overlay-content').click(function(){ return false; }); document.getElementById('data-id').innerHTML = 'data-id'; return id = 'data-id' });allitem.php <?php session_register(); session_start(); include("connect.php"); $catphp=$_GET["catphp"]; $_SESSION['catphp']=$catphp; //PAGINATION---------------------------------- $results = mysqli_query($mysqli,"SELECT COUNT(*) FROM products WHERE itemcon='$catphp'"); $get_total_rows = mysqli_fetch_array($results); //total records //break total records into pages $pages = ceil(($get_total_rows[0]/$item_per_page) + 1); //create pagination if($pages > 1) { $pagination = ''; $pagination .= '<ul class="paginate">'; for($i = 1; $i<$pages; $i++) { $pagination .= '<li><a href="#" class="paginate_click" id="'.$i.'-page">'.$i.'</a></li>'; } $pagination .= '</ul>'; } //PAGINATION---------------------------------- ?> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script type="text/javascript" src="overlay/custom.js"></script> <link href='overlay/overlaypopup.css' rel='stylesheet' type='text/css'> <script type="text/javascript"> $(document).ready(function() { $("#results").load("fetch_pages.php", {'page':0}, function() {$("#1-page").addClass('active');}); //initial page number to load $(".paginate_click").click(function (e) { $("#results").prepend('<div class="loading-indication"><img src="ajax-loader.gif" /> Loading...</div>'); var clicked_id = $(this).attr("id").split("-"); //ID of clicked element, split() to get page number. var page_num = parseInt(clicked_id[0]); //clicked_id[0] holds the page number we need $('.paginate_click').removeClass('active'); //remove any active class //post page number and load returned data into result element //notice (page_num-1), subtract 1 to get actual starting point $("#results").load("fetch_pages.php", {'page':(page_num-1)}, function(){ }); $(this).addClass('active'); //add active class to currently clicked element (style purpose) return false; //prevent going to herf link }); }); </script> </head> <body> <div id="results"></div> <?php echo $pagination; ?> </body>fetch_pages.php <?php session_start(); $catphp = $_SESSION['catphp']; include("connect.php"); //include config file ?><head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script type="text/javascript" src="overlay/custom.js"></script> <link href='overlay/overlaypopup.css' rel='stylesheet' type='text/css'> </head> <?php //sanitize post value $page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //validate page number is really numaric if(!is_numeric($page_number)) { die('Invalid page number!'); } //get current starting point of records $position = ($page_number * $item_per_page); //Limit our results within a specified range. $results = mysqli_query($mysqli,"SELECT * FROM products WHERE itemcon='$catphp' ORDER BY id ASC LIMIT $position, $item_per_page"); //output results from database to a paginated window echo '<ul class="page_result">'; while($row = mysqli_fetch_array($results)) { echo '<li id="item_'.$row["id"].'">'.$row["id"].'. <span class="product-thumb"><img src="uploads/thumbs/'.$row['pic'].'"></span> <span class="page_name"><a class="show-popup" href="#?id='.$row['id'].'">'.$row['name'].'</a> </span> <br /><br /> <span class="page_description">'.$row["description"].' </span><br /><br /> <span class="page_itemcondesc">Condition : <span class="page_itemcon">'.$row["itemcon"].'</span> </span> <span class="page_warrantydesc">Warranty : <span class="page_warranty">'.$row["warranty"].'</span> </span> <br /><br /> <span class="page_price">Price:'.$row["price"].'</span> </li>'; } echo '</ul>'; ?> <div class="overlay-bg" id="overlay-bg"> <div class="overlay-content"> <font style="font-weight:bold">Product Details </font> <br /> <?php include "xx.isd"; $mysqli = mysql_connect($mysql_hostname,$mysql_user,$mysql_password); if (!$mysqli) { die("Database connection failed: " . mysql_error()); } //Select a database to use $db_select = mysql_select_db($mysql_database,$mysqli); //Perform database query to read the table entry $result = mysql_query("SELECT * FROM products WHERE id=$id", $mysqli); if (!$result) { die("Database query failed: " . mysql_error()); } //Use returned data while($row = mysql_fetch_array($result)) { $id=$row['id']; $product_code=$row['product_code']; $name=$row['name']; $description=$row['description']; $specs=$row['specs']; $accessory=$row['accessory']; $notes=$row['notes']; $itemcon=$row['itemcon']; $warranty=$row['warranty']; $price=$row['price']; $stocks=$row['stocks']; $category=$row['category']; $pic=$row['pic']; echo '<li id="item_'.$row["product_code"].'">'.$row["product_code"].' <span class="page_name">'.$row["name"].'</a> </span> <br /><br /> <span class="page_description">'.$row["description"].' </span><br /><br /> <span class="page_specs"><font style="font-weight:bold">Specification:</font> '.$row["specs"].' </span><br /><br /> <span class="page_accessory"><font style="font-weight:bold">Accessories:</font> '.$row["accessory"].' </span><br /><br /> <span class="page_notes"><font style="font-weight:bold">Notes:</font> '.$row["notes"].' </span><br /><br /> <span class="page_itemcon"><font style="font-weight:bold">Condition:</font> '.$row["itemcon"].' </span> <span class="page_itemcon"><font style="font-weight:bold">Warranty:</font> '.$row["warranty"].' </span><br /><br /> <span class="page_price"><font style="font-weight:bold">Price:</font> '.$row["price"].'</span> <span class="page_price"><font style="font-weight:bold">Stocks:</font> '.$row["stocks"].'</span> <br /><br /> </li>'; echo '<li id="item_">'.' <span class="product-thumb"><img src="uploads/thumbs/'.$row['pic'].'"></span> </li>'; } //Get images from upload_data $sql2="select file_name from upload_data where prod_name='$name'"; $result2=mysql_query($sql2,$mysqli) or die(mysql_error()); while($row2=mysql_fetch_array($result2)) { $name2=$row2['file_name']; ?> <span class="product-thumb"> <?php echo "<img src='../../uploads/thumbs/".$name2."'>"; ?> </span> <?php } //Close connection mysql_close($mysqli); ?> <br /> <button class="close-btn">Close</button> </div> </div> <?php echo '</ul>'; ?> Hi all, I know this is my first post so please go easy I'm still learning PHP. Basically, I keep getting 'SQL Selection error: Unknown database 'localhost' I have tried a basic 'insert' and 'search' and both attempts return this error. search.php below <?php include 'studentfunc.php'; //import the class in this web page ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Retrieving Pet Data</title> </head> <body> <?php $db1 = new dbstudent(); $db1->openDB(); $sql="SELECT * from student"; $result=$db1->getResult($sql); echo "<table border='1'>"; echo "<tr><th>Pet ID</th><th>Name</th><th>Info</th><th>Info</th></tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>{$row['cid']}</td><td>{$row['name']}</td>"; echo "<td>{$row['address']}</td>"; echo"<td><a href='dispownerinfo.php?owner_id={$row['sid']}'>{$row['name']}</a></td>"; echo "</tr>"; } echo "</table>"; $db1->closeDB(); ?> </body> </html> <?php //Save it as db_config.php define('DB_HOST','localhost'); define('DB_NAME','test_work'); define('DB_USER','root'); define('DB_PASSWORD',''); ?> studentfunc.php below Code: [Select] <?php require("db_config.php"); class dbstudent { /* DB connection handle */ private $conn; function insert_student($sid, $name, $address, $postcode, $photo) { $esc_name = mysql_real_escape_string($name, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $esc_photo = mysql_real_escape_string($photo, $this->conn); $sql = "insert into student (sid , name, address, postcode, photo) values ('{$sid}', '{$esc_name}', '{$esc_address}', '{$esc_postcode}', '{$esc_photo}'"; $result = mysql_query($sql, $this->conn); if (!$result) { die("SQL Insertion error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } function openDB() { $this->conn = mysql_connect(localhost, root); if (!$this->conn) { die("SQL Connection error: " . mysql_error()); } $db_selected = mysql_select_db(DB_HOST, $this->conn); if (!$db_selected) { die("SQL Selection error: " . mysql_error()); } } function getResult($sql) { $result = mysql_query($sql, $this->conn); if ($result) { return $result; } else { die("SQL Retrieve Error: " . mysql_error()); } } function update_student($name, $address, $postcode, $photo, $sid) { $esc_name = mysql_real_escape_string($name, $this->conn); $esc_sid = mysql_real_escape_string($sid, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $sql = "update student set name='{$esc_name}' where id={$esc_sid}"; $result = mysql_query($sql, $this->conn); if (!$result) { die("SQL Error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } function closeDB() { mysql_close($this->conn); } } ?> I just dont get it! I am unimaginable grateful for any assistance here. I got a snippet of code from here that will give me the Monday of any submitted date, so if I pass 12/08/10 it'll return 12/06/10 as the Monday, which is correct. I tried to expand it to give me the Tuesday of that week: Code: [Select] function getWeekDays($date) { $offset = ''; if( date('l', strtotime($date)) == 'Monday' ) { $offset = ''; } elseif( date('l', strtotime($date)) == 'Sunday' ) { $offset = 'Tomorrow'; } else { $offset = 'Last Monday'; } $monday = date('m/d/Y', strtotime("$date $offset")); $tuesday = date('m/d/Y', strtotime("+1 day", $monday)); return $tuesday; } I keep getting the UNIX epoch returned for $tuesday...obviously this is just confusing the crap out of me, could someone explain what it is I am doing wrong? Thanks Hello folks! I have a mysql table with questions and another one with multiple choice answers. The common key is QuestionID. Some questions have 2 answers, some 3, and some 4. I can display a list of all questions on my page but I am unable to display the related answers below them. I have been trying since yesterday but I just can't get it right. It seems to be a loop related problem. Could you give me any pointers? Thank you! John Hey Guys/Gals
Benn awhile - so I'm confused on what's happening here. session_start() being called on every page, index.php, registration.php and server.php aswell as login.php. Now when I go too login - if I edit the code to echo the $_SESSION['username'] it works fine - gives me what I expect... I set the $_SESSION['username'] = $username and very next line header('Location: index.php'); this is where the issues is it's loosing the session data and I can't figure out why... so here are the two files if someone can point me in the right direction.. index.php <?php ob_start(); session_start(); if (!isset($_SESSION['username'])) { echo print_r($_SESSION); }else { echo print_r($_SESSION); } ?> <!DOCTYPE html> <html> <head> <title>Home</title> <link rel="stylesheet" type="text/css" href="styles/style.css"> </head> <body> <div class="header"> <h2>Home Page</h2> </div> <div class="content"> <!-- notification message --> <div class="error success" > <h3> <!-- there was error code display here --> </h3> </div> <!-- logged in user information --> </div> </body> </html> server.php <?php ob_start(); session_start(); ini_set('display_errors', '1'); ini_set('html_errors', '1'); error_reporting(E_ALL); //make connection with dba_close $username = ""; $email = ""; $errors = array(); $host = "localhost"; $db_username = ""; $db_password = ""; $db = ""; $conn = mysqli_connect($host,$db_username,$db_password,$db); if (mysqli_connect_errno()) { echo "Connection Failed... please contact support". mysqli_connect_error(); } //login user form details if (isset($_POST['login_user'])) { $username = $_POST['username']; //login for form initiated $user = "SELECT * FROM `users` WHERE `username` = '".$username."'"; $action = mysqli_query($conn,$user); while ($row = mysqli_fetch_assoc($action)) { if (mysqli_num_rows($action) === 1) { $_SESSION['username'] = $username; // echo "<br>"; // echo $_SESSION['username']; <-- this works echo's the username, if I remove header location redirect header('Location: index.php'); exit(); }else { echo "Username not found"; } } } ?>
I have stats log file I want to parse lines from. The lines I want to get a GET /xxxx/xxxx/xxxx/xxxx/xxx HTTP I am trying to get those lines and the regex works to get them but I cant figure out how to process the results I want to print out each match to the browser. Here is the php file I am using and the output it outputs is: Array ( ) Code: [Select] <?php $url = "filex"; $filepointer = fopen($url,"r"); if($filepointer){ while(!feof($filepointer)){ $buffer = fgets($filepointer,4096); $file .= $buffer; } fclose($filepointer); } else { die("Could not open file"); } $regexname = "/^GET(.*)HTTP/i"; preg_match_all('/^GET(.*)HTTP/i',$file,$match); $result = $match[1]; print_r($result) ; ?> Thanks in advance! I finished a template engine, its tiny, needed it for a small project. so with that in mind I am stuck on adding a new section that is not going well. tag: {subgame} this will show the layout of a particular game - works fine yippe! but that is just for one game. so now I am changing it to show more than one, and I cannot use that tag over, due to the way "str_replace" works (changes all in one swoop) so I thought doing it this way 2nd Method: {subgame1} {subgame2} {subgame3} etc... the search is: where field is one of the triggers (in this case SUBGAME) Code: [Select] if (strstr( '{'.$field.'}",$html_str) ) works fine for the first one, but obviously ignores the 2nd method I tried preg_match - but i know i am missing something, because I cannot get it to work. and ideal way would be the fnmatch( as of 5.3 its available for windows now) but only supports up to 260 characters - not good for website So what I am looking for: psuedo code: Code: [Select] if ( '{'.$field.'[optional digits]}' ) { do code here } I know preg_match seems to be the way but cant get it to see the numbers and if it does, it misses the origianl game, or worse crashes. Hi All i hope someone can help about to scream! basically I am trying to do a few things with the statement below; First i want to check if the user id exists in member_categories_position. If it Does i want then to exclude all entries from the second statement where member_id equals all results from the first statement the third statement is the else statement that displays if the member_id is not present in the member_categories position. PROBLEM - the result from the first system loops fine, however when i try and insert into the second statement (!='$memid') is produces no results and has no effect. I think the problem is that $memid is a looped result. How do i get the second statement to say that any member_id that is in member_categories_position will not show in that statement? Code: [Select] $sql2 = "SELECT * FROM member_categories_position a JOIN member_users b ON b.id = a.member_id"; $rs2 = mysql_query($sql2); while ($row = mysql_fetch_array($rs2)){ $memid = "".$row['member_id'].""; } if(mysql_num_rows($rs2) != 0){ $new= "SELECT * FROM member_categories JOIN member_users on member_categories.member_id=member_users.id JOIN member_config on member_categories.member_id=member_config.member_id WHERE member_categories.categories='$category' and member_categories.member_id !='$field' group by member_config.member_id order by RAND() limit 0,42"; $rs = mysql_query($new); while ($row = mysql_fetch_assoc($rs)) { echo "result excluding member ids from the first statement"; } echo "<div class=\"clear\"></div>"; } else{ $new= "SELECT * FROM member_categories JOIN member_users on member_categories.member_id=member_users.id JOIN member_config on member_categories.member_id=member_config.member_id WHERE member_categories.categories='$category' group by member_config.member_id order by RAND() limit 0,42"; $rs = mysql_query($new); while ($row = mysql_fetch_assoc($rs)) { echo "Result with all member ids"; } echo "<div class=\"clear\"></div>"; }} I have a client that has a youtube video on his page that he changes everyday. I have been wrestling with being able to allow him to login to an admin page, that returns a simple form for him to input the new video id from his youtube link which then posts to a txt file. This text file is then included in the html for to supply the correct youtube video. Basically the way it is now the html page has Code: [Select] <iframe class="youtube-player" type="text/html" width="566" height="266" src="http://www.youtube.com/embed/Video Id Here" frameborder="0"> </iframe> Now I have been completely unsuccessful just creating a form that will let him change just the "Video Id" so we have been working on copying and pasting the entire iframe code in the form. My first attempt created backslashes in the txt file where quotes are, I then added stripslashes to fwrite and that posted nothing to my txt file. So I'm not sure if the code I have is worth a spit or if I should restart with some assistance. My main goal (if achievable) is to remove the iframe code from the html page and use a php include to include the text file that has the iframe in it. Then create a page for my client to login to to paste either the video url or just the video id and have this change on the fly. Any help would greatly be appreciated! Its been quite a while since ive done anything PHP related but I decided to help a buddy with a website so he can sell his clothing company products online. I found a simple, pre made shopping cart script that seems to run fine. EXCEPT...the admin login. For some reason I keep getting returned to the same page, with the same error(pass and user didnt match). I know for sure that they do, therefore I am absolutely stumped. I have compared this code with books I have and cant seem to fix it. Can anyone help?? function doLogin() { // if we found an error save the error message in this variable $errorMessage = ''; $userName = $_POST['txtUserName']; $password = $_POST['txtPassword']; // first, make sure the username & password are not empty if ($userName == '') { $errorMessage = 'You must enter your username'; } else if ($password == '') { $errorMessage = 'You must enter the password'; } else { // check the database and see if the username and // password combo do match $sql = "SELECT user_id FROM tbl_user WHERE user_name = '$userName' AND user_password = PASSWORD('$password')"; $result = dbQuery($sql); if (dbNumRows($result) == 1) { $row = dbFetchAssoc($result); $_SESSION['plaincart_user_id'] = $row['user_id']; // log the time when the user last login $sql = "UPDATE tbl_user SET user_last_login = NOW() WHERE user_id = '{$row['user_id']}'"; dbQuery($sql); // now that the user is verified we move on to the next page // if the user had been in the admin pages before we move to // the last page visited if (isset($_SESSION['login_return_url'])) { header('Location: ' . $_SESSION['login_return_url']); exit; } else { header('Location: index.php'); exit; } } else { $errorMessage = 'Wrong username or password'; } } return $errorMessage; } |