berserk 60 Junior Poster

OK HOLD EVERTHING, i finally see what i have done wrong but the only problem is that i have no idea how to fix it, turns out non of my code is actually wrong, it all worked fine but the issue was that i was already calling the mysql_fetch_array() function in my html table, thats how i was getting the contents of the database to display properly, and i have come to find out that you cannot call this function twice on TECHNICALLY the same page. How in the world do i get around this?

berserk 60 Junior Poster

still nothing :< ive been changing evry little vale i can and so far all i can some up with that is completely conclusive is that for some reason unknown to me, mysql_fetch_array() is returning false and i dont know why.

berserk 60 Junior Poster

there was no error, it returned the same result it always does
here is the file thats exported if there was an error it would have posted in the file. there was none :(

berserk 60 Junior Poster

there is a screen shot of the tablein my program
and a screen shot of the table in phpmyadmin

berserk 60 Junior Poster

my issue has to be in the sql date part when i pass it in, something isnt right or at least thats the only thing i can see as a potential issue

berserk 60 Junior Poster

well you see the weird thing is, if i modify it in any way then i get an error telling me im giving a boolean when a resource is needed :< this is wild cause this is literally my only issue left an di have this whole code ready to be deployed on our linux server at work.

berserk 60 Junior Poster

I figured out the issue, i was posting twice on the same page, not allowed so i fixed it.

berserk 60 Junior Poster

here it is

</head>

    <div class="row-fluid">
        <div class="span12">


            <div class="container">


<br><br>
                            <form method="post">
                        <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">

                            <div class="alert alert-info">

                                <strong><i class="icon-user icon-large"></i>&nbsp;Do Not Call Information From User Submitted Data</strong>

                            </div>
                            <thead>

                                <tr>

                                    <th>Employee Name</th>
                                    <th>First Name</th>
                                    <th>Last Name</th>
                                    <th>Email Address</th>
                                    <th>Customer Address</th>
                                    <th>Phone Number</th>
                                    <th>Date Added</th>
                                    <th>Time Added</th>
                                    <th>Accidental Calls</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php 
                            $query=mysql_query("select * from usernumdata")or die(mysql_error());
                            while($row=mysql_fetch_array($query)){
                            $id=$row['id'];
                            ?>

                                        <tr>

                                         <td><?php echo $row['empname'] ?></td>
                                         <td><?php echo $row['firstname'] ?></td>
                                         <td><?php echo $row['lastname'] ?></td>
                                         <td><?php echo $row['email'] ?></td>
                                         <td><?php echo $row['streetadd'], " ", $row['city'], " ", $row['state'], " ", $row['zip'], " ", $row['prov'] ?></td>
                                         <td><?php echo $row['numb'] ?></td>
                                         <td><?php echo $row['date'] ?></td>
                                         <td><?php echo $row['time'] ?></td>
                                         <td><?php echo $row['called'] ?></td>
                                </tr>

                                  <?php } ?>
                            </tbody>
                        </table>

</form>

sadly it is identical, :/

berserk 60 Junior Poster

the part of the file that writes the date to the table looks like this
$mySqlDate = date('Y-m-d'); and it shows up in the table like this
2014-09-08

berserk 60 Junior Poster

ok i did that but its still not printing anything to csv, is it the date string maybe?

berserk 60 Junior Poster

I have been working on this for some time now and i cant get it to work, idk if im missing something small which im sure is the case, but the strange part is it works on an older installation of apache, so maybe im using code thats no longer supported, whatever the case ive diagnosed that the line while ($row = mysql_fetch_array($result)) is returning false when it should not be, i think it might be in the $sql varibale but im not sure, ive changed it to a simple line but it still returns false, so any assistence would be overwhelmingly appreciated.

<?php

// Database Connection

$host="localhost";
$uname="root";
$pass="";
$database = "numbers"; 

$e = NULL;
$b = NULL;

$con=mysql_connect($host,$uname,$pass); 


// set query

if(isset($_GET['submit']))
{
    $e = $_GET['e'];
    $b = $_GET['b'];
}

//or die("Database Connection Failed");
$selectdb=mysql_select_db($database) or 
die("Database could not be selected");

// Fetch Record from Database

$output = "";

$table = "usernumdata"; // Enter Your Table Name 
$sql = "SELECT * FROM $table WHERE STR_TO_DATE('date','%Y-%m-%d') BETWEEN '".$b."' AND '".$e."'";
$result = mysql_query($sql,$con);
$columns_total = mysql_num_fields($result);


// only print the values from the table that align with search query

    // Get The Field Name

    for ($i = 1; $i < $columns_total; $i++) 
    {
        $heading = mysql_field_name($result, $i);
        $output .= '"'.$heading.'",';
    }
    $output .="\n";


    // Get Records from the table

    while ($row = mysql_fetch_array($result)) 
    {
        for ($i = 1; $i < $columns_total; $i++) {
            $output .='"'.$row["$i"].'",';
        }
        $output .="\n";
    }


// Download the file

$filename = "usernumdataexported.csv";
header('Content-type: application/csv');
header('Content-Disposition: …
berserk 60 Junior Poster

I tried that, putting the three semi Colons at the end of my echo lines but they arent there in my other tables and they work just fine, plus it yielded the same result. I even tried moving some of the html around but NOTHING, its gotta be where it cant access the database, but why cant it? I dont see how this is any different execpt MAYBE where this table is along side another html file for uploading, but that shouldnt make any difference.

berserk 60 Junior Poster

no ive gone over it pretty closely, found nothing missing.

berserk 60 Junior Poster

no, no error messages at all, just no result :/

berserk 60 Junior Poster

I cannot get this table to work even though i hav eit working PERFECTLY in 3 other instances, now what i dont get is it seems to be a connection issue between the database and the form, now that makes some sense to me. What doesnt make sense is when i do the exact solution to connect it to the database, it doesnt work at all. what gives!

<?php mysql_select_db('numbers', mysql_connect('localhost','root',''))or die(mysql_error());?>

<html>
        <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="screen">

        <link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>

<script type="text/javascript" charset="utf-8" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/DT_bootstrap.js"></script>


<form method="post">
<div class="row-fluid">
        <div class="span12">

            <div class="container">
            <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">

            <div class="alert alert-info">

            <center>                  
            <strong><i class="icon-user icon-large"></i>&nbsp;Uploaded Files</strong>
            </center>

            </div>
            <thead>

                <tr>

                  <th>File Name</th>
                  <th>Upload Date</th>
                  <th>Upload Time</th>

                  </tr>
              </thead>
              <tbody>
              <?php 
              $query=mysql_query("select * from upfiles")or die(mysql_error());
              while($row=mysql_fetch_array($query)){
              $id=$row['id'];
              ?>

                    <tr>

                     <td><?php echo $row['filename'] ?></td>
                     <td><?php echo $row['update'] ?></td>
                     <td><?php echo $row['uptime'] ?></td>

                    </tr>

              <?php } ?>
              </tbody>
              </table>
          </div>
      </div>
  </div>
</form>
</html>

here is my table, why isnt it connecting to the database??? why is this different while the others are exactly alike and they work fine?

berserk 60 Junior Poster

you sir have helped me get my answer working right, i see my issue now, i was accessing the files directly while looping through them, they couldnt be accessed because they werent in the same directoy but when i changed it to the temp files it worked like a charm!

TYSM!

berserk 60 Junior Poster

I just cannot figure this issue out, i dont understand how the platform has anything to do with this code working? cause i tested my new code out on windows and out of curiosty i used the exact SAME xampp install to be sure it wasnt that but to my suprise i got the same results, it wont work on linux but it will in windows? why is this, is there something special i have to do in linux to get around this problem?

berserk 60 Junior Poster

okay so i have tinkered and came across something very interesting. and please dont feel bad for a little mistake believe me i have made my fair share of them as well so no big deal at all.

Now for the program, i messed with the fgetcsv() a little and found that it DOES INDEED work but ONLY if the file im trying to upload is IN the same directory as my php file. This is obviously a problem if the computer is pc2454 out of 5000 and they wish to upload it from their pc right there, they wont be able to physically put it in the directory itself. Here is the magic though, you see on windows this isnt a problem and uploads from another pc just fine, has been tested and deployed with over ten different machines and none of which had any issues. So why is it that this doesnt work on linux? This just raises more questions lol but such is the programming lifestyle!

here is my code that is technically working but not quite like id wish it to work.

$file = NULL;

    // Where the file is going to be placed 
    $target_path = "uploaded/";

    /* Add the original filename to our target path.  
Result is "uploads/filename.extension" */

    $file = $file.basename($_FILES['file']['name']);

    $file_handle = fopen($file, "r");

    $count= 1;
    mysql_query("TRUNCATE TABLE numdata") or die("MySQL Error: " . mysql_error()); //Delete the existing rows

    while (($data = fgetcsv($file_handle, 0, ",")) !== FALSE)
    {
        foreach($data as $row)
        {
            if($count …
berserk 60 Junior Poster

OKAY we are making progress and thats wonderful but now im stuck with a new error, now the fgetcsv() is coming back with an error still. Only this time the error has changed from boolean to string, is there another way i need to use it or another function all together? here is what i have so far.

    $file = NULL;

    // Where the file is going to be placed 
    $target_path = "uploaded/";

    /* Add the original filename to our target path.  
Result is "uploads/filename.extension" */

    $file = $file.basename($_FILES['file']['name']);

    $file_handle = file_get_contents($target_path, $file);

    $count= 1;
    mysql_query("TRUNCATE TABLE numdata") or die("MySQL Error: " . mysql_error()); //Delete the existing rows

    while (($data = fgetcsv($file_handle, 0, ",")) !== FALSE)
    {
        foreach($data as $row)
        {
            if($count % 2)
            {
                $complete = $row;
            }
            else{
                $complete .= $row;
                $insertArray[] = $complete;
            }
        $count++;
        $query="INSERT INTO numdata(numb) values($complete)";
        }
        mysql_query($query) or die(mysql_error());
    }

fclose($file_handle);

maybe im using it wrong now since i have changed the method im getting the contents of the file im uploading?

berserk 60 Junior Poster

u see i figured the same thing, i already tried this and nothing happened, i looked further into this and was trying to maybe save the uploaded file somewhere forcefully so make it work but that did nothing, im not sure why this is happeneing, but it might have something to do with the php version, my windows machine is running an older version, where my linux box is running 5.2 was the fopen function changed in some way cause im not finding much on it over the net?? whats up?

berserk 60 Junior Poster

I have this script that will NOT work no matter what i add to it, i have fopen not working and i believe that is the root of all my other errors but i cannot be sure, i originally had 8 errors but 4 of them were simple notices for undefined variables. I want to make my code work cross platform because I feel my program should be freely used on multiple platoforms, be it mac os, windows, or linux (preferably linux), any help would be greatly appreciated. Here are the errors and code below.

errors

Warning: fopen(/uploaded/606.txt): failed to open stream: No such file or directory in /opt/lampp/htdocs/upload/newup.php on line 19

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/upload/newup.php on line 24

Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/upload/newup.php on line 26

Notice: Undefined variable: query in /opt/lampp/htdocs/upload/newup.php on line 39
Query was empty

and here is the code im working with.

<?php
ini_set('session.save_path', '/opt/lampp/htdocs/tmp');;
session_start();
require ('dbconnect.php'); // connect to database

// initial database stuff
    set_time_limit(0);
    ini_set('memory_limit', '1024M');
    $file = NULL;

    // Where the file is going to be placed 
    $target_path = "/uploaded/";

    /* Add the original filename to our target path.  
Result is "uploads/filename.extension" */

    $file = $file.basename($_FILES['file']['name']);

    $file_handle = fopen($target_path.$file, "r");

    $count= 1;
    mysql_query("TRUNCATE TABLE numdata") or die("MySQL Error: " . mysql_error()); //Delete the existing rows

    while (($data = fgetcsv($file_handle, 0, ",")) !== FALSE)
    {
        foreach($data as $row)
        {
            if($count % 2)
            {
                $complete = $row;
            }
            else{
                $complete .= …
berserk 60 Junior Poster

Thanks for all the help and support, idk how id get any of this without you guys :D

berserk 60 Junior Poster

alright i got it all, i figured out that i was assigning values to the form variables twice AND i was posting instead of getting, lol gotta love those tiny errors, i will post fixed code

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add New User</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>

</head>
<body id="main_body" >

    <img id="top" src="top.png" alt="">
    <div id="form_container">
        <br>
        <form id="form_895800" class="appnitro"  method="get" action="form.php">
                    <div class="form_description">
            <center>
            <h2><font size = "4">Add a New Number to the Do Not Call List</font></h2>
            </center>
        </div>                       
            <ul >

                    <li id="li_1" >
        <label class="description" for="empname">Employee Full Name: </label>
        <div>
            <input id="empname" name="empname" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li class="section_break">
            <h3>Opt-Out Information</h3>
            <p></p>
        </li>        <li id="li_4" >
        <label class="description" for="firstname">First Name: </label>
        <div>
            <input id="firstname" name="firstname" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li id="li_5" >
        <label class="description" for="lastname">Last Name: </label>
        <div>
            <input id="lastname" name="lastname" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li id="li_6" >
        <label class="description" for="newnum">Phone Number: </label>
        <div>
            <input id="newnum" name="newnum" class="element text medium" type="text" maxlength="10" value=""/> 
        </div> 
        </li>        <li id="li_7" >
        <label class="description" for="email">Email: </label>
        <div>
            <input id="email" name="email" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li id="li_2" >
        <label class="description" for="element_2">Locale Information </label>


        <div>
            <input id="streetadd" name="streetadd" class="element text medium" value="" type="text">
            <label for="streetadd">Mailing Address</label>
        </div>

        <div class="left">
            <input id="city" name="city" class="element text medium" value="" type="text">
            <label for="city">City</label>
        </div>

        <div class="right">
            <input id="state" name="state" class="element text medium" value="" type="text">
            <label for="state">State / Province / Region</label>
        </div>

        <div class="left">
            <input id="zip" …
berserk 60 Junior Poster

ok thats interesting and i did not know that, so if this is the case then would it be easier to just rename the file to a PHP file and then include the html code in it? Im just getting ideas as to how to approach this cause what i want is the file to process the info from the form that is through html and then take that info and add it to the database with PHP. So can i do this? would it be easier this way? would this look better?

<form id="form_895800" class="appnitro"  method="post" action="form.php">
berserk 60 Junior Poster

thank you for the response, and dont worry about multi repsonse, its all good :)

and as for the html thing, my files may seem like they are seperate but it is the same file just two seperate code snippets. what i would love to do is set this to go back to th eprevious page after the submit button has been clicked, if this is not possible that is fine, i would be ok with making a seperate button that would be only for returning to the previous page.

See what its doing now is just submitting but no info is actually going through, idk why this is cause its worked fine before, maybe im just not seeing a simple issue, idk lol but ive been working on it so long im become sick of looking at it lol.

berserk 60 Junior Poster

i have an issue with this new form im using based roughly on a design template that i found online, it looks great for the purposes that i need it for, but the problem is i cant seem to get the input data from the form to pass to the database with php but i had literally the same exact set up before i simply didnt have a input form formated the way it is now, but how can formating change the fuctionality, any help at all is appreciated.

html form

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add New User</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>

</head>
<body id="main_body" >

    <img id="top" src="top.png" alt="">
    <div id="form_container">
        <br>
        <form id="form_895800" class="appnitro"  method="post" action="form.html">
                    <div class="form_description">
            <center>
            <h2><font size = "4">Add a New Number to the Do Not Call List</font></h2>
            </center>
        </div>                       
            <ul >

                    <li id="li_1" >
        <label class="description" for="empname">Employee Name: </label>
        <div>
            <input id="empname" name="empname" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li class="section_break">
            <h3>Opt-Out Information</h3>
            <p></p>
        </li>        <li id="li_4" >
        <label class="description" for="firstname">First Name: </label>
        <div>
            <input id="firstname" name="firstname" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li id="li_5" >
        <label class="description" for="lastname">Last Name: </label>
        <div>
            <input id="lastname" name="lastname" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li id="li_6" >
        <label class="description" for="newnum">Phone Number: </label>
        <div>
            <input id="newnum" name="newnum" class="element text medium" type="text" maxlength="10" value=""/> 
        </div> 
        </li>        <li id="li_7" >
        <label class="description" for="email">Email: </label>
        <div>
            <input id="email" name="email" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>        <li …
berserk 60 Junior Poster

i figured it out

berserk 60 Junior Poster

also to clerify it always returns a cannot call prompt when it should not, no matter what i punch in there

berserk 60 Junior Poster

i dont underdstand whats wrong with this mainly cause it worked yesterday and now its decided not to work, i changed all that i could think of back to see what caused the issue but nothing, maybe there is a small logic error somewhere and im just not seeing it, idk what it is but im stumped and i just need a second pair of eyes to help me out here. Thanks a bunch

<?php

/*
Instructions
The files for uploading must be in the same folder, this might be different for over the network uploading but is like this for now

There must be 11 databases all with the same parameters and fields with only their names different, names must match the table fields for each query statement
10 for the submission forms and 1 extra for the user number data thats submited
the 1 extra must be named usernumdata

*/

$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));

$k = NULL;

if(isset($_GET['submit']))
{
    $k = $_GET['k'];
}
?>
<html>
<head>
<style>
    nav {
    width: 100%;
    float: left;
    margin: 0 0 1em 0;
    padding: 0;
    background-color: #f2f2f2;
    border-bottom: 1px solid #ccc;  }
ul {
    list-style: none;
    width: 800px;
    margin: 0 auto;
    padding: 0; }
li {
    float: left; }
li a {
    display: block;
    padding: 8px 15px;
    text-decoration: none;
    font-weight: bold;
    color: #069;
    border-right: 1px solid #ccc; }
li:first-child a {
    border-left: 1px solid #ccc; }
li a:hover {
    color: #c00;
    background-color: #fff; }
</style>
<!-- script that will …
berserk 60 Junior Poster

nvm i figured it out, turns out the easiest way to do this is use the word binary when doing the selection of the password and username fields from your table.

example:

$sql="SELECT username, password FROM admin WHERE BINARY username='".$myusername."' AND BINARY password='".$mypassword."'";
berserk 60 Junior Poster

OKAY im on the right track here but no wim getting this error and i dont know why.

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\AppServ\www\admin\index.php on line 15

i put the COLLATE in the login prompt and it seems to be blocking my login but unfortunatly now its blocking any type of login so idk what to do, ive seen others with this same function but it works for them why wont it simply work for me!?

berserk 60 Junior Poster

ok but will this fix my issue, cause i need the passwords to be case sensitive and righ tnow they are not, i want "Admin" to be different from "admin"
do i do a comparison with lower case letters first? sorry but this problem is confusing to me :/

berserk 60 Junior Poster

I cannot get the login to work right, everytime i change anything little thing it stops working all together which is unacceptable. So far i have the login reading from the admin table i created, this is good but the issue is my passwords are not being read as case sensitive even though they are displaying on the table as case sensitive i.e. table password = "Admin" but can login using "admin" my username doesnt matter much so that im not worried about. Also one last note i understand that you should never store passwords as plain text but it doesnt matter in the application im working on so im not worried about it, but this functionaility is crucial and i need it. here is my code:

this is the login.php

<?php

session_start();
$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));


if(isset($_POST['login']))
{
    //get username and password entered by user
    $myusername=mysqli_real_escape_string($con,$_POST['username']);
    $mypassword=mysqli_real_escape_string($con,$_POST['password']);

    $sql="SELECT username, password FROM admin WHERE username='".$myusername."' AND password='".$mypassword."'";
    $check= mysqli_query($con,$sql);
    $row = mysqli_fetch_row($check);
    if($row[0]!="" && $row[1] !="") //compare username and password to ones  found in database
    {

         ## set logged_in to true
        $_SESSION['logged_in']= true;
         ## set username session
        $_SESSION['username'] = $row[0]; 

        header('location: table.php');
        exit();
    }
    else
    {
        $error="Your Login Name or Password is invalid";
        //echo "$error";
        //echo "<META http-equiv=' refresh' ;URL='index.php'>";
    }
}

?>
<html>
<head>
<!-- Basics -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Login</title>
<!-- CSS -->
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<!-- Main HTML -->
<!-- Begin Page Content …
berserk 60 Junior Poster

u my friend... have solved all my issues in like 5 lines... THANK YOU SO MUCH! MUCH LIKE, VERY HELP, MUCH AWESOME!!!

berserk 60 Junior Poster

okay i figured out whats kinda of wrong but i have no idea how to go about fixing it.

this part of my code:

if(isset($_GET['submit']))
{
    $username = $_GET['username'];
    $password = $_GET['password'];
}

is returning false so im not actually using anything from the user, it works on another page i have but wont work here? i dont understand why this is or how i even fix it??

berserk 60 Junior Poster

i think this issue is in that i have split the original functionality of the code into 2 pages instead of haveing it all on one, u see beofre i had the entries and the execution all on one page and it worked perfectly but now i have it set when the user hits the add new user button on the index page it takes them to the page with the new user prompts and i believe that is causing my issue, its executing before the data is even being passed, but how woul di set this up to work? could i use links to move the user to the page where this new code is and THEN execute it then have another link so the user can go back? or is there a simpler way? also i have tried everything and tested everything, the logic is working just fine i just feel there is something up with the execution. Also im not getting any errors thats my real issue.

berserk 60 Junior Poster

I need help adding new users to a table i have made for an admin that can add or delete users from said table freely. What i have so far is an entry that can add date and time but for some reason it doesnt add the username and password. I dont know if its skipping the username and password and simply adding them the second you go to that page but something is wrong and i can figure this out, i have been stuck for days and what makes little sense to me is that i have this same code somewhere else but it woks there, allbeit a little different but its the same concept so then why isnt it working here??

here is the code for the adduser.php

<html>


<form method="post" action="index.php">
<table  width="400" border="0" cellspacing="1" cellpadding="2">


<div style = "margin-bottom: 100px" >
<tr width="200">
<font size="6">
Add a New User with Administrative Privileges
<br>
<br>
</tr>
</font>
</div>


<tr>
<td width="100">Username:</td>
<td>
<input name="username" type="text" id="username">
</td>
</tr>

<tr>
<td style="width:100%;" width="200">Password:</td>
<td>
<input name="password" type="text" id="password">
</td>
</tr>

<tr>
<td>
<input name="new" type="submit" id="new" value="Add User">
</td>
</tr>

</table>
</form>

</html>


<?php include('header.php');

$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));   

//submission code, inserting data into mysql database   

$username = "";
$password = "";
$mySqlDate = date('Y-m-d');
$mySqlTime = date('g:i a');

if(isset($_GET['new']))
{
    $username = $_GET['username'];
    $password = $_GET['password'];
}

//filter out non numeric and special characters
$username = mysqli_real_escape_string($con, $_GET['username']);
$password = mysqli_real_escape_string($con, $_GET['password']);


$check …
berserk 60 Junior Poster

ok here is some more info if it helps, i have a basic setup so its very plain i just need it to work, this is my code so far but i have no idea whats wrong with it:

<html>


<form method="post" action="index.php">
<table  width="400" border="0" cellspacing="1" cellpadding="2">


<div style = "margin-bottom: 100px" >
<tr width="200">
<font size="6">
Add a New User with Administrative Privileges
<br>
<br>
</tr>
</font>
</div>


<tr>
<td width="100">Username:</td>
<td>
<input name="username" type="text" id="username">
</td>
</tr>

<tr>
<td style="width:100%;" width="200">Password:</td>
<td>
<input name="password" type="text" id="password">
</td>
</tr>

<tr>
<td>
<input name="new" type="submit" id="new" value="Add User">
</td>
</tr>

</table>
</form>

</html>


<?php include('header.php');

$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));   

//submission code, inserting data into mysql database   

$username = "";
$password = "";
$mySqlDate = date('Y-m-d');
$mySqlTime = date('g:i a');

if(isset($_GET['new']))
{
    $username = $_GET['username'];
    $password = $_GET['password'];
}

//filter out non numeric and special characters
$username = mysqli_real_escape_string($con, $_GET['username']);
$password = mysqli_real_escape_string($con, $_GET['password']);


$check = mysqli_query($con, "SELECT * FROM admin WHERE username = '".$username."'") or die();
$row = mysqli_fetch_row($check);

if ($row[0] == 0)
{
    $sql="INSERT INTO admin (username, password, date, time) VALUES ('".$username."','".$password."','".$mySqlDate."','".$mySqlTime."')";

    if (!mysqli_query($con,$sql)) 
    {
        die('Error: ' . mysqli_error($con));
    }
        echo "false";
    //$length = "Remember to use lower case letters and do not use spaces";
    //echo "<font size='5' color='blue'>".$length."</font> ";
}
else
{
    echo "true";
}

?>

thats the adduser.php

and this:

<?php 

/*
session_start();
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] == false){
    header('location: index.php');
    exit();
}
*/
include('header.php');
//include('index.php');

?>
<body>

    <div class="row-fluid">
        <div …
berserk 60 Junior Poster

here is something else to add, i have been testing and found that it will actually go ahead and enter the date and time info into the database but not the username and password, it does this without even needing any information entered into the username or password fields, when u hit back it will show a new entry in the table but with no username and password but it will have date and time.. weird...

berserk 60 Junior Poster

OH forgot to note that it will add one entry but will only correctly add the time and date to the table with username and password being blank, then after that it will add nothing unless i delete the one added entry.

berserk 60 Junior Poster

I have this code which ironically WORKS on another page i have but for some reason will not work with my new page even though LITERALLY its the exact same function and should work regardless but with my luck it wont so i need help, maybe i have a small error but i have compared and compared the code time and time again and theres literally no difference from what i can tell.

here is the code:

<?php

$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));   

//submission code, inserting data into mysql database   

$username = NULL;
$password = NULL;
$mySqlDate = date('Y-m-d');
$mySqlTime = date('g:i a');

if(isset($_GET['add']))
{
    $username = $_GET['username'];
    $password = $_GET['password'];
}

//filter out non numeric and special characters
$username = mysqli_real_escape_string($con, $_GET['username']);
$password = mysqli_real_escape_string($con, $_GET['password']);


$check = mysqli_query($con, "SELECT count(*) FROM admin WHERE username = '".$username."'") or die();
$row = mysqli_fetch_row($check);

if ($row[0] == 0)
    {
        $sql="INSERT INTO admin (username, password, date, time) VALUES ('".$username."','".$password."','".$mySqlDate."','".$mySqlTime."')";

        if (!mysqli_query($con,$sql)) 
        {
            die('Error: ' . mysqli_error($con));
        }
        $length = "Remember to use lower case letters and do not use spaces";
    echo "<font size='5' color='blue'>".$length."</font> ";
    }
else
{
    $length = "Remember to use lower case letters and do not use spaces";
    echo "<font size='5' color='blue'>".$length."</font> ";
}

?>

<html>


<form method="post" action="index.php">
<table  width="400" border="0" cellspacing="1" cellpadding="2">


<div style = "margin-bottom: 100px" >
<tr width="200">
<font size="6">
Add a New User with Administrative Privileges
</tr>
</font>
</div>


<tr>
<td width="100">Username:</td>
<td>
<input name="username" type="text" id="username">
</td>
</tr>

<tr>
<td …
berserk 60 Junior Poster

PERFECT! this is EXACTLY what i wanted, gotta love them tiny typos, you sir are a true friend now i can add some more to my program and hopefully have it up and running within the week, tysm!

berserk 60 Junior Poster

yes i still have it and it gives me that error still, and also the changes u made for the form page i had originally and they didnt work, or at least the logic part of testing the row[] was wrong for me and i had to change it to what i have up there so im still stuck :/

berserk 60 Junior Poster

ok im definitly getting somewhere but i cant seem to wrap my mind around this one. I fixed it and now im not getting any errors back BUT when i login it just returns me to the login page and doesnt actually direct me to the form page im trying to get to, then i changed the login.php to form.php and im getting an infinite loop which i didnt think was gonna work but i was just testing. do i have to change something in the index/login.php or do i have something else wrong? I apologize for being such a hassle i just keep taking steps and running into errors but im definitly making progress cause when i typ emy login information in i dont get an invalid prompt and when i try to access the form page it takes me to the login page which is what i want but now i just need to fix this recent issue.

berserk 60 Junior Poster

okay now im getting this error in my code

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\Multi_Delete\header.php:12) in C:\AppServ\www\Multi_Delete\form.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\Multi_Delete\header.php:12) in C:\AppServ\www\Multi_Delete\form.php on line 7

