PHP - *warning*: Array_combine(): Both Parameters Should Have An Equal Number Of Elements
Hi, Actually I am working on text annotation tool, for this I have downloaded from github (https://github.com/ag-sc/SANTO), after ran the code I am getting error while uploading file into tool like Warning*: array_combine(): Both parameters should have an equal number of elements in *C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php* on line *141* *Fatal error*: Uncaught mysqli_sql_exception: Column 'Text' cannot be null in C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php:145 Stack trace: #0 C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php(145): mysqli_stmt->execute() #1 C:\xampp\htdocs\SANTO\index2.php(36): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\SANTO\index2.php(54): action_include('importpub.ui') #3 {main} thrown in *C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php* on line *145* Please can anyone please help me how to fix this issue, actually they have given readme file I didn't get the solution. Thank you in advance. Similar TutorialsHello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. Hello all! New here and new to PHP. I have an old script that was built for PHP 5.X and need some help getting it to work with PHP 7.X. According to the PHP manual I need to pass the db connection as the first argument. I do get the display error "SQL Error: Can't select DB" and in the logs show "PHP Warning: mysqli_select_db() expects exactly 2 parameters, 1 given". <?php extract($_REQUEST); $DB_HOST="localhost"; //Host $DB_DATABASE="babyyoda"; //database name $DB_USER="mando"; //database username $DB_PASSWORD="password"; //databse password $ADMIN_EMAIL='admin@example.com'; $TEMPLATES='./templates/'; $URL_BASE='http://example.com/banners/'; $PATH='/var/www/vhosts/example.com/httpdocs/banners/'; $BANNERS_PATH=$PATH.'banners/'; $BANNERS_URL=$URL_BASE.'banners/'; $DB_TABLE_CATEGORIES='ban_categories'; $DB_TABLE_SUBCATEGORIES='ban_subcategories'; $DB_TABLE_SUBCATEGORIES_BANNERS='ban_subcategories_banners'; $DB_TABLE_BANNERS='ban_banners'; $DB_TABLE_USERS='ban_users'; $DB_TABLE_SETTINGS='ban_settings'; $IMAGE_MAGICK_PATH='/usr/bin/'; //$IMAGE_MAGICK_PATH='/usr/local/bin/'; // on some servers it may be like this $TEMPLATE_EXECUTE_PHP=1; // set to 1 to allow use of php inside of templates $CRYPT_SALT='ef&dF%HGRTSvsw35'; $TYPES[1]='Jpeg'; $TYPES[2]='Gif'; $TYPES[3]='Flash'; // dont change flash should be "3" //$LINKED_SCRIPTS['Galleries Manager']='/galleries/admin/'; //$LINKED_SCRIPTS['Flash Manager']='/flash/admin/'; $NATS=0; //$PASS_VARIABLES=array('campaign','program'); define('CONFIG_INCLUDED',1); mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die("SQL ERROR: Can't Connect to DB"); mysqli_select_db($DB_DATABASE) or die("SQL ERROR: Can't select DB"); error_reporting(0); ini_set('session.gc_maxlifetime',3600); ?>
I came up with the below but I don't know where to insert these two statements and what to remove. $link = mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD); mysqli_select_db($link, $DB_DATABASE);
Hi guys, I have coded this, however I have received an error msg, can someone advice me in this? Thank you Warning: mysqli_query() expects at least 2 parameters, 1 given in D:\inetpub\vhosts\abc.com\httpdocs\report.php on line 166 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in D:\inetpub\vhosts\abc.com\httpdocs\report.php on line 167 <?php $sql = mysqli_query("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC"); while($data = mysqli_fetch_array($sql)) { echo '<input name="district" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].' class="required" title="Please check at least 1 location."> <label for="'.$data['district_id'].'">'.$data['district_name'].'</label>'; } ?> Here's what I'm wanting to do: Number = 100 In a for loop take that number, 100, and break it down into 5 random numbers to equal 100. So the for loop would output something like this: 1. 32 2. 5 3. 18 4. 9 5. 36 Total = 100 Everytime the numbers would be different. I hope that explains it Thanks! I can't remember where I found this csv_to_array function but I've used it with no problem until just recently. function csv_to_array($filename, $delimiter=',', $enclosure='"', $escape = '\\') { if(!file_exists($filename) AND !is_readable($filename)) {echo "File does not exist or is not readable."; return false;} $header = null; $values = array(); $data = array(); $lines = file($filename); foreach($lines as $line) { $values = str_getcsv($line, $delimiter, $enclosure, $escape); $values = array_map('trim', $values); if(!$header) {$header = $values; var_dump($header); echo "<br><br>"; var_dump($values); echo "<br><br>"; } else $data[] = array_combine($header, $values); } return $data; } I am now getting the "array_combine(): Both parameters should have an equal number of elements" error but I can't figure out how rows of the same CSV are coming up with different numbers of columns. Several columns have a fair amount of text including commas and I've formatted those columns as TEXT so they get quotes around them and I've taken the CSV, renamed it as a TXT file, and imported it back into Excel and all rows seem to have the correct number of columns. If they didn't it would be obvious as the data in the columns bounce around. I noticed in file that double quotes in the TEXT columns are escaped with another double quote. In the function it says the escape is \ so I did a search and replace "" > \\" but that had no effect. The var_dump section spits out two rows of the array. I went to row 45 in the CSV and see nothing out of the ordinary. array(46) { [0]=> string(6) "PartNo" [1]=> string(7) "Company" [2]=> string(6) "Status" [3]=> string(10) "DateEdited" [4]=> string(8) "Comments" [5]=> string(6) "Photos" [6]=> string(11) "VehicleType" [7]=> string(4) "Make" [8]=> string(5) "Model" [9]=> string(9) "BodyStyle" [10]=> string(9) "Driveline" [11]=> string(10) "LiftHeight" [12]=> string(7) "MaxTire" [13]=> string(9) "YearStart" [14]=> string(7) "YearEnd" [15]=> string(9) "Trademark" [16]=> string(6) "Series" [17]=> string(8) "Category" [18]=> string(11) "SubCategory" [19]=> string(12) "3SubCategory" [20]=> string(18) "AssociatedComments" [21]=> string(8) "Max 2000" [22]=> string(11) "Application" [23]=> string(8) "Max 2000" [24]=> string(11) "Daystar App" [25]=> string(12) "ExtendedDesc" [26]=> string(7) "Max 240" [27]=> string(13) "MarketingDesc" [28]=> string(8) "Max 2000" [29]=> string(16) "FeaturesBenefits" [30]=> string(3) "MAP" [31]=> string(4) "MSRP" [32]=> string(14) "PriceEffective" [33]=> string(11) "DateUpdated" [34]=> string(3) "UPC" [35]=> string(9) "BoxLength" [36]=> string(8) "BoxWidth" [37]=> string(9) "BoxHeight" [38]=> string(9) "BoxWeight" [39]=> string(5) "Color" [40]=> string(7) "Country" [41]=> string(6) "Carded" [42]=> string(9) "ScheduleB" } array(46) { [0]=> string(6) "PartNo" [1]=> string(7) "Company" [2]=> string(6) "Status" [3]=> string(10) "DateEdited" [4]=> string(8) "Comments" [5]=> string(6) "Photos" [6]=> string(11) "VehicleType" [7]=> string(4) "Make" [8]=> string(5) "Model" [9]=> string(9) "BodyStyle" [10]=> string(9) "Driveline" [11]=> string(10) "LiftHeight" [12]=> string(7) "MaxTire" [13]=> string(9) "YearStart" [14]=> string(7) "YearEnd" [15]=> string(9) "Trademark" [16]=> string(6) "Series" [17]=> string(8) "Category" [18]=> string(11) "SubCategory" [19]=> string(12) "3SubCategory" [20]=> string(18) "AssociatedComments" [21]=> string(8) "Max 2000" [22]=> string(11) "Application" [23]=> string(8) "Max 2000" [24]=> string(11) "Daystar App" [25]=> string(12) "ExtendedDesc" [26]=> string(7) "Max 240" [27]=> string(13) "MarketingDesc" [28]=> string(8) "Max 2000" [29]=> string(16) "FeaturesBenefits" [30]=> string(3) "MAP" [31]=> string(4) "MSRP" [32]=> string(14) "PriceEffective" [33]=> string(11) "DateUpdated" [34]=> string(3) "UPC" [35]=> string(9) "BoxLength" [36]=> string(8) "BoxWidth" [37]=> string(9) "BoxHeight" [38]=> string(9) "BoxWeight" [39]=> string(5) "Color" [40]=> string(7) "Country" [41]=> string(6) "Carded" [42]=> string(9) "ScheduleB" } And, the whole thing seems to loop indefinitely. A get hundreds of rows of the array_combine error followed by hundreds of rows of "Trying to access array offset on value of type bool" followed by hundreds of rows of "undefined index". When I replace the CSV I'm working on with the CSV that worked in the past I don't get the array_combine error. The CSVs are similar but with different data. The only difference that I know of being that the NEW file has several columns with soft returns to created spacing between paragraphs. I supposed that could be the problem but I'd think Excel would throw a fit when I try to import that data. I'm at a loss as to how I can figure this out. Any thoughts? Thanks, Mike Hello group. I need some help with my code.
<?php
$a1 = array("line1"=>"1-2-3-10-14","line2"=>"1-2-3-10-34","line3"=>"1-2-7-16-35","line4"=>"1-2-3-17-19","line5"=>"2-5-11-15-32");
$result = array_intersect($a1,$a2); ?> Right now, I can only search and find an exact match of all 5-Numbers. I want to code a PHP form that will take a (5-number string) as input and then compare that string against an array database of (5-number strings) to find all matching number occurrences for each “LINE 1 thru LINE 5”. For instance, if I were to type the 5-number string “1-2-3-10-34” as input. The Output populated results would look like this .. Edited February 21, 2019 by Jayfromsandiego Hi guys I'm kinda stuck..so hopefully you guys can lend me a hand I've got an array containing date elements ("Y-m-d")... I'm trying to output some data into googlecharts..so i need to count how many elements that are in the array with todays date -1 day, todays date-2 days...todays date -3days etc... Up until a set number of days (for example 7 days, 14 days etc).. Any advice on how to go about to achieve this? I am calling CURL and trying to do a POST request with parameters: Code: [Select] $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_USERAGENT, "curl 7.23.1 (x86_64-unknown-linux-gnu)"); curl_setopt($curl, CURLOPT_USERPWD, "username:password"); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_URL, "https://www.mydomain.com/route"); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, "key1=blah1&key2=blah2"); return curl_exec(curl); The problem, inside the request at http://www.mydomain.com/route I am not seeing any POST parameters passed. I.E. Code: [Select] print_r($_POST); Code: [Select] Array ( ) Should have key1=blah1 and key2=blah2. Any ideas? I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? Hi Everyone I am having a few issues with my website. I have developed in on my xampp local host and it works ok but when I upload the files and try to renew a membership using stripe I get the following messages. Warning: session_start(): Cannot start session when headers already sent in /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/inc/settings.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/procedures/payments/charge.php:1) in /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/procedures/payments/charge.php on line 141 I have some includes that appear on every page. This is the bootstrap.php file. This file holds the settings.php which connects to my database and other function files. In this settings page I call the session_start() php function and then connect to my database. I call the bootstrap.php file on every page to there for call the session_start() on every page. I am using sessions alot so is this the right thing to do? I have attached the renew_membership payment page which holds the form. The user fills out the payment page and the form data gets sent to a script called charge.php which uses the stripe objects to make the payment. I then want to do a redirect to the paymentSuccess.php page to output to the user that the payment was made successfully. This is where the issues arrise. I have split the charge file into 3 screen shots so it is more readable. Hope someone can help me. Thanks a lot David
Edited April 26 by Irish_Dave I am running to an issue that I have never delt with before and am not sure if there is even a possible solution: I have two files: fileA and fileB fileA contains a loop that loops 30 times each time its called. in the loop there is a 2second delay $i = 1; do { $i++; sleep(2); if(!isset($_SESSION['user']) { break; } } while($i < 31); if fileB i have a simple destroy session $_SESSION = array(); session_destroy(); I call both files via ajax, and that is where i run into my problem. if I call fileA first, then call fileB through ajax, the code in FileB does not execute until fileA has run its course. Is it possible to get around this? Like set the priority of one over the other? <?php if(isset($_POST['submit'])){ $name = $_POST['name']; } ?> <form method="POST" action="hist1.php"> <br /> <input type="hidden" name="name" value="<?php echo $name ?>" /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question1 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q1"><br /><br /> <label class="items">1st Question :</label> <br /> <center> <textarea class="textareaQ" name="question1" readonly><?php echo $question1; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad1" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad1" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad1" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q2"><label title="Proceed to 2nd Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question2 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q2"><br /><br /> <label class="items">2nd Question :</label> <br /> <center> <textarea class="textareaQ" name="q2" readonly><?php echo $question2; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad2" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad2" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad2" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q1"><label title="Proceed to 1st Question">Back</label></a> | <a class="nxt" href="#q3"><label title="Proceed to 3rd Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question3 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q3"><br /><br /> <label class="items">3rd Question :</label> <br /> <center> <textarea class="textareaQ" name="q3" readonly><?php echo $question3; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad3" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad3" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad3" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q2"><label title="Proceed to 2nd Question">Back</label></a> | <a class="nxt" href="#q4"><label title="Proceed to 4th Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question4 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q4"><br /><br /> <label class="items">4th Question :</label> <br /> <center> <textarea class="textareaQ" name="q4" readonly><?php echo $question4; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad4" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad4" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad4" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q3"><label title="Proceed to 3rd Question">Back</label></a> | <a class="nxt" href="#q5"><label title="Proceed to 5th Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 WHERE question != '$question1' AND question != '$question2' AND question != '$question3' AND question != '$question4' ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question5 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q5"><br /><br /> <label class="items">5th Question :</label> <br /> <center> <textarea class="textareaQ" name="q5" readonly><?php echo $question5; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad5" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad5" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad5" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q4"><label title="Proceed to 4th Question">Back</label></a> | <input type="submit" title="Submit Answers" name="submit" class="submit" value=" Submit " onclick="return confirm('Are you sure you want to submit your answers?\nYou can review your answer by click the Back link')" /> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> </form> Edited by mac_gyver, 09 October 2014 - 10:51 AM. code in code tags please I have some function or method. Is there a better design patter to implement this?
function myFunction($a=null,$b=null,$c=null,$d=null,$e=null,$f=null,$g=null,$h=null) { //Do a bunch of stuff }Maybe the second function? function myNewFunction($data=array()) { $data=array_merge(array('a'=>null,'b'=>null,'c'=>null,'d'=>null,'e'=>null,'f'=>null,'g'=>null,'h'=>null),$array); //Do a bunch of stuff }Please provide decision making factors why you would use one approach over the other. I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> I'm trying to set up my home page so that when the server loads index.php it that loads home.php but all the information for home.php is stored in the database under ID 13. So how can I say at the top of my home page that if if (!isset($_GET['id'])) { $id == 13; } (this doesn't seem to work) so that all my variables are populated with the information for the home page? Thanks. .= I am wondering why sometime it is require to add a dot before the equal in php? Hi: I am working with a little bit of code, but not certain if my syntax is correct. Doesn't seem to be doing what I need it to do: Code: [Select] <?php if (date <= "4/8/2011") echo "Event Details"; else echo "Default Text"; ?> Basically, I want to show "Event Details" if the date is before or on 4/8/2011. If it is after 4/8/2011, I want to show "Default Text" It seems to be doing the opposite. What am I missing? hey gys im trying to build a permissions system based on the users group. Groups can be 1, 2, or 3. Here is the code im using: <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("chat") or die(mysql_error()); $result = mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'") or die(mysql_error()); if($result["group"]==1){ echo 'yes'; } else { echo 'no'; } ?> And here is how my db looks like: The thing is, when Im logged in with the user test and run that script, its saying no as the group im in isnt 1. Why is this happening? Can someone help me fix my code. I introduce if condition when a string is empty as Code: [Select] if (empty($string)) { How I can add the condition for a certain value too. If empty or equal to "word1". So I am tryting to create a script to upload a CSV file into a MySql DB. It has like 10K records into SQL
My Code is copy below ...
I get the following errors.
Line 16 is the $handle
line 18 is the While Statement
Error:
Warning: fopen(): Filename cannot be empty in C:\local\htdocs\ADPStorage\DemandCSV.php on line 16 Warning: fopen()expects parameter 1 to be resource, boolean given in C:\local\htdocs\ADPStorage\DemandCSV.php on line 18 I use my script for another table and it worked like a charm. Less data and less colums do. Bad Code: (good Code sample below. this one) <?php $today = date("m.d.y.h.m.s"); echo $today; $BPTD_fy = '2014'; $BPTD_updatedate = $today; $conn = mysql_connect("Localhost","root","password") or die (mysql_error()); mysql_select_db("ds_storage",$conn); if(isset($_POST['submit'])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); while(($fileop = fgetcsv($handle, 100000, ",")) !==FALSE) { $BPTD_fy = $fileop[0]; $BPTD_Status = $fileop[1]; $BPTD_Classification = $fileop[2]; $BPTD_ProcureCat = $fileop[3]; $BPTD_Product = $fileop[4]; $BPTD_Project = $fileop[5]; $BPTD_DSCategory = $fileop[6]; $BPTD_Calculated = $fileop[7]; $BPTD_CapacityType = $fileop[8]; $BPTD_Amount = $fileop[9]; $BPTD_Jul = $fileop[10]; $BPTD_Aug = $fileop[11]; $BPTD_Sep = $fileop[12]; $BPTD_Oct = $fileop[13]; $BPTD_Nov = $fileop[14]; $BPTD_Dec = $fileop[15]; $BPTD_Jan = $fileop[16]; $BPTD_Feb = $fileop[17]; $BPTD_Mar = $fileop[18]; $BPTD_Apr = $fileop[19]; $BPTD_May = $fileop[20]; $BPTD_Jun = $fileop[21]; $BPTD_Location = $fileop[22]; $BPTD_Env = $fileop[23]; $BPTD_Requester = $fileop[24]; $BPTD_ServiceArea = $fileop[25]; $BPTD_ServiceGroup = $fileop[26]; $BPTD_DepHead = $fileop[27]; $BPTD_Recgroup = $fileop[28]; $BPTD_RecOwner = $fileop[29]; $BPTD_Entrydate = $fileop[30]; $BPTD_updatedate = $fileop[31]; $sql = mysql_query("INSERT INTO inv_bpt_demand (Status, Classification, ProcureCat, Product, Project, DSCategory, Calculated, CapacityType, Amount, Jul, Aug, Sep, Oct, Nov, Dec, Jan, Feb, Mar, Apr, May, Jun, Location, Env, Requester, ServiceArea, ServiceGroup, DepHead, Recgroup, RecOwner, Entrydate, updatedate) VALUES ('$BPTD_Status', '$BPTD_Classification', '$BPTD_ProcureCat', '$BPTD_Product', '$BPTD_Project', '$BPTD_DSCategory', '$BPTD_Calculated', '$BPTD_CapacityType', '$BPTD_Amount', '$BPTD_Jul', '$BPTD_Aug', '$BPTD_Sep', '$BPTD_Oct', '$BPTD_Nov', '$BPTD_Dec', '$BPTD_Jan', '$BPTD_Feb', '$BPTD_Mar', '$BPTD_Apr','$BPTD_May', '$BPTD_Jun','$BPTD_Location', '$BPTD_Env','$BPTD_Requester', '$BPTD_ServiceArea', '$BPTD_ServiceGroup','$BPTD_DepHead', '$BPTD_Recgroup','$BPTD_RecOwner','$BPTD_Entrydate','$BPTD_updatedate')"); if($sql) { echo 'Data Uploaded Successfully'; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>BPT Demand CSV</title> <link rel="stylesheet" type="text/css" href="file:///C|/local/htdocs/style/style.css" /> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> </head> <body> <div id="mainWrapper"> <form method="post" action="https://localhost/Storage/DemandCSV.php" enctype="multipart/form-data"> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--end mainWrapper--> </body> </html>Similar Working code (good) <?php $conn = mysql_connect("Localhost","root","password") or die (mysql_error()); mysql_select_db("ds_storage",$conn); if(isset($_POST['submit'])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); while(($fileop = fgetcsv($handle,1000,",")) !==FALSE) { $PC_Num = $fileop[0]; $PC_Name = $fileop[1]; $PC_BPTNUM = $fileop[2]; $PC_busclass = $fileop[3]; $PC_Note = $fileop[4]; $PC_Acro = $fileop[5]; $PC_type = $fileop[6]; ///echo $fileop[1]; $sql = mysql_query("INSERT INTO inv_names (PC_Num, PC_Name, PC_BPTNUM, PC_busclass, PC_Note, PC_Acro, PC_type) VALUES ('$PC_Num', '$PC_Name', '$PC_BPTNUM', '$PC_busclass', '$PC_Note', '$PC_Acro', '$PC_type')"); if($sql) { echo 'Data Uploaded Successfully'; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Upload CSV</title> <link rel="stylesheet" type="text/css" href="file:///C|/local/htdocs/style/style.css" /> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> </head> <body> <div id="mainWrapper"> <form method="post" action="https://localhost/Storage/Storage_CSV.php" enctype="multipart/form-data"> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--end mainWrapper--> </body> </html>Please help and thx in advance ~J |