berserk 60 Junior Poster

thank you very much i appreciate the help and assistence

berserk 60 Junior Poster

ok i got it working but im sure its one big security risk lol, i changed the verified header to the form header and it worked, this is basically what i needed.

berserk 60 Junior Poster

THIS WORKED FINALLY!!

however i can tseem to get it to go to the right page after the evaluation has passed.

here is my current code but it doesnt work.

<html>
<body>
<!-- End Page Content -->
<?php
$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));
if(isset($_POST['login']))
{
//$myusername = $_GET['name'];
//$mypassword = $_GET['password'];
$myusername=mysqli_real_escape_string($con,$_POST['username']);
$mypassword=mysqli_real_escape_string($con,$_POST['password']);
//$sql="SELECT * FROM admin WHERE username='".$myusername."' AND password='".$mypassword."'";
$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] !="")
{
//echo "Successful Login";
//echo "<META http-equiv=' refresh' ;URL='form.php'>";
    //echo 'Successful Login<br/>';
    //echo "<META http-equiv=' refresh' ;URL='form.php'>";
    header('location: form.php');
    exit();
}
else
{
 $error="Your Login Name or Password is invalid";
echo "$error";
//echo "<META http-equiv=' refresh' ;URL='index.php'>";
}
}
?>
<form action="index.php" method="post">
<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>
<!-- Main HTML -->
<!-- Begin Page Content -->
<div id="container">
<form>
<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 class="check" for="checkbox">Keep me logged in</label>
<input type="submit" value="Login" name="login" id="login">
</div>
</form>
</div>
</body>
</form>
</html>

I have used header which didnt work and throws an error about being unable to change the header information, i have also tried the meta tag and that did nothing either so im kinda at a lose on how to redirect the user to the desired form page. are there any other ways …

berserk 60 Junior Poster

I changed those but it still logs in automatically without verifiying if the login information is correct. What gives?

here is the newly modified code.

<html>
<body>   

    <!-- End Page Content -->

<?php

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


if(isset($_POST['login']))
{
    $myusername = $_GET['name'];
    $mypassword = $_GET['password'];

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

    //$sql="SELECT * FROM admin WHERE username='".$myusername."' AND password='".$mypassword."'";

    $sql="SELECT username FROM admin WHERE username='".$myusername."' AND password='".$mypassword."'";
    $check=  mysqli_query($con,$sql);

    $row = mysqli_fetch_row($check);


    if($row[0]!="")
    {
        //echo "Successful Login";
        echo "<META http-equiv=' refresh' ;URL='form.php'>";

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

    }
}


?>

<form action="form.php" method="post">
<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>
    <!-- Main HTML -->   
    <!-- Begin Page Content -->  
    <div id="container">     
        <form>       
        <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 class="check" for="checkbox">Keep me logged in</label>       
        <input type="submit" value="Login" name="login" id="login">
        </div>       
        </form>
    </div>


</body>
</form>
</html>
berserk 60 Junior Poster

okay so i have narrowed my code down some more and have rid myself of many errors but im still not getting the desired result.

here is my code now.

<html>
<body>   

    <!-- End Page Content -->

<?php

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


if(isset($_POST['login']))
{
    $myusername = $_GET['name'];
    $mypassword = $_GET['password'];

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

    $sql="SELECT * FROM admin WHERE username='".$myusername."' AND password='".$mypassword."'";
    $check=  mysqli_query($con,$sql);

    $row = mysqli_fetch_row($check);


    if($row[0] == 0)
    {
        //echo "Successful Login";
        echo "<META http-equiv=' refresh' ;URL='form.php'>";

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

    }
}


?>

<form action="form.php" method="post">
<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>
    <!-- Main HTML -->   
    <!-- Begin Page Content -->  
    <div id="container">     
        <form>       
        <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 class="check" for="checkbox">Keep me logged in</label>       
        <input type="submit" value="Login" name="login" id="login">
        </div>       
        </form>
    </div>


</body>
</form>
</html>

