Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. So is this not a string but an array? 't':new Date(2014,1-1,3,9,35,38),'a':'3.57289','lat':'12,123','lon':'-12,123','dep':'1,1','s':'1,0','q':'90,02','dL':'4,3','dD':'VSV','dR':'PlaceName'
  2. I think MySQL only recognises floats with a period (1.04) not a comma $sql = "update personen set gehalt = gehalt * 1.04"; You can reformat the decimal place back to a comma with number format
  3. After playing with regex I came up with this $string = "'t':new Date(2014,1-1,3,9,35,38),'a':'3.57289','lat':'12,123','lon':'-12,123','dep':'1,1','s':'1,0','q':'90,02','dL':'4,3','dD':'VSV','dR':'PlaceName'"; // regex for finding keys $keyMatch = "#'(\w+)':#"; // match all keys preg_match_all($keyMatch, $string, $keys); // split string on keys $values = preg_split($keyMatch, $string); $values = array_filter($values); $values = array_map(function($value) { return trim($value, "',"); }, $values); // combine both arrays into key - value pairs $data = array_combine($keys[1], $values); printf('<pre>%s</pre>', print_r($data, true));
  4. You could simplify it with explode $string = "'t':new Date(2014,1-1,3,9,35,38),'a':'3.57289','lat':'12,123','lon':'-12,123','dep':'1,1','s':'1,0','q':'90,02','dL':'4,3','dD':'VSV','dR':'PlaceName'"; // explode on ,' $data = explode(',\'', $string); foreach($data as $key => $value) { // remove current key/value from array unset($data[$key]); // get the key value pair list($key, $value) = explode(':', $value); // trim quotes $key = trim($key, "'"); $value = trim($value, "'"); // assign key/value to array $data[$key] = $value; } printf('<pre>%s</pre>', print_r($data, true));
  5. Barands solution seems fit for the answer to your problem. This is how your code should be <form name="search" method="post" action="find.php"> <table width="900" border="1" class="srch"> <tr class="head"><td>States</td><td>Networks</td><td>Channels</td></tr> <tr><td> <input type="checkbox" value="Delhi" name="state[]">DELHI<br /> <input type="checkbox" value="Chandigarh" name="state[]">Chandigarh<br /> <input type="checkbox" value="Patna" name="state[]">Patna<br /> <input type="checkbox" value="Kolkata" name="state[]">Kolkata<br /> <input type="checkbox" value="Madras" name="state[]">Madras<br /> <input type="checkbox" value="Mumbai" name="state[]">Mumbai<br /></td> <td> </tr> <tr><td colspan="3" align="Right"><input type="submit" name="search" value="Search" /></td></tr> </table> </form> </div><!-- end service--> <div id="media" class="group"> <?php echo "<h2>Search Results:</h2><p>"; if(isset($_POST['search'])) { $state = $_POST['state']; //If they did not enter a search term we give them an error if ($ntwrk == "" AND $chn== "" AND !is_array($state)) { echo "<p>You forgot to enter a search term!!!"; exit; } // Otherwise we connect to our Database $con=mysql_connect('localhost', 'abcd', '1234'); if(!$con){ die('Connection error'. mysql_error()); } mysql_select_db('mapping', $con); foreach ($_POST['state'] as $state) { $statearray[] = mysql_real_escape_string($state); } $states = implode ("','", $statearray); $sql = "SELECT * FROM channel WHERE state IN ('$states')"; //Now we search for our search term, in the field the user specified $result = mysql_query($sql) or die(mysql_error()); //This counts the number or results - and if there wasn't any it gives them a little message explaining that if (mysql_num_rows($result) == 0) { echo "Sorry, but we can not find an entry to match your query...<br><br>"; } else { echo "<table border='1' width='900' class='srchrslt'> <tr class='head'> <td>State</td><td>City</td><td>Network</td><td>Channel</td><td>LCN</td></tr>"; //And we display the results while($row = mysql_fetch_assoc( $result )) { echo "<tr>"; echo "<td>" . $row['State'] . " </td>"; echo "<td>" . $row['City'] . " </td>"; echo "<td>" . $row['Network'] . " </td>"; echo "<td>" . $row['Channel'] . " </td>"; echo "<td>" . $row['LCN'] . " </td>"; echo "</tr>"; } echo "</table>"; } } ?>
  6. Alternately you could initialize $row to 1 for ($row = 1; $row < $count; $row++) { echo $shop[$row]["Title"]." costs ".$shop[$row]["Price"]." and you get ".$shop[$row]["Number"]; echo "<br />"; }
  7. You need to escape the doubled quotes for the HTML echo "<td><a href=\"tracks.php?DiscNo=" . $row["DiscNo"] . "\">Link Text</a></td>"; // with double quoted string escape the double quotes // ^^------ Escape the double quotes -------^^ // Or do echo '<td><a href="tracks.php?DiscNo="' . $row["DiscNo"] . '">Link Text</a></td>'; // with single quoted string you do not need to escape the double quotes.
  8. Regex is not easy to understand at first (I took me a while to start to understand it). The best place I learnt regex was at regular-expressions.info, there they explained the basic patterns through to the more advanced patterns. You can also check out the php manual on the PCRE pattern syntax too.
  9. You have changed the formatting of the option tag (maybe you was thinking it was wrong) it should be like this <option<?php echo $selected; ?>><?php echo $option ?></option> The text in green is PHP code. The brown text is HTML code. There is nothing syntactically wrong with this code.
  10. Oops. yea I left a single quote off <td><select name="owner"> <?php $options = set_and_enum_values($con, 'inventory', 'owner'); foreach($options as $option): $selected = (isset($_POST['owner']) && $_POST['owner'] == $option) ? ' selected="selected"' : ''; // ^ I left this quote off ?> <option<?php echo $selected; ?>><?php echo $option ?></option> <?php endforeach; ?> </select></td>
  11. You do not have matching curly braces somewhere. You need to go through your code and make sure every { (opening brace) has a matching } (closing brace)
  12. Maybe try <td><select name="owner"> <?php $options = set_and_enum_values($con, 'inventory', 'owner'); foreach($options as $option): $selected = (isset($_POST['owner']) && $_POST['owner'] == $option) ? ' selected="selected" : ''; ?> <option<?php echo $selected; ?>><?php echo $option ?></option> <?php endforeach; ?> </select></td>
  13. You need to loop over $fields to generate the <options> <td><select name="owner"> <?php $options = set_and_enum_values($con, 'inventory', 'owner'); foreach($options as $option): ?> <option><?php echo $option ?></option> <?php endforeach; ?> </select></td>
  14. The code to call the function is this (make sure you have not put it in function.inc.php) $fields = set_and_enum_values($mysqli, 'table', 'field'); Replace $mysqli with your mysqli object. Replace table with your table name Replace field with the name of the field you want to get the enum/set values from. Yes, because the mysqli object is being passed by reference
  15. You just need to replace mysql_* with mysqli_ and pass in the mysqli object where needed. The function posted in the first link I have updated to mysqli function set_and_enum_values( &$conn, $table , $field ) { $query = "SHOW COLUMNS FROM `$table` LIKE '$field'"; $result = mysqli_query( $conn, $query ) or die( 'Error getting Enum/Set field ' . mysqli_error() ); $row = mysqli_fetch_row($result); if(stripos($row[1], 'enum') !== false || stripos($row[1], 'set') !== false) { $values = str_ireplace(array('enum(', 'set('), '', trim($row[1], ')')); $values = explode(',', $values); $values = array_map(function($str) { return trim($str, '\'"'); }, $values); } return $values; } $fields = set_and_enum_values($mysqli, 'table', 'field'); printf('<pre>%s</pre>', print_r($fields, true));
  16. You would setup your user dropdown menu like this $result = mysql_query('SELECT ID, student_name FROM students'); echo '<select name="student_id">'; // populate the dropdown with usernames, assigning the ID as their value while($result = mysql_fetch_assoc($result)) { echo '<option value="'.$row['ID'].'>'.$row['student_name'].'</a>'; } echo '</select>';When the form is submitted you'd get the student id from $_POST['student_id'] variable. You'd use this variable in your queries, eg when adding grades $student_id = intval($_POST['student_id']); // the student input $hair_grade = intval($_POST['hair_grade']); // the hair grade input $clothing_grade = intval($_POST['clothing_grade']); // the clothing grade input $education_grade = intval($_POST['education_grade']); // the education grade input mysql_query("INSERT INTO grades SET hair = $hair_grade clothing = $clothing_grade education = $education_grade student_id = $student_id");If you are updating/deleting a students grades you would reference the student id in a WHERE clause. Example query for updating a a students grade mysql_query("UPDATE grades SET hair = $hair_grade clothing = $clothing_grade education = $education_grade WHERE student_id = $student_id");
  17. What do you mean by this? Are you getting a blank screen? If you are then there is a PHP error preventing the page from loading. To see the error either look in your servers error log or enable error_reporting by adding the following two lines at the top of your script ini_set('display_error', 1); error_reporting(E_ALL); Post the error(s) here if you are not sure how to fix them.
  18. You the syntax for the dropdown options is wrong echo "<option value='{$option}' </option>"; the above should be like echo "<option value='{$option}'>$option</option>"; //OR Just use echo "<option>$option</option>";
  19. PCRE (preg_*) functions require delimiters to state the start and end of a regex pattern. function Relink($linkstrip) { $linkstrip = ereg_replace('~_+~', '-', str_replace(array(' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '|', '\\', '\'', '"', '[', ']', '{', '}', ':', ';', '.', ',', '/', '?', '', '<', '>'), '_', trim(ereg_replace('~\s+~', ' ', trim($linkstrip)))));
  20. Your could use preg_replace instead $message_message = $row['message_message']; $message_message = preg_replace("/\[(\d+)\]/", '[<a href=\"http://mywebsite.com/system/page1.php?number=$1">$1</a>]', $message_message);
  21. Ch0cu3r

    mySQL date

    You can change the date in your MySQL queries using the DATE_FORMAT function, eg SELECT DATE_FORMAT(your_date_col, 'Y-M-d') as formatted_date FROM table
  22. Have you checked to make sure that the curl request is actually returning the downloaded file? Also have you asked permission from the site owner that you can download and use their content on your site?
  23. Do you mean the new entry does show up after you insert a record? This is because you get the records from the database first and then insert a new record. What you should do is insert a record first and then get all the records afterwards. <?PHP $connect = mysql_connect("localhost","",""); mysql_select_db("site1",$connect); mysql_query("SET NAMES utf8") or die(mysql_error()); // Insert a new record if(isset($_GET['click'])) { $date = date("Y-m-d"); $mass['ip'] = $_SERVER['REMOTE_ADDR']; $name = mysql_real_escape_string($_POST['name']); $mail = mysql_real_escape_string($_POST['mail']); $txt = mysql_real_escape_string($_POST['txt']); $ins = mysql_query("INSERT INTO guestbook(name,mail,txt) VALUES('$name','$mail','$txt')"); if(!$ins) echo mysql_error(); } ?> <html> <head> <title>Guestbook</title> </head> <body> <form action='bb.php?click' method='post'> name:<input type="text" name="name" /><br /> mail:<input type="text" name="mail" /><br /> comment:<textarea name="txt" rows="7"></textarea><br /> adress <input type='submit' value='ENTER' /> </form> <?php // Get the records from the database $read = mysql_query('SELECT * FROM guestbook ORDER BY date ') or die(mysql_error()) ; while($mass = mysql_fetch_assoc($read)) { echo '<p>' . $mass['name']." " . $mass['mail'] . " " $mass['date']."<br />"; echo $mass['text']."</p>"; echo "<hr width=100% />"; } ?> </body> </html> Note I have used mysql_real_escape_string to protect against SQL injection attacks. Also I would recommend you to start changing your code over other php mysql libraries such as mysqli and pdo as the mysql_* function library is deprecated and could soon be removed.
  24. The official site for wordpress is wordpress.org.
  25. If you dont want to code it youself then you could try third party scripts such as Joomla or Wordpress. They are both very customisable and have many themes and modifications to suite your needs.
×
×
  • 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.