Jump to content

Valakai

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by Valakai

  1. Ok, thank you for the input. I'll stick to a numeric index array.
  2. Well I'd suggest then to search for tutorials on session_*() functions, storing/retrieving information from a database and handling form inputs.
  3. Well one solution would be to use str_replace like this $text = str_replace('\'', '\'\'', $text) Though I doubt that would be a foolproof solution. -- Gah, need to sleep soon, making too many mistakes.
  4. Whoops thats MySQL.
  5. Wrap your variables with addslashes(), which will escape the quotes and allow MSSQL to store them.
  6. You have to add the code after each mysql_query() or die('Query failed:' . mysql_error()) Example: mysql_query('SELECT * FROM table') or die('Query failed:' . mysql_error())
  7. Well theres no quotes around the value= attributes in the input elements. Can you do an echo() or var_dump() on $tab and $id?
  8. The brace on line 10 is closing ( } ) and not opening ( { ) which is required after an if() Correct code: mysql_connect(localhost,root,""); mysql_select_db(prerentdb) or die( "Unable to select database"); if(!empty($_POST["submit"])) { $apt = $_POST['apt']; $query="SELECT * FROM payments Where apt='$apt'"; $result=mysql_query($query); if(mysql_num_rows($result)) { $sql = "UPDATE payments SET amtpaid = '0', prevbal = '0', tentpay = '0', datepaid = ' ', late = ' ', paidsum = '0' WHERE paidsum = rentdue OR late = 'L'"; mysql_query($sql) or die("Update query failed."); echo "Records have been updated"; } }
  9. Well there's some value (however slight) in them, but if you need/want something more advanced I'd suggest finding some open source software and taking it apart bit by bit.
  10. I'm not sure if you are reading my code right, but to make it a bit simpler: while($row = mysql_fetch_assoc($query)) { $rows[$row['user_name']] = $row; } Would become: $rows['user1'] = array('user_id' => 1, 'user_name' => 'user1'); $rows['user2'] = array('user_id' => 1, 'user_name' => 'user2'); $rows['user3'] = array('user_id' => 1, 'user_name' => 'user2'); There is no overriding indexes, each value is unique and would create an array of the data.
  11. str_replace(' ', '', $text);
  12. From a quick search http://www.phpeasystep.com/phptu/6.html http://www.1337labs.com/2010/12/23/multiple-admin-login-over-mysql-database-table/ http://www.php-mysql-tutorial.com/wikis/php-tutorial/basic-user-authentication.aspx
  13. What is the value of $tab and $id? From the looks of the first error, $tab doesn't have a value and $id would be 11/' and in the second $tab is still empty and $id is a single quote
  14. My bad, mysql_query() doesn't return false on no results.
  15. Can you please post the entire error string? There is no reason why that code would cause an error.
  16. The code you submitted is perfectly fine, the rest of the code you didn't probably contains the error.
  17. $sql = 'SELECT * FROM '.$tab.' WHERE '.$tab.'_id = \''.$id'\''; or $sql = "SELECT * FROM ".$tab." WHERE ".$tab."_id = '".$id."'"; both work.
  18. A MySQL Query is most likely returning false when it finds no results, but you've stored this in $result. You then pass $result into mysql_num_rows(), which expects a MySQL resource, but instead is receiving a boolean.
  19. Sorry, I copied the functions wrong In the first function $sql is just a place holder for whatever SQL I will want to execute. In the second function mysql_fetch_assoc($result) is meant to be mysql_fetch_assoc($query), $query being returned from a mysql_query() These functions would return all the records as the id_column I choose is going to be a unique id like the primary key. As an example if I ran this on a user database $rows = getRows(mysql_query('SELECT user_id, user_name, user_email FROM users'), 'user_id'); would return Array ( 1 => Array('user_id' => 1, 'user_name' => 'example1', 'user_email' => '[email protected]'), 2 => Array('user_id' => 2, 'user_name' => 'example2', 'user_email' => '[email protected]'), 3 => Array('user_id' => 3, 'user_name' => 'example3', 'user_email' => '[email protected]') )
  20. If you want to keep the format Y/m/d, you can use the date() function on the $vip_purchased timestamp.
  21. I would store the vip_purchased as an int(10) and populate it with the time() function at the time of purchase You can then check when 1 month has passed with this code // (time() - $vip_purchased) - Number of seconds since time of purchase // (60*60*24*31) - Number of seconds in 31 days if(((time() - $vip_purchased) > (60*60*24*31)) { // VIP Time Expired }
  22. I'm not quite sure what you want, I think this is it though. echo(implode(',', $tags));
  23. I've been using this code for a long time and realised it's very repetitive, but the id_column I want changes all the time function getRows() { $query = mysql_query($sql); $rows = array(); while($row = mysql_fetch_assoc($query)) { $rows[$row['id_column']] = $row; } return $rows; } So I wrote this function that will automatically create an array with a column I choose if I wish, but I'm not sure if it's very efficient. function getRows($query, $column_id = false) { $rows = array(); while($row = mysql_fetch_assoc($result)) { if($column_id === false) { $rows[] = $row; } else { if(isset($row[$column_id])) { $rows[$row[$column_id]] = $row; } else { $rows[] = $row; } } } return $rows; } I would appreciate some input as to make it better. Thanks.
×
×
  • 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.