it still doesnt check the username and password values and just logs in anyway, what is WRONG with my code lol

berserk 60 Junior Poster

I cant seem to get this login form to work right I have the login form come up and i can use it to get to the form.php page that i try to access but my problem is that its not verifying any login information, it just goes on through to the form page regardless. Let me give some more detail to clerify some things, im running this program over a local network so i dont need anything encrypted and also my login form is based entirely on an admin changable user name and password in phpmyadmin, my boss will have access to this page and be able to change the username and password to what he sees fit all i need to do is make sure that it reads the username and password from the database and checks to see if the entered ones are the same, if so then go to the form. here is the code i have, im sure its wrong but what i dotn understand is i have a similar function in another project that work exactly like it should with code set up like what i have here, also im getting this error that im sending the header before this is executed and it cant change the header again, which is weird cause i have commented out all the echos and so it shouldnt be giving me this error. Help please.

<html>

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

<head>
    <!-- Basics -->  
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> …
berserk 60 Junior Poster

Ok i know this question might be riddled with ignorance but please bare with me. How to i go about deploying my php application i have developed, do i make it into an executable that can be installed on user machines, or do i just set it up like a website and host it via server, im a little confused because i have read that you can do both depending on the application you have and what it does. Mine is simple, its just a search engine that will allow you to search a database that is uploaded by the admin and is searchable to the users, there is also some other pages that are used that do other functionaility like making the data in the database deletable and i even added a login page for that page, but do i load all this into an executable file? i wouldnt think i would have to since its web based and is all handled by a server. Then again i could be literally so off that its laughable, regardless any assistence on this subject would be greatly appreciated and will be documented for later use. Thank you for your time.

berserk 60 Junior Poster

Thank you so much urtrivedi, this is exactly what i needed. I bow to your wisdom cause i still dont fully understand but i am reading more into it as well as something on creating a login page so i will go from there. Thanks again for all the help you gave me. it was very much appreciated

berserk 60 Junior Poster

that looks like it could work but my question is how would you use the if statement to run a check and give feedback to the user to let them know whther or not the number is there, also can you give an example cause this looks a little complicated, sorry im kind of new to the whole php/html/mysql thing so simple explanations are appreciated, thanks.

berserk 60 Junior Poster

