anupamsaha
Members-
Posts
251 -
Joined
-
Last visited
Never
Everything posted by anupamsaha
-
Need help sending uploaded files to a subfolder
anupamsaha replied to buddhi225's topic in PHP Coding Help
Try this: move_uploaded_file($paperTMP, $_SEVER['DOCUMENT_ROOT'].'/'.$folder.'/'.$paper); -
Interesting !!! Do you want to create a database to a client's computer by using a PHP script? Need more information w.r.t. the "offline program". Basically, PHP is a server-side script. Never meant to do any "installation" type task in client-side.
-
Try changing if ( $_GET['view'] == process ) to if ( $_GET['view'] == 'process' ) Also, check other scripts linked with this script.
-
Try this <?php if ( $_GET['view'] == process ) { // Gathered Information $Zuser = $_POST['user']; $pass = $_POST['pass']; $cash = $_POST['cash']; $Zquestion = $_POST['question']; $Zanswer = $_POST['answer']; // Lowercase gathered information $user = strtolower($Zuser); $question = strtolower($Zquestion); $answer = strtolower($Zanswer); // Check whether $user exists or not $sql = "SELECT `username` FROM `user` WHERE `username` = '$user'"; $rs = mysql_query($sql) or die(mysql_error()); // If number of rows returned is more than 1, it means username is duplicated if ( mysql_num_rows($rs) > 1 ) { echo "Duplicate username"; } else { mysql_query("INSERT INTO users (username, password, money, current, rank, secretquestion, secretanswer) VALUES('$user', '$pass', '$cash', '0', 'noob', '$question','$answer' ) ") or die(mysql_error()); echo "User Created!"; } } ?>
-
If "id" is an auto incremented field, remove '' from the VALUES in the SQL. Your SQL will look like: mysql_query("INSERT INTO users (username, password, money, current, rank, secretquestion, secretanswer) VALUES('$user', '$pass', '$cash', '0', 'noob', '$question','$answer' ) ") or die(mysql_error()); Does this help?
-
I see the db informations (the private variables) are blank in the class. How are setting those? Directly in the class? If not, create a constructor in the class to set those and then use those in the connect() method. As they are blank in the class, you get "false" from the connect() method. <?php /** * Database.php */ class Database { private $db_host = ''; private $db_user = ''; private $db_pass = ''; private $db_name = ''; public static $con; /** * Magic construct method */ public function __construct($host, $user, $password, $dbname) { $this->$db_host = $host; $this->db_user = $user; $this->db_pass = $password; $this->db_name = $dbname; } public function connect() { if(!$this->con) { $myconn = @mysql_connect($this->db_host,$this->db_user,$this->db_pass); if($myconn) { $seldb = @mysql_select_db($this->db_name,$myconn); if($seldb) { $this->con = true; return true; } else { return false; } } else { return false; } } else { return true; } } public function disconnect() { if($this->con) { if(@mysql_close()) { $this->con = false; return true; } else { return false; } } } } ?> To call this class: <?php /** * dbtest.php */ include('Database.php'); $db = new Database('localhost', 'username', 'password', 'database_name'); var_dump($db->connect()); ?>
-
Before executing the INSERT query in the table, do a check on the existence of the username (SELECT query) supplied through the form and if does not exist, then do the insert, otherwise, show the error message. Does it help?
-
Try do Google with "caching with php".
-
Please post the DB class here.
-
Do this: public static $conn; Does this help?
-
If you have the time to read JQuery, please read it. It will answer your many unanswered questions like this. http://jquery.com/ Cheers!
-
Just for a basic heads up, <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('log_errors', '0'); // Werservice URL $endpoint = "http://www.parcel2go.com/api/Parcel2GoApi.asmx?WSDL"; // Create SOAP Client Object $client = new SoapClient($endpoint); // Get all the methods from the webservice print('<pre>'); print_r($client->__getFunctions()); print('</pre>'); ?> Try reading these URLs: http://www.php.net/soap http://www.herongyang.com/PHP/php_soap.html http://www.phpbuilder.com/manual/en/function.soap-soapclient-construct.php You can always do Google for lot more tutorials. Hope this will help.
-
Hi, The API referred here is a webservice. Try creating a webservice client and call the methods as described in it. Try SOAP extension in PHP. Thanks
-
[SOLVED] PHP Solution to not being able to duplicate usernames in SQL
anupamsaha replied to plznty's topic in PHP Coding Help
Seems that your table already has some data. Please check whether there exists duplicate username already in the table or not. If there is already duplicate username exists, you cannot set UNIQUE for the username column. Same goes for blank values in username column. Remove the duplicate username values and/or blanks from the table or change them to some unique values directly into the table, then it will work. Hope this will help. -
Sorry for the late reply. Please try the following: <?php // MySQL Connection $conn = mysql_connect('localhost', 'username', 'password') or die('Database connection failed'); // Select DB mysql_select_db('dbname') or die('Database selection failed'); // SQL to get list (title and ids) $sql = 'SELECT `id`, `title` FROM `table_name` ORDER BY `title`'; // Run query $rs = mysql_query($sql) or die('Error in SQL: ' . $sql . '<br />Reason: ' . mysql_error()); ?> <html> <head> <title>page title</title> <script type="text/javascript"> <!-- function doPost(intId) { var objForm = document.getElementById('idForm'); objForm.getElementById('articleId').value = intId; objForm.method = 'post'; objForm.action = 'article_details.php'; objForm.post(); } //--> </script> </head> <body> <?php // Create links while ( $row = mysql_fetch_assoc($rs)) { echo '<a href="javascript:void(0);" onClick="doPost(' . $row['id'] . ')">' . $row['title'] . '</a><br />'; } ?> <form id="idForm"> <input type="hidden" id="articleId" name="articleId" value="" /> </form> </body> </html>
-
OK. Here we go... <html> <head> <title>page title</title> <script type="text/javascript"> <!-- function doPost() { var objForm = document.getElementById('idForm'); objForm.getElementById('element1').value = 'some value'; objForm.method = 'post'; objForm.action = 'name_of_the_script_where_data_to_be_posted'; objForm.post(); } //--> </script> </head> <body> <a href="javascript:void(0)" onClick="javascript:doPost()">Some text</a> <form id="idForm"> <input type="hidden" id="element1" name="element1" value="" /> </form> </body> </html> Hope this will help.
-
Syntax of "checkdate()" is bool checkdate ( int $month , int $day , int $year ) So, change the if (checkdate....) statement in your code.
-
Create a form and set hidden elements in it in your page. On the click event of the links, call a javascript function, that will set values to those form hidden elements and call the post() method. Its a pure JavaScript solution. No, PHP required. Hope this will help.
-
Here is the concept in pure PHP. Please try this. commonInclude.php <?php /** * commonInclude.php */ // List of pages $pageArray = array( 'home', 'page1', 'page2', ); function getLink($pageIndex = 0) { global $pageArray; $returnLinks = array(); // Print the starting UL print '<ul>'; // If the pageIndex passed to the function does not exist in $pageArray, take the home as default if ( !isset($pageArray[$pageIndex]) ) { $default = 0; } // Else, default is the pageName passed in this function else { $default = $pageIndex; } // Construct all the LI tags here for($index = 0, $count = sizeof($pageArray); $index < $count; $index++) { if ( $index == $default ) { print '<li class="active">' . $pageArray[$index] . '</li>'; } else { print '<li>' . $pageArray[$index] . '</li>'; } } // Print the closing UL print '</ul>'; } ?> home.php <?php include_once('commonInclude.php'); // The menu section getLink(0); ?> page1.php <?php include_once('commonInclude.php'); // The menu section getLink(1); ?> And so on.... Does it make sense?
-
Please check the "temp" upload location of the file. If it is not an image or a blank, then don't record the image. Does it make sense?
-
Can you please provide some more information here?
-
page has to be load just on a certain time
anupamsaha replied to gwolff2005's topic in PHP Coding Help
Not clear what you need. Still, will date() function help here? -
In the "init()" method, value is set to 10. And, 10 is always greater than 1 (as in the expression). Thats why, its always true. Does it help?
-
Why there are 3 identical name attributes to 3 different form input elements? Agent Name:<input type="text" name="name" value="<?php echo $Agent_name; ?>" /><br /> Address:<input type="text" name="name" value="<?php echo $Address; ?>" /><br /> Postcode:<input type="text" name="name" value="<?php echo $Postcode; ?>" /><br /> Change them and change PHP variables accordingly.
-
How to insert a record onto a mysql table
anupamsaha replied to xx_princess_xx's topic in PHP Coding Help
May be, I was not clear in my previous post. I meant the following: If the insert query is trying to insert 3 as a value in Agent_Id field in "properties" table, then there must exists a value 3 in the Agent_Id field in the "agents" table. Otherwise, the error will occur. Am I clear?