Jump to content

arjang

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

arjang's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thank you:) it works now
  2. i am trying to pass form variables to MYSQL query but i get this error: Database query failed: 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 'bamo'' AND password=''KosaryBram1'' LIMIT 1' at line 1 here is my code: public static function authenticate($username="", $password=""){ global $database; $username = $database->GetSQLValueString($username, "text"); $password = $database->GetSQLValueString($password, "text"); $sql = "SELECT * FROM users "; $sql .= "WHERE username ='{$username}' "; $sql .= "AND password='{$password}' "; $sql .= "LIMIT 1"; $result_set = self::find_by_sql($sql); $found = $database->fetch_array($result_set); return !empty($found) ? $found : false; }
  3. i had the same problem with persian and english. i changed the character set in persian table to utf8 and added this code in the connection file mysql_set_charset('utf8'); everything woks well
  4. any help please ???
  5. i think there is a problem with get method. the $_GET[english_id] never turns to null so elseif statement never turns to true. for example, if i update an article with id=1 for both tables, only english table is updated. if i update an article from kurdish table with an id that doesnt exist in english table, the else tsatement below equals to true but without any mysql error. i mean only the first part of message is displayed. <?php else{ $message = "Update was not successful" . "<br />"; $message .= mysql_error(); } ?>
  6. the list of articles are on another page with link to update.php using get method. im using POST method in the form. if i click on any of the two table's article list, the form fields get filled with the right table fields from database but when i click on update button, only english table is updated. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td align="right" nowrap="nowrap"> </td> <td><input name="id" type="hidden" id="id" value="<?php echo $row_en_list['id']; ?>" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Title:</td> <td> <input type="text" name="title" value="<?php echo htmlentities($row_en_list['title'], ENT_COMPAT, 'utf-8'); ?>" size="32" /> </td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Author:</td> <td> <input type="text" name="author" value="<?php echo $row_en_list['author']; ?>" size="32" /> </td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right" valign="top">Content:</td> <textarea name="content" cols="50" row="5"><?php echo htmlentities($row_en_list['content'], ENT_COMPAT, 'utf-8'); ?></textarea> </td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input name="update" type="submit" id="update" value="Update article" /></td> </tr> </table> <input type="hidden" name="id" value="<?php echo $row_en_list['id']; ?>" /> </form>
  7. hi i have a database with two tables and i use one form to update both tables depending on GET parameter. if get=kurdish_id then i get fields from kurdish table and vise versa for english table. my code retrieves the right table fields but when i click on Update Article, only english table is updated for both tables. i dnt know where the problem is! i am adding the code so that you can see where the problem is. here is the code: <?php $editFormAction = $_SERVER['PHP_SELF']; $colname_en_list = "-1"; $colname_ku_list = "-1"; if (isset($_GET['kurdish_id'])) { $colname_ku_list = mysql_prep($_GET['kurdish_id']); $colname_en_list = NULL; }elseif (isset($_GET['english_id'])) { $colname_en_list = mysql_prep($_GET['english_id']); $colname_ku_list = NULL; } if(isset($_POST['update'])){ $errors = array(); $required_fields = array('title', 'author', 'content'); foreach($required_fields as $fieldName){ if(!isset($_POST[$fieldName]) || empty($_POST[$fieldName])){ $errors[] = $fieldName; } } $field_length = array('title' =>150); foreach($field_length as $fieldname => $max_length){ if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $max_length){ $errors[] = $fieldname; } } if(empty($errors)){ $id = mysql_prep((int)$_POST['id']); $title = mysql_prep(trim($_POST['title'])); $author = mysql_prep(trim($_POST['author'])); $content= mysql_prep($_POST['content']); $sql = "UPDATE "; if($colname_en_list){ $sql .= "english table "; }elseif($colname_ku_list){ $sql .= "kurdish table "; } $sql .="SET title = '$title', author = '$author', content = '$content' WHERE id = $id"; $result = mysql_query($sql, $connection); if(mysql_affected_rows()==1){ global $message; $message = "The article was successfully updated."; }else{ $message = "Update was not successful" . "<br />"; $message .= mysql_error(); } }else{ $message = "there were ". count($errors) . " errors in the form"; } } $query_en_list ="SELECT * FROM "; if($colname_en_list!=null){ $query_en_list.="english table "; $query_en_list.="WHERE id = $colname_en_list"; } elseif($colname_ku_list!=null){ $query_en_list.="kurdish table"; $query_en_list.="WHERE id = $colname_ku_list"; } $en_list = mysql_query($query_en_list, $connection) or die(mysql_error()); $row_en_list = mysql_fetch_assoc($en_list); $totalrow_en_list_en_list = mysql_num_rows($en_list); ?> MOD EDIT: code tags added
  8. thank you guys for the help:)
  9. Im using: <form id="searchbar" method="post" action="searchresult.php"> <ul> <li><input id="search-key" type="text" name="term" value="Search articles" size="25px"></li> <li><input id="searchsubmit" type="submit" name="submit" value=""></li> </ul> </form> to search the database. i used ur code but it is still the same, no result dsplayed!! this is my first website in php. i appreciate if you explain what the code does so that i learn how to use it.
  10. i used $_SERVER['HTTP_REFERER'] together with js but non is reliable. what if the server doesnt support $_SERVER['HTTP_REFERER'] or the visitor has js turned off? anyone looked at my code? is it good way of returning to previous page? it works fine but need to do some coding for the search result page.
  11. thank you Alfa9, but this code return visitors to external pages too. for example if they came from google, it will return them back to google.
  12. hi all:) it is me again having some problem with php. i hope you guys can help me again. i do appreciate your replies. i have a page which is linked from three different pages. visitors can get to this page via any of these three pages. i want to create a return link which returns visitors to the page they came from. i use the following php code which works fine but i wonder if it is good way of doing it!! or it is safe or not. one more thing, when clicking on the Go back link to searchresult page, returned articles dont exist anymore. you have to enter a key word again. [attachment deleted by admin]
  13. thank you for the code:) it solved my problem:)
  14. thanx alot guys:) i give it a try. hope i get how it works. thanx again for helping:)
  15. i attached the code. this code only inserts data into english_articles. i want to give the option to the user to choose between any of the two table to insert data into. [attachment deleted by admin]
×
×
  • 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.