hey i have this code that always evaluates to true but it should only in the case of there being a value in the database i have selected, maybe im doing this wrong or maybe its something else but i cant seem to figure out the problem :( any assistence is greatly appreciated.

//submission code, inserting data into mysql database

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

if(isset($_GET['add']))
{
    $newnum = $_GET['newnum'];
    $firstname = $_GET['firstname'];
    $lastname = $_GET['lastname'];
}

if(strlen($newnum) == $min_length)
{
    $newnum = mysqli_real_escape_string($con, $_GET['newnum']);
    $firstname = mysqli_real_escape_string($con, $_GET['firstname']);
    $lastname = mysqli_real_escape_string($con, $_GET['lastname']);

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

    if ($row[0] > 0)
    {
        $sql="INSERT INTO usernumdata (numb) VALUES ('".$newnum."')";

        if (!mysqli_query($con,$sql)) {
            die('Error: ' . mysqli_error($con));
        }   
        echo "<div style='text-align: center'> <font size='6' color='green'>Successfully Added New Number</font> <div>";
    }
    else
    {
        echo "<div style='text-align: center'> <font size='6' color='red'>Number Already Exists In Do Not Call List</font> <div>";
    }
    /*
    $sql="INSERT INTO usernumdata (numb, firstname, lastname, date, time) VALUES ('".$newnum."','".$firstname."','".$lastname."','".$mySqlDate."','".$mySqlTime."')";

    if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }
    echo "<div style='position:fixed; bottom:65; left:37%'> <font size='6' color='green'>Successfully Added New Entry</font> <div>";
    */
}

else{
    $length = "Remember Phone Number Must be ".$min_length. " Digits Long";
    echo "<div style='position:fixed; bottom:50; left:31%;'> <font size='6' color='blue'>".$length."</font> <div>";
}

as you can see from the code above im trying to set it up to do a double test which is probably bad coding pratice but i needs to output different messages in case …

berserk 60 Junior Poster

nvm i got all that i needed :D thank you all for all this help cause i could not have done it without u

berserk 60 Junior Poster

There is something more i need help with lol, i need to know how i can print data from the table based on a double search query, like from _______ to _______ print this to a csv file, i have the printing figured out but im not sure how to use the double query? here is what i have so far.

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"); 
$result=mysql_select_db($database)
or die("database cannot be selected <br>");

// Fetch Record from Database

$output = "";
$table = "usernumdata"; // Enter Your Table Name 
$sql = mysql_query("SELECT * FROM $table WHERE date= '".$e."'");
$columns_total = mysql_num_fields($sql);

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


if($results = mysql_fetch_array($sql))
{
    // Get The Field Name

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

    // Get Records from the table

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


// Download the file

$filename = "usernumdataexported.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);

im pretty sure all information needed is there so if anything else is needed please let me know.

berserk 60 Junior Poster

I agree, i read the apache license and it plainly states that as long as you do not try to come after them with lawsuits and that u do not hold them responsible then u can use he code freely in free or personally derived products. Also thank you for the help, i still needed to sue this code because i needed to print basic tables that could be modified and thats what i have accomplished.

for the record the sites licensure is here and there codes are as well, for any people who come across this post.

http://www.apache.org/licenses/LICENSE-2.0

http://getbootstrap.com/2.3.2/#transitions

Thanks so much and happy coding!

berserk 60 Junior Poster

i changed it but it did nothing, its strange cause i found another solution to my problem somewhere that i literally pulled the whole project file and it worked marvoulously, but what confuses me is that its the exact same set up we have here but without the admin rights, literally the only difference is the delete portion of this setup is its own file. heres the link to the file, i hope its ok to use this cause id rather not steal anyones work if i can help it.

http://www.sourcecodester.com/php/5270/delete-multiple-rows-checkbox-mysql.html

Please inform me if its illegal to use this code because ill be using this in a professional workplace environment :/

also i chose to use this because the table that red data is beautiful and looks gorgous with mutiple functions built right in making it extremely useful

berserk 60 Junior Poster

I fixed my code but im still not getting any results :( Its not doing anything and unfortunatly the line:

header('Refresh: 3; url=table.php');exit; //3 second delay before refresh

gave me this error:

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\newsearch\table.php:9) in C:\AppServ\www\newsearch\table.php on line 56

not sure at all what to do :(

berserk 60 Junior Poster

Well so far i have my table the way i like which is wonderful but now my delete portion o fmy code isnt working, and im sure i have made a programming logic mistake so bear with me

here is my code, i know its wrong but keep in mind im still pretty new to php so please go easy on me lol

$delete = (array) $_POST['delete'];

if($delete){
    for($i=0;$i<$count;$i++){
    $del_id = $checkbox[$i];
    $arrayList = implode(',', $cleanArray);
    $sql = "DELETE FROM usernumdata WHERE $del_id IN ($arrayList)";
    $result = mysqli_query($con, $sql);
    }
    if($result){
    echo "<meta http-equiv='refresh' content='0;URL=table.php'>";
    }
}

thank you both for all the assistence i have recieved, this has been some of the best guided self learning i have ever had and i greatly thank you both especially you diafol, i truly do appreciate it :)

also i forgot to post what my table form looks like, this is it

while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  $output = "<td><input type='checkbox' name='delete[{$row['id']}]' /></td>";
  echo $output;
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['lastname'] . "</td>";
  echo "<td>" . $row['numb'] . "</td>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['time'] . "</td>";
  echo "</tr>";
}

this seems to work so i think its right, i just wanted a second opinion lol

berserk 60 Junior Poster

I need to add a check box on the end of each value in my html table that will be checked if the user would like to remove that value from the mysql database, my current cod elooks like this:

<?php
$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));
// Check connection

$result = mysqli_query($con,"SELECT * FROM usernumdata");

