Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. Move echo $name; so it is after this line chmod(UPLOAD_DIR . $name, 0644); $name is only defined when $_FILES["myFile"] is not empty What is the output of printf('<pre>%s</pre>', print_r($_POST, true)); printf('<pre>%s</pre>', print_r($_FILES, true)); When the form us submitted?
  2. You need to name your form fields using name="fieldname" not id="fieldname"
  3. Can you explain what it is you are trying to do. I do not understand the logic in your code.
  4. I do not see how that helps contributes to solve the OP's question/problem.
  5. If you are allowing users to edit the database records from your form you need to give each field in your form a unique name, currently you are giving all the fields the same name of security_code. I'd setup the form like this <?php require_once("config.php"); $query_for_result=mysql_query("SELECT * FROM mytable ORDER BY id ASC"); $num=mysql_num_rows($query_for_result); ?> <form method="post" action="update.php"> <table> <tr> <td>Sl.No..</td> <td>Item</td> <td>Paper</td> <td>Finish</td> <td>Price</td> <td>Vat</td> <td>Total Amount</td> </tr> <?php while ($row = mysql_fetch_assoc($result)) { $id = $row['id'] ?> <tr> <td><?php echo $id; ?></td> <td><input name="item[<?php echo $id; ?>][album_name]" value="<?php echo $row['album_name'] ?>" type="text" style="width:150px;"/></td> <td><input name="item[<?php echo $id; ?>][paper_used]" value="<?php echo $row['paper_used'] ?>" style="width:85px;"/></td> <td><input name="item[<?php echo $id; ?>][finishing]" value="<?php echo $row['finishing'] ?>" type="text" style="width:90px;"/></td> <td><input name="item[<?php echo $id; ?>][price]" value="<?php echo $row['price'] ?>" type="text" style="width:25px;"/></td> <td><input name="item[<?php echo $id; ?>][vat]" value="<?php echo $row['vat'] ?>" type="text" style="width:35px;"/></td> <td><input name="item[<?php echo $id; ?>][total_amt]" value="<?php echo $row['total_amt'] ?>" type="text" style="width:50px;"/></td> </tr> <?php } ?> </tr> </table> </form> Here the field names are named in this format item[<record id>][<table field name>] When the form is submitted $_POST['item'] will contain a multidimensional array of records to be updated in the database. In update.php the code for updating the records will be like <?php require_once("config.php"); // the data tpes of each field $data_type = array( 'album_name' => 'string', 'paper_used' => 'string', 'finishing' => 'string', 'price' => 'float', 'vat' => 'float', 'total_amt' => 'float', ); if(isset($_POST['submit'])) { if(is_array($_POST['item'])) { // loop over the items in the field foreach($_POST['item'] as $record_id as $fields) { // dynamically create the update query for updating the record $query = 'UPDATE mytable SET '; // loop over the fields foreach($fields as $field_name => $field_value) { // sanitize the field value based on field data type switch($data_type[$field_name]) { case 'float': $field_value = floatval($field_value); break; case 'string': default: $field_value = mysql_real_escape_string($field_value); } $query .= "$field_name = '$field_value' "; } // which record is being updated $query .= 'WHERE id=' . intval($record_id); // update the record $result = mysql_query($query); if($result && mysql_affected_rows()) { echo "Record #$record_id has been updated!<br />"; } } } } ?>
  6. Apply the QSA (Query String Append) flag on your rewrite rule RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L,QSA]
  7. You are getting that error because VARCHAR datatypes requires you to define the maximum number of characters that can be stored for each field.
  8. This code here for checking the password has a few major problems $check_passwd == md5($passwd . $salt); for($round = 0; $round < 65536; $round++) f($check_passwd = md5($salt['passwd'])) { $login_ok = true; } 1) First $passwd and $salt are not defined, When assigning a value to a variable you use thr assignment operator = not the comparison operator == 2) Why the for loop? 3) md5($salt['passwd']) should be $row['passwd'] The is the variable that holds the users hashed password stored in your database, which is returned by your query . And you should use the comparison operator ( == ) when checking values match
  9. The problem is here $fw = fopen("problem4.txt", "w"); Mode w will overwrite what was previously written to that file. The mode you'll want use would be a, so it'll append to what is currently written to that file. I'd do not recommend using fopen whilst within the while loop. Instead I'd open file just before it $fw = fopen("problem4.txt", "a"); // open problem4.txt and append to what is currently written to it. while(!feof($fp)){
  10. You need to calculate how many days are leftover. Change for($i=0; $i<($this->maxday+$this->startday); $i++){ to $totalDays = $this->maxday+$this->startday; // total days to iterate over $leftOverDays = ceil($totalDays / 7) * 7 - $totalDays; // days left to iterate over for($i=0; $i< $totalDays; $i++) Next change $output .= '</table>'; to // add empty table cells to complete calendar if($leftOverDays > 0) { $output .= str_repeat('<td></td>', $leftOverDays); $output .= '</tr>'; } $output .= '</table>';
  11. Change if($_POST['Submit']!=''){ to if(isset($_POST['Submit'])){ The problem is PHP will report an undefined index if you use an key to an array that doesnt exist. The Submit index wont exist if you have not submitted the form. Once the form is submitted the notice will disappear because now the index is defined. Using isset on $_POST['Submit'] will eliminate the notice if the form has not been submitted.
  12. You need to move these conditions if($cali == $this->today && $this->currentmonth == $this->cMonth && $this->currentyear == $this->cYear){ $ev = ''; $ev .= "<td align='center' bgcolor='red' title='Today'>$cali</td>"; }elseif($i <$this->startday){ $ev = ''; $ev .= "<td> </td>"; }else{ $ev = ''; $ev .= "<td align='center' bgcolor='white'>$cali</td>"; } outside of the foreach loop so it is $date = $this->cYear."-".$this->cMonth."-".$cali; $ev = ''; foreach($this->events as $event){ if($event['start'] <= $date && $event['end'] >= $date){ $ev = "<td align='center' bgcolor='#00FF00' title='".$event['description']."'>$cali</td>"; } } if(empty($ev)) { if($cali == $this->today && $this->currentmonth == $this->cMonth && $this->currentyear == $this->cYear){ $ev = "<td align='center' bgcolor='red' title='Today'>$cali</td>"; }elseif($i <$this->startday){ $ev = "<td> </td>"; }else{ $ev = "<td align='center' bgcolor='white'>$cali</td>"; } } $output .= $ev;
  13. What do you mean by one input? Jairathnem code will filter out any duplicated numbers in the comma delimited list. Which is what your original question was
  14. $_POST data is not remembered during multiple page requests. The post data will only exist when the form is submitted. When you click one of the pagination links, the post data will not exits and so the login form appears. The next page will only display when you filll the login form again. What you should do set a login token in the $_SESSION when you authenticate the user. Then when you go to display the paginated results, check to make sure the login token exists to verify the user is authenticated. if no login token then display the login form. This is how your code should be structured <?php // create a session, so the $_SESSION vars are remembered session_start(); // do the login, when login form is submitted if(isset($_POST['submit'])) { $user=$_POST['user']; $pass=$_POST['pass']; if($user=="jishil" && $pass=="1234") { // set sessions vars when user is authenticated $_SESSION['loggedIn'] = true; // set the loggedIn token to true $_SESSION['username'] = $user; // the users username } } // only display the login form if the user is not authenticated (loggedIn token is not true) if(!isset($_SESSION['loggedIn']) || $_SESSION['loggedIn'] !== true) { // display login form } else { // // user is authenticated display the paginated result } ?>
  15. Change $engineerList .= '<option value>'. to $engineerList .= '<option>'.
  16. $sql = 'SELECT keywords,title,description FROM meta_tags where id=$page_id'; Variables are not expanded in single quotes. Change id=$page_id'; to id='.$page_id;
  17. Umm, the link I gave is not linking correctly try http://jsfiddle.net/7r6pX/1/ EDIT: Screw that, I made a new one try http://jsfiddle.net/hLKK6/
  18. That error usually means the query has failed, due to an error. Is that all your code? Are you connected to mysql? Use mysql_error to see what the error could be. $result=mysql_query($query) or trigger_error('DB error: ' . mysql_error());
  19. Easiest way is using glob Example foreach(glob('Gallery/thumbnails/*') as $file) { echo $file; } If you want to filter the images, by file extension use this instead glob('Gallery/thumbnails/*.{gif,jpg,png,bmp}', GLOB_BRACE)
  20. Currently you have set no width so it'll only consume the space it needs to fit the text. When you mouseover the text it becomes bold, which requires more space and so the text shifts slightly to the right. To prevent this you need to define a width. Also rather than hard-coding a pipe character to separate each item in menu, use borders instead Working example http://jsfiddle.net/7r6pX/1/
  21. In that case topic locked. Post all replies in the other topic please.
  22. You appear to be creating individual php files for each post. This I do not recommend You should be storing the posts in some sort of database. You'd then use PHP to retrieve the contents of the post from the database. Like this tutorial shows http://www.daveismyname.com/creating-a-blog-from-scratch-with-php-bp
  23. Can you post your code here. It sounds to me you are not including the engineer list within your form.
  24. As I said to submit the form to itself. Rather than change the form action, you could keep it set to php self. But Once you have validated/verified the users data to your requirements you can just include insert.php instead. example pseudo code <?php if(isset($_POST['submit'])) { /* validates users data */ if(/* users data validates */) { include 'insert.php'; } } ?> /* display form/validation errors */
  25. No, just alter the regex to only capture the value of v= not the whole of the youtube url if(preg_match_all("/http\:\/\/www\.youtube\.com\/watch\?v=(\w{11})/", $result, $links)) { foreach($links[1] as $link) { echo "http://youtube.com/embed/$link<br />"; } }
×
×
  • 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.