PHP - Warning Session Start Line 1
I keep having the same problem when i run my script on the server. the error is
Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/alliapop/public_html/ekloges2010/ekloges2010/eisagogi.php:1) in /home/alliapop/public_html/ekloges2010/ekloges2010/includes/session.php on line 1I know i have to put session start at he very first line and i did but the problem keeps showing up. What else should i check? Similar TutorialsHi 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 having trouble resolving an error. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/s519970/public_html/header.php:27) in /home/s519970/public_html/admin/login.php on line 2 What I can gather is I can't use "header (Location: 'admin.php')" after i've used session_start(). I have tried to replace the header (Location: 'admin.php') with this: echo "<script>document.location.href='admin.php'</script>"; echo "<script>'Content-type: application/octet-stream'</script>"; I've been trying to read up on solutions but haven't been able to get it sorted. If anyone can offer some advice that would be greatly appreciated as im new to php. Code: [Select] <?php session_start(); if(isset($_SESSION['user'])) echo "<script>document.location.href='admin.php'</script>"; echo "<script>'Content-type: application/octet-stream'</script>"; ?> <div id="loginform"> <form action="dologin.php" method="post"> <table> <tr> <td><span>Username:</span></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><span>Password:</span></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="login" value="Login" /></td> </tr> </table> </form> </div> I have tried using require_once('yourpage.php'); before my <head></head> tags in the header document where I've specified the html information but this doesn't seem to work. I've been advised to use ob_start("ob_gzhandler"); but I am not sure how to implement this. Any advice is greatly appreciated! in this page http://maximaart.com/newscp/ i have this problem Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/maximasy/public_html/newscp/index.php:1) in /home/maximasy/public_html/newscp/index.php on line 2 my source code is <?php session_start(); include_once("config.php"); include_once("functions.php"); $errorMessage = ''; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { if ($_POST['txtUserId'] === "$user" && $_POST['txtPassword'] === "$pass") { // the user id and password match, $_SESSION['basic_is_logged_in'] = true; require("main.php"); exit;?> I am trying to create an index page which contains registration and login field the problem that i get is on successful login a warning is displayed session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Eventz.com\index.php:116) in C:\xampp\htdocs\Eventz.com\index.php on line 235 This is the login part of my index.php this tag is inside an html table below the login form I also have a registration form and its php code above the login form Code: [Select] <?php if (isset($_REQUEST['pass'])) { $id=$_POST['id']; $pass=$_POST['pass']; $conn =mysql_connect("localhost","root",""); if (!$conn) { die('Could not connect: ' . mysql_error()); } /* checking connection....success! */ $e=mysql_select_db('test', $conn); if(!$e) { die(''.mysql_error()); } else { echo 'database selected successfully'; } if (isset($_REQUEST['id']) || (isset($_REQUEST['pass']))) { if($_REQUEST['id'] == "" || $_REQUEST['pass']=="") { echo "login fields cannot be empty"; } else { $sql=mysql_query("Select email,password from login where email='$id' AND password='$pass'"); $count=mysql_num_rows($sql); if($count==1) /* $count checks if username and password are in same row */ { session_start(); $_SESSION['id']=$id; echo "</br>Login Successful</br>"; } else { echo "</br>invalid</br>"; echo "please try to login again</br>"; } } } } ?> Any help or suggestion would be appreciated I have issues with a user being logged in and staying logged in, When logging in I create these $_SESSION variables Array ( [usr_login] => username [usr_fname] => first [usr_lname] => last [usr_email] => email [ses_usrid] => 1 [loggdin] => Yes [loginremember] => ) And after login it looks great till I refresh the page or go anywhere else on the site. All variables above are gone. Consequently, this works with no issues on the prod server, just not on my machine. Code I've been playing with since it started, specifically the setting of the cookie. (this code runs before anything else) // ================================================================= // Sesssion start // ================================================================= session_set_cookie_params( 0, "/; SameSite=Strict", ".killgorack.com", true, true ); session_start(); // ================================================================= // Security stuff // ================================================================= header("strict-transport-security: max-age=31536000"); header('X-Frame-Options: sameorigin'); header("X-XSS-Protection: 1; mode=block"); header('X-Content-Type-Options: nosniff'); header("Content-Security-Policy: default-src BLA BLA BLA "); header("Feature-Policy: vibrate 'none'"); header("Referrer-Policy: no-referrer"); header("Access-Control-Allow-Origin: https://www.MYWEBSITE.com/"); header("Expect-CT: max-age=86400, enforce"); header_remove("X-Powered-By"); // ================================================================= Any ideas? Edited May 19, 2019 by KillGorackHi all, I have a session problem on my development site. Whenever I go to my login screen at www.mydomain.com/my/path/index.php, i get the following error messages: Quote Warning: session_start() [function.session-start]: open(/tmp/sess_f89c3850adf5a752b13f5c6b9022d8c4, O_RDWR) failed: Permission denied (13) in /home/account/public_html/shop_lite/admin/index.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/account/public_html/shop_lite/admin/index.php:2) in /home/account/public_html/shop_lite/admin/index.php on line 2 However, when I go to mydomain.com/my/path/index.php, the error messages aren't there. I am very confused. We don't have an SSL (which google suggested it could be) or any whitespace between the opening php tag. I have chmoded the /tmp directory to 777 but to no avail. Any ideas? My opening code is below: Code: [Select] <?php session_start(); require_once("includes/db_connector.php"); include("includes/cms_class.php"); include("includes/login_class.php"); loginForwarder(); $issue = checkLoginIssue(); if (isset($_POST["login"])) { loginUser($_POST["email"], $_POST["password"]); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/my_template.dwt.php" codeOutsideHTMLIsLocked="false" --> Hello there, I am working on a pagination script and have hit a bit of a wall. Here is the script: Code: [Select] <?php include("header.php"); ?> <?php $host = "localhost"; // $user = ""; //username to connect to database $pass = ""; //password to connect to database $db = ""; //the name of the database mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error()); mysql_select_db($db) or die("ERROR DB:".mysql_error()); $max = 25; //amount of articles per page. $p = $_GET['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view the article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM 3dpics WHERE id = '$id'"); while($r = mysql_fetch_array($sql)) { $title = $r['title']; $url = $r['url']; echo "<div align='center'><img src='$url' width='500' height='500'><br />$title<br /><br /><a href='test.php'>Back</a></div>"; } }else{ //view all the articles in rows $sql = mysql_query("SELECT * FROM 3dpics LIMIT ".$limits.",$max") or die(mysql_error()); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM 3dpics"),0); $totalpages = ceil($totalres / $max); echo "<table name='myTable' cellpadding='5' cellspacing='5'>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; } echo "</tr></table></div>"; //close up the table for($i = 1; $i <= $totalpages; $i++){ //this is the pagination link echo "<a href='test.php?p=$i'>$i</a>|"; } } ?> All this does is pull the url's of the images out of the database. But, it all shows up on 1 line across the screen! I tried echoing the rows instead, but then it just shows up as 1 line going horizontal. So i'm trying to figure out a way to get 5 pictures per row. This is the code that displays them on the main page: Code: [Select] echo "<table name='myTable' cellpadding='5' cellspacing='5'>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; } echo "</tr></table></div>"; //close up the table Thanks for all your help!
I'm trying to start a session in a simple php file.
Here's *all* the code:
Here's the URL: hey guys, Im trying to register a session from a login im making and for some reason its not working. here is my code: <?php session_start(); if(isset($_POST['username'])){ $username = $_POST['username']; //name of the text field for usernames $password = $_POST['password']; //likewise here just for the password //connect to the db $user = 'root'; $pswd = ''; $db = 'chat'; $conn = mysql_connect('localhost', $user, $pswd); mysql_select_db($db, $conn); //run the query to search for the username and password the match $query = "SELECT * FROM users WHERE username = '$username' AND password ='$password'"; $result = mysql_query($query) or die("Unable to verify user because : " . mysql_error()); //this is where the actual verification happens if(mysql_num_rows($result) == 1){ //the username and password match //so e set the session to true $_SESSION['username'] = $username; $_SESSION['uID'] = $result['user_id']; //$_SESSION['email'] = $result['email']; //and then move them to the index page or the page to which they need to go header('Location: index.php'); }else{ $err = 'Incorrect username / password.' ; } //then just above your login form or where ever you want the error to be displayed you just put in echo $err; } else ?> Im trying to make it so it also gets the user_id of the user logging in and creates a session for it. It works for the username part, and Im able to echo the username im logged in with, but for some reason it does want to work for the user_id part. This is what doesnt register $_SESSION['uID'] = $result['user_id']; Thanks for the upcoming help. I have several pages on my site using the exact same code at the very top, which works fine except for one page: <?php include_once("../members/dbinfo.php"); The top of dbinfo looks like this: <?php session_start(); And then the connection strings for the database However it is giving me this error on this one page: Quote Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\members\dbinfo.php on line 1 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\members\dbinfo.php on line 1 Now the session does actually start and doesn't prevent anything from working, I just get those messages. I'm at a loss as to why a different page with the exact same code, save for searching the database for a different product version would have this problem. I have had this code in place as well which works fine on other pages but doesn't help my problem at all: if(!isset($_SESSION['OK'])){ session_start(); } OK being a variable I set up during log in. I'm at a loss, is anyone able to help me out with this? I am getting Warning: Division by zero in /rate.php on line 64 <?php function rateinstar($value) { preg_match_all('#([0-9]+)([0.0-9.9]+)|([0-9]+)#',$value,$tek); if($tek[0][1] > 0) { $rate=$tek[0][0]/$tek[0][1]; } else { $rate=0; } preg_match_all('#([0-9]+).([0-9]+)#',round($rate,1),$decm); if($decm[2][0] != "") { $no=($decm[1][0]*2)+1; for($i=1;$i<=10;$i++) { if($i<=$no){ if($i%2!=0) echo '<span class="starin piece1"></span>'; else echo '<span class="starin piece2"></span>'; }else{ if($i%2!=0) echo '<span class="starin piece3"></span>'; else echo '<span class="starin piece4"></span>'; } } }else{ for($i=1;$i<=10;$i++) { if($i<=$rate*2){ if($i%2!=0) echo '<span class="starin piece1"></span>'; else echo '<span class="starin piece2"></span>'; }else{ if($i%2!=0) echo '<span class="starin piece3"></span>'; else echo '<span class="starin piece4"></span>'; } } } } function rateintext($value) { preg_match_all('#([0-9]+)([0.0-9.9]+)|([0-9]+)#',$value,$tek); $rate=$tek[0][0]/$tek[0][1]; preg_match_all('#([0-9]+).([0-9]+)#',round($rate,1),$decm); return round($rate,1); } ?> Hi, I have an old code from 2004 and I would like to update it to use new Session object. That means instead of session_register using the $_SESSION super global variable. The main reason for this change is that wheneve I logged out from the software I get: Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0 Spo I replace my old code: <?php session_name("MySite"); session_start(); reset ($_GET); session_register("ADMIN"); session_register("ADMINNAME"); session_register("MAIL") ; $USERCOOKIE_FOR_TRACKING = array(); //to get all session variables foreach ($_SESSION as $key => $value) { $value=stripslashes(trim($value)); $$key=$value; } ?> with this new code: <?php session_name("MySite"); session_start(); reset ($_GET); $_SESSION['ADMIN']=""; $_SESSION['ADMINNAME']=""; $_SESSION['MAIL']=""; $USERCOOKIE_FOR_TRACKING = array(); //to get all session variables foreach ($_SESSION as $key => $value) { $value=stripslashes(trim($value)); $$key=$value; } ?> BUT now I cannot login to the software any more. looks like I am doing something wrong here. please tell me how do I upgrade my code. Thank you. Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/myritebook/public_html/footer.php on line 13 I am trying to fix the above error. Please Help. code is given below:
<?php
if ($conn) {
try{
catch(Exception $e){ Hi Guys.
Doing an assignment for uni, and stuck on an error. Ill attach some files to show the problem and any help very much appreciated.
Error and the screen it comes on
Code
<?php $select = mysqli_query($con, "SELECT * FROM categories");
while ($row = mysqli_fetch_assoc($select)) { }
function dispsubcategories($parent_id) {
}
function getnumtopics($cat_id, $subcat_id) {
and the structure of the database
Edited March 28, 2020 by Ben555 Hi! So I'm working for someone, and they want me to fix this error in a PHP file.. Here is the code: <?php include_once('config.php'); $online = mysql_query("SELECT * FROM bots WHERE status LIKE 'Online'"); $offline = mysql_query("SELECT * FROM bots WHERE status LIKE 'Offline'"); $dead = mysql_query("SELECT * FROM bots WHERE status LIKE 'Dead'"); $admintrue = mysql_query("SELECT * FROM bots WHERE admin LIKE 'True'"); $adminfalse = mysql_query("SELECT * FROM bots WHERE admin LIKE 'False'"); $windows8 = mysql_query("SELECT * FROM bots WHERE so LIKE '%8%'"); $windows7 = mysql_query("SELECT * FROM bots WHERE so LIKE '%7%'"); $windowsvista = mysql_query("SELECT * FROM bots WHERE so LIKE '%vista%'"); $windowsxp = mysql_query("SELECT * FROM bots WHERE so LIKE '%xp%'"); $unknown = mysql_query("SELECT * FROM bots WHERE so LIKE 'Unknown'"); $totalbots = mysql_num_rows(mysql_query("SELECT * FROM bots")); $onlinecount = 0; $offlinecount = 0; $deadcount = 0; $admintruecount = 0; $adminfalsecount = 0; $windows8count = 0; $windows7count = 0; $windowsvistacount = 0; $windowsxpcount = 0; $unknowncount = 0; while($row = mysql_fetch_array($online)){ $onlinecount++; } while($row = mysql_fetch_array($offline)){ $offlinecount++; } while($row = mysql_fetch_array($dead)){ $deadcount++; } while($row = mysql_fetch_array($admintrue)){ $admintruecount++; } while($row = mysql_fetch_array($adminfalse)){ $adminfalsecount++; } while($row = mysql_fetch_array($windows8)){ $windows8count++; } while($row = mysql_fetch_array($windows7)){ $windows7count++; } while($row = mysql_fetch_array($windowsvista)){ $windowsvistacount++; } while($row = mysql_fetch_array($windowsxp)){ $windowsxpcount++; } while($row = mysql_fetch_array($unknown)){ $unknowncount++; } $statustotal = $onlinecount + $offlinecount + $deadcount; $admintotal = $admintruecount + $adminfalsecount; $sototal = $windows7count + $windowsvistacount + $windowsxpcount + $unknowncount; ?> Can anyone tell me the error here, can how to fix it? <?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 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? 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 |