echo "<table border='1'>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Phone Number</th>
<th>Date Added</th>
<th>Time Added</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['lastname'] . "</td>";
  echo "<td>" . $row['numb'] . "</td>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['time'] . "</td>";
  echo "</tr>";
}

echo "</table>";

mysqli_close($con);
?>

Obviously from my setup i would like if the user could click multiple checkboxes from the table and delete them all at once. Ive attached an image of what the table looks like now.

While im at it i would like to know if there is a way to check to see if multiples of the same number in the table already exist, that way i could keep the user from submitting multiples of the same thing, how would i go about checking this?

berserk 60 Junior Poster

sure, this is a snippit of it

berserk 60 Junior Poster

i tried that but im still getting the boolean error, i found a way to do it but i admit it is a bit unorthodox however it works for what i need so thank you anyway. I will try to learn more about union so that next time i can have cleaner code.

berserk 60 Junior Poster

well my problem is that the last time i tried something different from what i have it failed but it shouldnt have cause i have seen it work fro others in their code.

$query = "SELECT * FROM numdata WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata2 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata3 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata4 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata5 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata6 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata7 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata8 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata9 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata10 WHERE numb='".$k."'";

the only thing i havent tried yet would be OR as i used IN and it gave me the exact same error. How would one correctly go about using OR with the ten queries i have listed above and just make it into one query?

berserk 60 Junior Poster

should i post the whole code for others? or at least my finshed solution?

berserk 60 Junior Poster

thanks again for helping, i appreciate all help given :D

berserk 60 Junior Poster

i tried that but it still gives me that boolean error, lol i figured this problem out be it a tedious solution, i just had it pass multiple queries for each table i have available, then using elseif statements i searched through all that had values in them, only catch is that i had to have as many tables in my database as there were statements cause then it would attempt to read from nothing and give an error.

berserk 60 Junior Poster

I apologize :

$raw_results = mysqli_query($con, $query);

needs to be:

$raw_results = mysqli_multi_query($con, $query);
berserk 60 Junior Poster

update, i now know that i need to use mysqli_multi_query but i still have no idea what to do with it, im using this format now:

$query = "SELECT * FROM numdata WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata2 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata3 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata4 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata5 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata6 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata7 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata8 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata9 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata10 WHERE numb='".$k."'";

$raw_results = mysqli_query($con, $query);

but its still giving me the same exact error. am i using this all wrong?

here is the complete execution of the code:

$query = "SELECT * FROM numdata WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata2 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata3 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata4 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata5 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata6 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata7 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata8 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata9 WHERE numb='".$k."';";
$query .= "SELECT * FROM numdata10 WHERE numb='".$k."'";