I added the code at the top of my form page like you explained and i inspected the rest of my code and from what i see it should be working but its not, help please lol.

here is the form code:

<?php 
include('header.php'); 
//include('index.php');

session_start();
if (!isset($_SESSION['logged-in']) || $_SESSION['logged-in'] == false){
    header('location: login.php');
    exit();
}

?>
<body>

    <div class="row-fluid">
        <div class="span12">




            <div class="container">
            ......
            ......
            ......
            rest of code.....

this is what the top of my page looks like do i have to also put this check in the login page? and why would it tell me i cannot modify the header?

berserk 60 Junior Poster

to answer zaggas comment i need randomized links because i can get on the page past the login prompt without needing to login because i can bookmark the link, i may have my login page set up incorrectly but im not at all sure how to do that if i do. I am somewhat understanding that i need to set each login up with a session and then direct it to the appropriate page via header, will this hide the link so that a user cannot pass through without entering the correct login information, my program will run via local server and be accessible to only people on that network if that makes any difference, sorry but this is all very new to me so if i sound like im ignorant or lost i apologize.

also thank you zagga for the example code, i very much appreciate that, helps me understand a little easier when i can see what i have to do :D

berserk 60 Junior Poster

i have an issue, my code works wonderfully for the pupose its designed for however for security reasons i need th epages page my login page to have either randomized links or just links that cannot be bookmakred too so that one can bypass the login page. My login page is set up to do a basic query from a table of usernames and passwords and so far thats been great but like i said before i need the page to be random each time. How do i go about doing this? I know only what i have read so far online and thats very little about this subject. Here is my code so far:

<?php

session_start();
$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));
if(isset($_POST['login'])){

$myusername=mysqli_real_escape_string($con,$_POST['username']);
$mypassword=mysqli_real_escape_string($con,$_POST['password']);

$sql="SELECT username, password FROM admin WHERE username='".$myusername."' AND password='".$mypassword."'";
$check= mysqli_query($con,$sql);
$row = mysqli_fetch_row($check);
if($row[0]!="" && $row[1] !=""){

 ## set logged_in to true
$_SESSION['logged_in']= true;
 ## set username session
$_SESSION['username'] = $row[0]; 

header('location: form.php');
exit();
}
else
{
$error="Your Login Name or Password is invalid";
//echo "$error";
//echo "<META http-equiv=' refresh' ;URL='index.php'>";
}
}
?>
<html>
<head>
<!-- Basics -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Login</title>
<!-- CSS -->
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<!-- Main HTML -->
<!-- Begin Page Content -->
<div id="container">
<?php echo ($error ? $error : '' );?>

<form action="index.php" method="post">

<label for="name">Username:</label>
<input type="name" name="username" id="username">
<label for="username">Password:</label>
<p><a href="#">Forgot your password?</a>
<input type="password" name="password" id="password">
<div id="lower">
<input type="checkbox"><label …
berserk 60 Junior Poster

