Jump to content

arunpatal

Members
  • Posts

    273
  • Joined

  • Last visited

Everything posted by arunpatal

  1. function display_sql_list($table_name){ $display = mysqli_query($this->connect,"SELECT * FROM $table_name") or die (header("location:error1")); while ($result = mysqli_fetch_assoc($display)){ echo $result["name"]; } } Using like this work fine
  2. This is booking_list.php page <?php $mysql = new viks2007(); $design = new design(); echo $mysql->display_sql_list($bookpage_table_name); ?>
  3. function display_sql_list($table_name){ $display = mysqli_query($this->connect,"SELECT * FROM $table_name") or die (header("location:error1")); while ($result = mysqli_fetch_assoc($display)){ $results[] = $result["name"]; } return $results; } The code above returns error Notice: Array to string conversion in pages\booking_list.php on line 5 Array What is wrong?
  4. When i don't use header then javascript runs but after adding header (below javascript) javascript is not working if(isset($_POST["update_cart"])){ foreach($_POST["quantity"] as $pid => $qty): @array_splice($_SESSION["my_cart"][$pid] = $qty); if ($_SESSION["my_cart"][$pid] < 1 ){ unset ($_SESSION["my_cart"][$pid]);} elseif ($_SESSION["my_cart"][$pid] > 10){ $_SESSION["my_cart"][$pid] = 10; echo "<script> alert('quantity cannot be more then 10') </script>"; }; endforeach; header("location:" . $_SERVER["PHP_SELF"]); };
  5. Hi, can i use clean url for diffrent pages RewriteRule .* category.php?key1=%1&key2=%2&key3=%3 [L] AND RewriteRule .* index.php?key1=%1&key2=%2&key3=%3 [L]
  6. Hi, I am trying to create a table via foreach loop $mysqli = ""; $mysqli .= "mysqli_query($new_con,'CREATE TABLE IF NOT EXISTS $main_table("; foreach ($fields as $field_name => $field_value): @$field_type = @$type[$field_name]; $mysqli .= "$field_value $field_type,"."<br>"; endforeach; $mysqli .= "$fields[0] INT AUTO_INCREMENT PRIMARY KEY"; $mysqli .= ")')"; echo $mysqli; But i am getting error Catchable fatal error: Object of class mysqli could not be converted to string in C:\wamp\www\My_Site\install\function.php on line 97 This is 97 line => $mysqli .= "mysqli_query($new_con,'CREATE TABLE IF NOT EXISTS $main_table("; This all code is inside function
  7. Hi, i have an array... i want to use it with if statement.. if (any element of array is empty then) { some code } else { }
  8. hi, I made clean url and facing one problem.... Example: my url look like this http://localhost/Viks/Sim1/Sim2/Sim3/Sim4 Now when i click on same link which is on same page url look like this http://localhost/Viks/Sim1/Sim2/Sim3/Sim1/Sim2/Sim3/Sim4
  9. Sorry that i could not clear what i really want. I want to hide index.php or anything following index.php like index.php?x=value That it shows only domain name like mywebsite.com
  10. I want to do somthing if i have url like domain/index.php or domain/index.php?x=value if ($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] == $_SERVER['SERVER_NAME'] . "/index.php"){ execute some code.. } The code above work fine but when index page changes to index.php?x=value then the code doesn't execute.....
  11. So finally i comeup with this //remove one quantity from item if (isset ($_GET["index"])) { $index = $_GET["index"]; if ($_SESSION["viks_cart_array"][$index]["quantity"] <= 1){ unset ($_SESSION["viks_cart_array"][$index]); } else{ $q = $_SESSION["viks_cart_array"][$index]['quantity']; $_SESSION["viks_cart_array"][$index]['quantity'] = $q - 1; header("location:" . $_SERVER["PHP_SELF"]); } }; Code is working fine but please correct me if it can be better Thanks to all
  12. I got your point.... Your code work but i will change my code to make life easy....
  13. Each subarray contains item id and qty I tried this but no success if (isset ($_GET["remove"])) { $x = $_GET["remove"]; foreach($_SESSION["viks_cart_array"] as $index => $value) { if ($_SESSION["viks_cart_array"][$index]['item_id'] == $x) { if ($_SESSION["viks_cart_array"][$index]['quantity'] == 0) { unset ($_SESSION["viks_cart_array"][$index]); } else { $_SESSION["viks_cart_array"][$index]['quantity'] = $q - 1; } } } };
  14. The array look like this Array ( [0] => Array ( [item_id] => 1 [quantity] => 0 ) [1] => Array ( [item_id] => 2 [quantity] => 1 ) )
  15. Hi, Here am i again with new problem.... //remove one quantity from item if (isset ($_GET["remove"])) { $x = $_GET["remove"]; foreach($_SESSION["viks_cart_array"] as $index => $value) { if ($_SESSION["viks_cart_array"][$index]['item_id'] == $x) { $q = $_SESSION["viks_cart_array"][$index]['quantity']; $_SESSION["viks_cart_array"][$index]['quantity'] = $q - 1; header("location:" . $_SERVER["PHP_SELF"]); break; } } }; I want to remove index when quantity is zero $_GET["remove"] values gets a item_id
  16. above was just a example.... I am using session to store these array. Thanks
  17. Hi, I was googling for updating a multidimensional array and found this.... <?php $test_array = array ( array ('item' => '1', 'qty' => '1'), array ('item' => '2', 'qty' => '1'), array ('item' => '3', 'qty' => '1') ); foreach($test_array as &$value){ if($value['item'] === '2'){ $value['qty'] = 5; break; } } ?> Can anyone explain me that what is &$value When i remove & from of $value then the qty dose not change.....
  18. Yes... That was the problem... Thanks
  19. I am getting error while inserting data... This is the error 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 'VALUES('','aaa','','','','2','2014-02-11')' at line 1 and here is code function add_page(){ global $content; if (isset ($_POST["title"])){ $title = mysql_real_escape_string($_POST["title"]); $heading = mysql_real_escape_string($_POST["heading"]); $content = mysql_real_escape_string($_POST["content"]); $date = date("Y-m-d"); $id = htmlspecialchars($_GET["cat_id"]); $target = "images/"; $target = $target . basename( $_FILES['page_img']['name']); move_uploaded_file($_FILES['page_img']['tmp_name'], $target); //$pic variable is the name of image which can be save into database $pic =($_FILES['page_img']['name']); mysql_query("INSERT INTO $content VALUES('','$title','$heading','$content','$pic','$id','$date')") or die (mysql_error()); $msg = "<style>#msg{display:block;} #form{display:none;}</style>"; $msg .= "<div id='msg'>Page $title has been added</div>"; return $msg; } };
  20. its very easy with the help of str_repeat <?php $val = $_POST["val"]; function x($y){ $ans = str_repeat($y,$y); echo $ans; } x($val); ?> <form method="POST"> <input type="text" name="val"> <input type="submit"> </form>
  21. I want aid ($answers table) value to save into an_id ($questions table)
  22. I created two tables. mysql_query("CREATE TABLE IF NOT EXISTS $answers( aid int UNSIGNED auto_increment primary key, answers varchar(255) NOT NULL )") or die (mysql_error()); mysql_query("CREATE TABLE IF NOT EXISTS $questions( qid int auto_increment primary key, question varchar(455) NOT NULL, an_id int(11) UNSIGNED NOT NULL, FOREIGN KEY (an_id) REFERENCES $answers(aid), added_on date )") or die (mysql_error()); Now i am inserting data via form $question = mysql_real_escape_string($_POST["question"]); $answer = mysql_real_escape_string($_POST["answer"]); $date = date('Y-m-d'); mysql_query("INSERT INTO $answers (answers) VALUES ('$answer')") or die (mysql_error()); mysql_query("INSERT INTO $questions (question,added_on) VALUES ('$question','$date')") or die (mysql_error()); But i am facing this error... Cannot add or update a child row: a foreign key constraint fails (`german_quiz`.`questions`, CONSTRAINT `questions_ibfk_1` FOREIGN KEY (`an_id`) REFERENCES `answers` (`aid`)) Please help
×
×
  • 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.