$raw_results = mysqli_query($con, $query);

    if(mysqli_num_rows($raw_results) > 0)
    {
        while($results = mysqli_fetch_array($raw_results))
        {
            echo "<tr align='center' bgcolor='#FF0000'> <td height='25px'><font size='6'>is in database</font></td> </tr>" ;
        }
    }
    else{
        echo "<tr align='center' bgcolor='#00FF00'> <td colspan='2' height='25px'><font size='6'>is not in …
berserk 60 Junior Poster

I need help trying to get my mysqli_query() function to work right. I have this so far:

$raw_results = mysqli_query($con, "SELECT * FROM numdata WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata2 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata3 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata4 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata5 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata6 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata7 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata8 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata9 WHERE numb='%".$k."%'
UNION
SELECT * FROM numdata10 WHERE numb='%".$k."%'");

if(mysqli_num_rows($raw_results) > 0)

I found on the internet that this works but i tried it and i recieved a boolean error like so:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\AppServ\www\newsearch\search.php on line 63

it says the error is in the last line of that code above, which means to me that the query has something wrong because its always passing a false which it shouldnt, im not sure if UNION was the correct thing to use in this case but i cant find much else that works for me. Any help is greatly appreciated.

berserk 60 Junior Poster

lol OKAY i got it, i figured out why it was putting the extra 606 in there, i was having it add the query to the table twice, once for the 606 and then again for the whole number. i moved the mysql_query($query) or die(mysql_error()); outside the second loop and that did the trick.
THANK YOU SO MUCH for your assistence, i could not have done this with out you my friend. You have trully made this website that much more essential for me when it comes to asking for meaningful help to my programming problems!

thank you again! :D

berserk 60 Junior Poster

sure thing

606,0000000
606,0160158
606,0173557
606,0262530
606,0561177
606,0654393
606,0843095
606,1305858
606,2000192
606,2000735
606,2000753
606,2000902
606,2001473
606,2001688
606,2002053
606,2002109
606,2005516
606,2011277
606,2015371
606,2015668
606,2017779
606,2020017
606,2020068
606,2020090
606,2020094
606,2020103
606,2020149
606,2020188
606,2020206
606,2020271
606,2020292
606,2020300
606,2020307
606,2020316
606,2020361
606,2020399
606,2020460
606,2020481
606,2020493
606,2020507
606,2020514
606,2020559
606,2020588
606,2020640
606,2020654
606,2020700
606,2020704
606,2020728
606,2020774
606,2020790
606,2020794
606,2020831
606,2020870
606,2020964
606,2020994
606,2021007
606,2021010
606,2021016
606,2021018
606,2021019
606,2021023
606,2021024
606,2021030
606,2021038
606,2021041
606,2021042
606,2021047
606,2021048
606,2021051
606,2021056
606,2021058
606,2021060
606,2021066
606,2021067
606,2021068
606,2021071
606,2021074
606,2021076
606,2021078
606,2021081
606,2021082
606,2021083
606,2021084
606,2021085
606,2021086
606,2021087
606,2021089
606,2021092
606,2021093
606,2021094
606,2021096
606,2021097
606,2021103
606,2021106
606,2021107
606,2021108
606,2021109
606,2021111
606,2021112
606,2021117
606,2021119
606,2021122
606,2021123
606,2021124
606,2021126
606,2021129
606,2021134
606,2021135
606,2021136
606,2021137
606,2021139
606,2021141
606,2021143
606,2021144
606,2021145
606,2021147
606,2021156
606,2021157
606,2021159
606,2021160
606,2021161
606,2021163
606,2021166
606,2021170
606,2021171
606,2021172
606,2021173
606,2021177
606,2021178
606,2021179
606,2021185
606,2021186
606,2021188
606,2021190
606,2021192
606,2021195
606,2021198
606,2021201
606,2021203
606,2021205
606,2021206
606,2021209
606,2021210
606,2021211
606,2021213
606,2021215
606,2021216
606,2021217
606,2021219
606,2021221
606,2021224
606,2021226
606,2021227
606,2021228
606,2021235
606,2021240

this is how the file looks, it reads into the database as this:

606
6069345942
606
6063455678
606
6067651234
...
berserk 60 Junior Poster

i tried taking one loop out but im still getting this:

Column count doesn't match value count at row 1

berserk 60 Junior Poster

OKAY! so i am so very close to the desired output thanks to your scripts, i took some of what you did and amde it work with mine but im getting some extra values. here is my script

<?php

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

    // initial database stuff

        $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)
        {
            $row = $line[1]; //starting position
            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());
                set_time_limit(0);
            }
        }

fclose($file_handle);


echo "Done!";         

    // Form to upload a new file
    echo "
         <form enctype='multipart/form-data' name='fileupload' action='newup.php' method='POST'>
            <label for= 'file'> Filename: </label>
            <input type='file' name='file' id= 'file'>
            <input type='submit' name='submit' value='submit'>
        </form>

    ";
?>

the ouput before was:
123
456789
123
456789
...

NOW the output is:
123
123456789
123
123456789
123
123456789
123
123456789

is there any way i can skip the first entry? when i tried to elimnate it it gave me this error.

Column count doesn't match value count at row 1

ALMOST THERE lol

berserk 60 Junior Poster

