Page 1 of 1
Help me pls, php newbie with php problem..
Posted: Sun Oct 31, 2010 10:26 pm
by joandong2
HELP ME PLEASE, i keep getting this error, and with regards to header eerror, i tried replacing it with a script, it's ok, but after i login, it will not direct to the index.php, im a newbie,
Code: Select all
[u]index.php[/u]
<?php
session_start();
if (!isset($_SESSION['user_id'])){
header('location: login.php');
}
?>
<html>
<title> WEEEE </title>
<h1><b>SALES AND INVENTORY</b></h1>
<form action='sales.php' method='post'>
<input type='submit' name='new_sale' value='new_sale'/>
</form>
</html>
[u]login.php[/u]
<?php
include("connection.php");
if (isset($_POST['login'])) {
$username = trim(($_POST['user']));
$password = trim(($_POST['pass']));
//$hashed_password = sha1($password);
$query = "SELECT * FROM users where username='$username' and password='$password'";
$result = mysql_query($query) or die();
if (mysql_num_rows($result) == 1)
{
// username/password authenticated
// and only 1 match
session_start();
$user = mysql_fetch_row($result);
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
echo '<script>alert("User confirmed.");location.href="index.php";</script>';
}
else
{
// username/password combo was not found in the database
echo "invalid user!";
}
}
?>
<html>
<br /><br /><br />
<form action="login.php" method="post">
<table align="center" >
<tr>
<td>USERNAME:</td>
<td><input type="text" name="user" maxlength="30"></td>
</tr><tr>
<td>PASSWORD</td>
<td><input type="password" name="pass" maxlength="30"></td>
</tr><tr>
<td><input type="submit" name="login" value="login"></td>
</tr>
</tr>
</form>
</html>
Re: Help me pls, php newbie with php problem..
Posted: Sun Oct 31, 2010 10:35 pm
by mikecampbell
session_start() must be called before you send anything to the browser. So move down the <span>...</span> bit at the top (you'd want it to come after your opening html tag anyways).
Re: Help me pls, php newbie with php problem..
Posted: Sun Oct 31, 2010 10:51 pm
by joandong2
which page are you refering to master?? im sorry, im a newbie,,

, i tried moving the position of the sessions,but still this error exist, i would like to eliminate the direct acces of the index.php without logging in..
Re: Help me pls, php newbie with php problem..
Posted: Mon Nov 01, 2010 3:01 am
by mikecampbell
Remove or move <span style="text-decoration: underline">index.php</span> from the top of login.php.
Re: Help me pls, php newbie with php problem..
Posted: Mon Nov 01, 2010 8:05 pm
by joandong2
oh, its a different page, i have a problem with my sessions, ????
Re: Help me pls, php newbie with php problem..
Posted: Mon Nov 01, 2010 8:27 pm
by Christopher
You are showing the source for index.php, but the error message is for login.php. The problem is that there is some output before the call to session_start(). It could be a space or return or tab, but there is some output.
Also, you can just copy and paste the error message. You don't need huge screenshots for error messages.

Re: Help me pls, php newbie with php problem..
Posted: Tue Nov 02, 2010 12:39 am
by joandong2
Re: Help me pls, php newbie with php problem..
Posted: Tue Nov 23, 2010 8:55 am
by joandong2
help pls?? again?? i've been thinking what wrong with this,, when i hit record button, it will insert date, and total sales into a table, and that seems ok, but if there are no sales/ sold product, the total will be zero, but when i hit record button, it will not insert into the table. what's wrong?? huhu, everyting is fine if there is sold items, even if the total sales is 0, but if no sold items, and total is 0, it ain't inserting.. help meeee plsss......
Code: Select all
[u]view_sales.php[/u]
<?php
//include("header.php");
include("connection.php");
if (isset($_POST['fr_sub'])){
$date= $_POST['st_date'];
$total=0;
$query = "SELECT * FROM sales where date='$date'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 0)
{
echo "NO SALES-----";
}
else
{
echo "<table cellpadding='2'>";
echo "<h2>DATE: <b>".$date."</b></h2>";
echo "<tr><th>SALES ID</th><th>TIME</th><th>TOTAL PAYMENTS</th><th>CASH</th><th>CHANGE</th></tr>";
while($row = mysql_fetch_array($result))
{
$id=$row['sales_id'];
//echo "<form action ='view_sales4.php' method='get'>";
echo "<tr><td style='text-align:center'>";
echo $id;
//echo "<input type='hidden' name='sel_id' value=".$row['sales_id'].">";
echo "</td><td>";
echo $row['time'];
echo "</td><td style='text-align:center'>";
echo "P".$row['t_pay'];
echo "<input type='hidden' value='".$row['t_pay']."'>";
echo "</td><td style='text-align:center'>";
echo "P".$row['cash'];
echo "</td><td style='text-align:center'>";
echo "P".$row['change'];
//echo "</td><td>";
//echo "P".$row['price'];
//echo "</td><td>";
//echo $row['quantity'];
echo "</td><td>";
//echo '<a href="" rel="facebox">view sales</a>';
//echo "<input type='submit' name='view' value='view' >";?>
<a href="view_sales4.php?id=<?php echo $id; ?>" rel="facebox"><?php echo "view sale"; ?></a>
<?php echo "</td></tr>";echo "</form>";
$total += $row['t_pay'];
}
}
echo "</table>";
echo "<table>";
echo "<form action ='daily_sales.php' method='post'>";
//echo "<br />";
echo "<hr><tr>";
echo "<td>";
echo "<input type='hidden' name='date' value='".$date."'>";
echo "</td><td>";
echo "TOTAL SALE: <b>P".$total."</b>";
echo "</td><td>";
echo "<input type='hidden' name='total' value='".$total."'>";
echo "</td><td>";
echo "<input type='submit' name='record' value='RECORD' class='button'>";
echo "</td></tr>";
echo "</form>";
echo "</table>";
}
?>
[u]daily_sales.php[/u]
<?php
include("connection.php");
if(isset($_POST['record'])){
$total= $_POST['total'];
$date= $_POST['date'];
$query="SELECT * FROM daily_sales2 where '$date'=date";
$result=mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
if(mysql_num_rows($result)>0)
{
echo '<script>alert("GA CGE LANG TAG RECORD ANI!");location.href="index.php";</script>';
}
else
{
$query = "INSERT INTO daily_sales2 values (null,'$date','$total')";
$result = mysql_query($query) or die('error');
echo '<script>alert("MANIRA NATA!");location.href="index.php";</script>';
}
}
?>
Re: Help me pls, php newbie with php problem..
Posted: Tue Nov 23, 2010 11:46 am
by Christopher
Based on the logic at the bottom of your script, it will only INSERT in the else for if(mysql_num_rows($result)>0).
Re: Help me pls, php newbie with php problem..
Posted: Wed Nov 24, 2010 6:53 am
by joandong2
sir help me pls?? if the date is already recorded in the table == exit, else insert values?? what's wrong sir?? i also try removing the if statement and put the insert function directly, still if there are no sold items and the total sale is 0, it aint recording.... huhuhuhuu helllpp????????????? plssss??????????????
Re: Help me pls, php newbie with php problem..
Posted: Thu Nov 25, 2010 4:05 am
by joandong2
help?
Re: Help me pls, php newbie with php problem..
Posted: Sun Nov 28, 2010 10:13 am
by joandong2
huhu?help?