i got it figured out

berserk 60 Junior Poster

is there an example i can use for uploading the file then saving it to a location an dusing it from that location? and also deleteing it for storage purposes

berserk 60 Junior Poster

I cant seem to upload a file in php to my server from just anywhere, it will only upload correctly if the file is in the same folder as my upload script which is a serious problem if i want the user to be able to upload from just anywhere.

here is my full code:

require ('dbconnect.php'); // connect to database

// initial database stuff
    set_time_limit(0);
    ini_set('memory_limit', '1024M');

    $file = $_FILES["file"]["name"];
    $file_handle = fopen($file, "r");

    $count= 1;
    mysql_query("TRUNCATE TABLE numdata") or die("MySQL Error: " . mysql_error()); //Delete the existing rows

    while (($data = fgetcsv($file_handle, 0, ",")) !== FALSE)
    {
        foreach($data as $row)
        {
            if($count % 2)
            {
                $complete = $row;
            }
            else{
                $complete .= $row;
                $insertArray[] = $complete;
            }
        $count++;
        $query="INSERT INTO numdata(numb) values($complete)";
        }
        mysql_query($query) or die(mysql_error());
    }

fclose($file_handle);

how do i change the code to enable uploads from any location, or is there a setting i need to change for my server? Any help is greatly appreciated!

Thanks for your time and wisdom.