i see how u set up that file, unfortunatly i can skip these numbers i need it to be one whole number

example:
123
456789
becomes
123456789

is there any way i could skip the comma and use some other delimiter?

berserk 60 Junior Poster

yes that my main issue, i figured the problem wasnt very big but i have no idea how to go about fixing this issue. also sorry for the late responce, chrome messed up and wont let me log into this site anymore! its just not my week :/

berserk 60 Junior Poster

well i was actually thinking of that very idea, but i cant create a new table for this. I need to be able to take the values put them together and then rewrite the whole table over.

<?php

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

    // initial database stuff

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

        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)
            {
                $query="INSERT into numdata(numb) values($row)";
                mysql_query($query) or die(mysql_error());
                set_time_limit(0);
            }
        }

fclose($file_handle);


echo "Done!";         

    // Form to upload a new file
    echo "
         <form enctype='multipart/form-data' name='fileupload' action='upload.php' method='POST'>
            <label for= 'file'> Filename: </label>
            <input type='file' name='file' id= 'file'>
            <input type='submit' name='submit' value='submit'>
        </form>

    ";
?>

this is what my code looks like now, it just adds the data from each comma seperated value and throws it into the database, what i would like to do is maybe read the values from 123 and then just haveing the program read the next value 456789 into the same field with 123 so that they are together and not a seperate value in the database.

Also ty so much for the assistence, im going to keep the code you answered with because im sure i will be able to use that for reference later on, it feels wonderful to get this level of assistence :) thank you again.

berserk 60 Junior Poster

well this is a little of both if that makes any sense, its a php question because i wanted to know if the solution was doable with php but also a mysql question because im doing this all to a database. If im posting in the wrong place then by all means please change the location :).
Lastly all i really need to do is just combine those values into single values and put them back into the same table, just rewriting the existing values that are there, if this is possible that is.

berserk 60 Junior Poster

Table: numdata

id  numb
1   123
2   456789
3   123
4   456789
5   123
6   456789
7   123
8   456789
9   123
10  456789
11  123
12  456789
13  123
14  456789
......

What i would like to do is combine the data in numb only, so the desired data output would be something like this.

    id  numb
    1   123456789
    2   123456789
    3   123456789
    4   123456789
    5   123456789
    6   123456789
    7   123456789
    8   123456789
    9   123456789
    10  123456789
    11  123456789
    12  123456789
    ....

I have about 1000 values to do like this and they are all different.
I have honestly no idea how to even go about this so any help would be greatly appreciated, thanks in advance.

berserk 60 Junior Poster

nvm it was a linux issue, its working fine now but its slow as christmas lol ty u so much for all the help

i ended up changing the permission of the folder with these commands

"ps aux | grep httpd"
this command was to see what folders had owner ship, in this case it was daemon

"sudo chown daemon /opt/lampp/htdocs"
this was to grant access to the folder

"sudo chmod -R 0755 /opt/lampp/htdocs"
this one allowed me to write to the directory

all were needed to fix my issue but now its working fine :D thank you for all your wisdom, it was all very much appreciated.

berserk 60 Junior Poster

ok now here is something interesting, im getting the strangest error with my completed program, i admit my test file data.txt was for testing purposes but now im using the main file which is MUCH MUCH larger and its giving me this

Warning: fopen(606.txt): failed to open stream: Permission denied in /opt/lampp/htdocs/upload.php on line 8

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

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

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

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

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

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

note the 11 and 13 line errors repeat forever, any idea why this is happening when it was JUST working??

berserk 60 Junior Poster

OMG it works :D now there is one more little part id like help with if you would be so kind. The part of my file that is in html that is an upload form, how would i go about combining that with my current setup where the file would be uploaded by a user and automatically read into the data base? like they would upload from where ever and the result would all the info in the file would be read into the database

and also seriously thank you so much, i am forever grateful :)

berserk 60 Junior Poster

here is the upload.php

?php

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

    // initial database stuff

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

        mysql_query("TRUNCATE TABLE Numbers") or die("MySQL Error: " . mysql_error()); //Delete the existing rows
        while (($data = fgetcsv($file_handle, 1000, ",")) !== FALSE)
        {
            foreach($data as $row)
            {
                $query="INSERT into numbdata(Numb) values($row)";
                mysql_query($query) or die(mysql_error()); 
            }
        }

fclose($file_handle);


echo "Done!";
/*


    // Form to upload a new file, make sure you get the "enctype" or it won't work
    echo "
        <form  enctype='multipart/form-data' name='fileupload' action='upload.php' method='POST'>

            <input type='file' name='uploadedfile'> 
            <input type='submit' name='upload' value='Upload File'>

        </form>
    ";
*/
?>

and here is the dbconnect.php

<?php
    $host = "";        // the host your database server is on, probably localhost
    $username = "";        // Database Username, if you are doing this locally and haven't set one it will probably be "root"
    $password = ;            // Database Password, if you are doing this locally and haven't set one it will probably be NULL 
    $database = "Numbers";    // The name of the database you want to use.

    // Try to connect to mysql
    mysql_connect($host, $username, $password) or die ("Could not connect to database");  

    // Try to select the database 
    mysql_select_db($database) or die ("Could not select database");    
?>
tapananand commented: Check if you did completely what was asked before posting here. You updated only one line and not the other. +0
berserk 60 Junior Poster

i mean i dont really need to since there is only comma seperated data in my file but someone i know told me it was good practice to clean my data? not sure but i tried your solution and its still giving me this error
MySQL Error: Table 'Numbers.Numbers' doesn't exist

berserk 60 Junior Poster

i think this is it.

berserk 60 Junior Poster

well i checked the database issue but i didnt get far :( here is the dbconnect.php

<?php
    $host = "*****";        // the host your database server is on, probably localhost
    $username = "*****";        // Database Username, if you are doing this locally and haven't set one it will probably be "root"
    $password = ******;            // Database Password, if you are doing this locally and haven't set one it will probably be NULL 
    $database = "Numbers";    // The name of the database you want to use.

    // Try to connect to mysql
    mysql_connect($host, $username, $password) or die ("Could not connect to database");  

    // Try to select the database 
    mysql_select_db($database) or die ("Could not select database");    
?>

and here is the screen shot of my table, at least i hope this is the part needed, and also ty so so much for all this, ive been working on this for a while but with little to show for it.

berserk 60 Junior Poster

TYSM now im actually getting some errors, however its saying now that my table doesnt exist?
here is the error.

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

Notice: Array to string conversion in /opt/lampp/htdocs/upload/upload.php on line 20
MySQL Error: Table 'Numbers.Numbers' doesn't exist

I dont understand? i mean the only line i changed was just that one and even though i know the table does exist my code says it doesnt?

sigh if it aint one thing its anohter :/

berserk 60 Junior Poster

I am unable to get my text file data.txt to read correctly into my database.
This is what my text file looks like

9889483782,6068378394,6069437364... and so on for like 50 numbers

I have to get each of the comma seperated values to show up in the database, id like them to be placed in their own respective row in my table numdata where the values will be inserted in the field, Numb.

My problem is that im not getting any errors? but my code produces no results. What do i do to fix this?
Also please try to elaborate and use code examples, i learn better by seeing it work as well as understaing how it works. Thank You.

Another quick note, the data in the txt file has nothing else in it, no spaces or anything just comma seperated vlaues.

<?php

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

    // initial database stuff

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


        fclose($file_handle);

            while (($data = fgetcsv($file_handle, 1000, ",")) !== FALSE) 
            {  

                $i = 1;
                foreach($file as $row)
                {
                    $data = explode(',',$row);
                    $query .= $i < $count ? ',':'';
                    $i++;
                }
                $query="INSERT into Numbers(Numb) values('$data')";
                mysql_query("TRUNCATE TABLE Numbers") or die("MySQL Error: " . mysql_error()); //Delete the existing rows
                mysql_query($query) or die(mysql_error());  
            }  




echo "Done!";
?>