textarea content insertion failed to mysql database - php

I am trying to post records into database same script was working fine a few days ago after I modify my website, its not working correctly.
When I try to echo the contents then I get everything is working fine. even I tried to insert record without textarea content then it works perfectly only when I try to insert records with content I mean $post_content then i got an error in query.
If I use mysql_real_escape_string(), I got the record inserted but without textarea content, its blank, I used nl2br() for escaping line break but nothing works totally depressed at this moment, and the same code is working perfectly on my local computer server dont find where the real problem is.
I thought the text editor is causing the problem, I am using niceEdit now, I also tried using tinyMce but never works. Can anyone please help me?
<!DOCTYPE html>
<html>
<head>
<title> Insert New Post</title>
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
<style>
input[type="text"]{
width:90%;
height: 30px;
}
select{
height: 30px;
}
table{
width:100%;
}
label{
font-weight:300;font-size:1.5em;text-align: right;
}
textarea{
width: 90%;
}
</style>
</style>
</head>
<!-- BEGIN BODY -->
<body>
<?php include('config.php'); ?>
<?php
ob_start();
if($_SERVER["REQUEST_METHOD"] == "POST"){
$post_title=$_POST['post_title'];
$post_author=$_POST['post_author'];
//$post_date=date("l jS \of F Y h:i:s A");
//$post_date=date("l jS \of F Y");
$post_catagory=$_POST['post_catagory'];
$post_image=$_FILES['post_image']['name'];
$post_image_tmp=$_FILES['post_image']['tmp_name'];
$post_keyword=$_POST['post_keyword'];
$post_page=$_POST['post_page'];
$post_content=mysql_real_escape_string($_POST['post_content']);
// $post_content= nl2br($post_content);
if($post_author==''){
echo "<script>alert('You must fill all blank fields'); window.location('insert_post.php');</script>";
exit();
}
else{
move_uploaded_file($post_image_tmp,"../../images/$post_image");
$sql="insert into post (page_id,post_title,post_author,post_image,post_keywords,post_catagory,post_content) values ('$post_page','$post_title','$post_author','$post_image','$post_keyword','$post_catagory','$post_content')";
$result=mysqli_query($bd,$sql) or die("Error occured:in query".mysql_error());
if(!$result){
echo"<h2 style=\"color:red;position:absolute;top:0;left:400px;\">Your post wasnt posted something is worng</h2>";
exit();
}else{
echo"<h2><script>alert('Your Post has been published successfully!')</script>";
echo"<script>window.open('insert_post.php','_self')</script>";
}
}
}
?>
<!-- MAIN WRAPPER -->
<div id="wrap" >
<?php
//echo $post_author;
// echo $post_title;
// echo $post_page;
// echo $post_keyword;
// echo $post_content;
// echo $post_image;
?>
<!-- MENU SECTION -->
<!--END MENU SECTION -->
<!--PAGE CONTENT -->
<?php //include('include/content.php'); ?>
<div class="row">
<div class="col-lg-12">
<div id="post_form">
<table>
<form action="" method="post" enctype="multipart/form-data" id="post_form">
<tr>
<td><label>Post Title</label></td>
<td><input class="form-control" type="text" name="post_title"></td>
</tr>
<tr>
<td><label>Post Author</label></td>
<td><input class="form-control" type="text" name="post_author"></td>
</tr>
<tr>
<td> <label>Post Catagory</label></td>
<td><select class="form-control" name="post_catagory">
<?php
$sql="select * from catagory";
$result=mysqli_query($bd,$sql) or die("Error:".mysql_error());
while($row=mysqli_fetch_array($result)){
?>
<option value="<?php echo $row['name'] ?>"><?php echo $row['name'];?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td><label>Post keywords</label></td>
<td><input type="text" name="post_keyword" placeholder="Enter text"></td>
</tr>
<tr>
<td><label>Post Image</label></td>
<td><input type="file" name="post_image"/></td>
</tr>
<tr>
<td><label>Select Page</label></td>
<td><select class="form-control" name="post_page">
<?php
$sql="select * from menu";
$result=mysqli_query($bd,$sql) or die("error".mysql_error());
while($row=mysqli_fetch_array($result)){
?>
<option value="<?php echo $row['id'];?>"><?php echo $row['name'];?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td><label>Post Contents</label></td>
<td><textarea id="area1" name="post_content" rows="10"></textarea></td>
</tr>
<tr>
<td>Action Key</td>
<td><button type="submit" class="btn btn-default" name="submit" onclick="nicEditors.findEditor('area1').saveContent();">Publish Now</button><button type="reset" class="btn btn-default">Reset Button</button></td>
<td></td>
</tr>
</form>
</table>
</div>
</div>
</div>
<!--END PAGE CONTENT -->
<!-- RIGHT STRIP SECTION -->
<?php //include('include/right.php'); ?>
<!-- END RIGHT STRIP SECTION -->
</div>
</body>
</html>
<!--END MAIN WRAPPER -->
<!-- FOOTER -->

You mixed up mysql and mysqli. When you call mysqli_query, you have to prevent data with mysqli_ functions too.
$post_content = mysqli_real_escape_string(nl2br($_POST['post_content']));
// ^
You should use mysql_real_escape_string for all string inputs to database which include, not just for the content.

Just use mysql_real_escape_string() for all the values to be inserted.

Use mysqli_real_escape_string()
string mysqli_real_escape_string ( mysqli $link , string $escapestr )
You have to add connection link as first argument of mysqli_real_escape_string()
$post_content = mysqli_real_escape_string($bd, nl2br($_POST['post_content']));
Again
mysqli_query($bd,$sql) or die("Error occured:in query".mysql_error());
^
Instead of
mysql_error()
use
mysqli_error($bd)

Related

Add to cart button redirecting to another page

Whenever I click on the add to cart button it just goes to another page instead of showing it in the table
<?php
require "includes/dbh.php";
if(isset($_post['add'])){
if(isset($_SESSION['shopping_cart'])){
This is how I get the data in the html
$item_array_id=array_column($_SESSION['shopping_Cart'],'item_id');
if(!in_array($_GET['id'],$item_array_id)){
$count=count($_SESSION['shopping_cart']);
$item_array=array(
'item_id' =>$_GET['id'],
'item_name'=>$_POST['hidden_name'],
'item_price'=>$_POST['hidden_price'],
'item_quantity'=>$_POST['quantity'],
);
$_SESSION['shopping_cart'][$count]=$item_array;
}else{
echo "<script> alert('item already added')</script>";
echo "window.location='displayitems.php'></script>";
}
}else{
$item_array=array(
'item_id' =>$_GET['id'],
'item_name'=>$_POST['hidden_name'],
'item_price'=>$_POST['hidden_price'],
'item_quantity'=>$_POST['quantity'],
);
$_SESSION['shopping_cart'][0]=$item_array;
}
}
if(isset($_get['action'])){
if($_get['action']=='delete'){
foreach($_SESSION['shopping_cart'] as $keys =>$values){
if($values['item_id']==$_get['id'])
{
unset($_SESSION['shopping_cart'][$keys]);
echo '<script>alert("item removed")</script>';
echo '<script>window.location="displayitems.php</script>';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
<style>
.product{
border:1px solid
margin:-1px 19px 3px -1px;
padding: 10px;
text-align:center;
bacgkround-color:#efefef;
}
</style>
</head>
<body>
<?php
if(isset($_SESSION['userId'])){
echo '<div id="items" >';
include_once 'includes/dbh.php';
require 'includes/gallery-upload.in.php';
$sql="SELECT * FROM gallery ORDER BY orderitems DESC;";
$stmt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt,$sql)){
echo "sql statement failed in displayitems.php";
}else{
mysqli_stmt_execute($stmt);
$result=mysqli_stmt_get_result($stmt);
while($row=mysqli_fetch_assoc($result))
{
?>
This is my form in adding to cart button
<div class="col-md-3">
<form method="POST" action="displayitems.php?action=add&id=<?php
echo $row["idGallery"]?>">
<div class="product">
<img src=images/<?php echo $row['imgFullNameGallery'] ?>
<br>
<h3><?php echo $row['nameitem']?></h3>
<h3><?php echo $row['price']?></h3>
<input type='number' name='quantity' value="1">
<input type='hidden' name='hidden_name' value="<?php echo
$row['nameitem']?>">
<input type='hidden' name='hidden_price' value="<?php
echo
$row['price']?>">
<button type='submit' name='add'>Add to cart</button>
</div>
</form>
</div>
<?php
}
}
}
?>
<div style="clear":both"></div>
<h3 class="title2">Shopping cart details</h3>
<div class="table table-bordered">
<table>
<tr>
<th width=40%>Item Name</th>
<th width=10%>Quantity</th>
<th width=20%>Price</th>
<th width=15%>Total</th>
<th width=5%>Action</th>
</tr>
<?php
if(!empty($_SESSION['shopping_cart'])){
$total=0;
foreach($_SESSION['shopping_cart']as $keys => $values){
?>
<tr>
<td><?php echo $values['item_name'];?></td>
<td><?php echo $values['item_quantity'];?></td>
<td>$<?php echo $values['item_price'];?></td>
<td><?php echo
number_format($values['item_quantity']*$values['item_price'],2);?></td>
<td>REMOVE</span></td>
</tr>
<?php
$total= $total+($values['item_quantity']*$values['item_price']);
}
?>
<tr>
<td coslpan="3" align="right">total</td>
<td align="right"><?php echo number_format($total,2);?></td>
</td></td>
<?php
}
?>
</table>
</div>
</body>
</html>
It doesn't show in the table and the url is just changing to http://localhost/Soft/displayitems.php?action=add&id=1 and the page is blank
because of you using form and the button type is submit so it's expecting a callback function. Regarding you don't have one and you want to display everything in the same page so you have instead to make the submit functionality to a link instead.
Change :
<button type='submit' name='add'>Add to cart</button>
to
<a type='submit' name='add'>Add to cart</a>
or
<input type="submit" value="Add to cart">
here is a mozilla ref

I can't update MySQL PHP

I don't get any errors but I can't update MySQL PHP. I want to change dropdown status from "sedang diproses" dropdown into "Berjaya or Tidak Berjaya". Also I can't change in the database "sedang diproses" into "Berjaya or Tidak Berjaya"
This is my Code Html
<?php
session_start();
include ('include/myFunction.php');
require('include/connect.php');
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<link href="css/myStyle.css" rel="stylesheet" type="text/css" />
<link href="css/myStyle1.css" rel="stylesheet" type="text/css" />
<!-- Button to open the modal login form -->
<link href="css/myStyle3.css" rel="stylesheet" type="text/css" />
<body>
<div align="right">
<a href="logout.php" ><img src="img/logout.png" width="63" height="46" /></a>
</div>
<div class="header" align="left"><img src="img/gmbar.PNG" width="223" height="126" /><!-- end .header --><!-- end .header --></div>
<div class="content" style="font:Verdana, Geneva, sans-serif">
<div class="content" style="font:Verdana, Geneva, sans-serif">
<div class="topnav" id="myTopnav" style="font-family:Verdana, Geneva, sans-serif">Kembali
</div>
<p> </p>
<?php if($_SESSION['namaadmin'] ==null)
{
header('location:index.php');
}
else
{
?>
<form action="prosesstatus.php" method="post">
<table width="1002" height="87" border="0" align="center" bgcolor="#CCCCFF">
<tr bgcolor="#00CCFF">
<td width="30"><strong>Bil</strong></td>
<td width="298"><strong>Nama</strong></td>
<td width="176"><strong>Nama Kursus</strong></td>
<td width="150"><strong>Tarikh Daftar</strong></td>
<td width="150"><strong>Status</strong></td>
<td width="168"><strong>Kemaskini Status</strong></td>
<td width="131"><strong>Pilihan</strong></td>
</tr>
<?php
$namakursus = '';
if( isset( $_GET['namakursus'])) {
$namakursus = $_GET['namakursus'];
}
$sql1 = "Select * from pemohonan INNER JOIN kursus ON pemohonan.idkursus = kursus.idkursus
INNER JOIN pemohon ON pemohonan.idPemohon = pemohon.idPemohon WHERE kursus.namakursus = '$namakursus' ";
$result1=mysqli_query($dbc,$sql1) or die (mysqli_error());
$i=1;
while($row1 = mysqli_fetch_assoc($result1))
{
?>
<tr>
<td><strong><?php echo $i; ?><input name="idkursus" type="hidden" size="50" value="<?php echo $row1['idkursus'];?>"/><input name="idPemohonan" type="hidden" size="50" value="<?php echo $row1['idPemohonan'];?>"/></strong></td>
<td><strong><?php echo $row1['nama']; ?></strong><input name="id" type="hidden" size="50" value="<?php echo $row1['idPemohon'];?>"/></strong></td>
<td><strong><?php echo $row1['namakursus']; ?></strong></td>
<td><strong><?php echo $row1['tarikhpemohon']; ?></strong></td>
<td><strong><?php echo $row1['status']; ?></strong></td>
<td><select name="status" value="<?php echo $row1['status']; ?>">
<option value="sila pilih">-Sila Pilih-</option>
<option value="Berjaya">Berjaya</option>
<option value="Tidak Berjaya">Tidak Berjaya</option>
</select></td>
<td><input name="btnKemaskini" type="submit" value="Kemaskini" /></td>
</tr>
<?php
$i++;
}
mysqli_close($dbc);
}
?>
</table></form>
<p> </p>
<p> </p>
<div class="footer" style="font-family:Arial, Helvetica, sans-serif">
<?php footertext(); ?>
</div>
</body>
</html>
This is Image
This Is My Image DB
This is my Code Php
<?php
require ('include/connect.php');
$idPemohonan = '';
$idPemohon = '';
$idkursus = '';
if (isset($_GET['idPemohon'],$_GET['idkursus'],$_GET['idPemohonan']))
{
$idPemohon = $_GET['idPemohon'];
$idkursus = $_GET['idkursus'];
$idPemohonan = $_GET['idPemohonan'];
}
$tarikhharini=date('y-m-d');
$status=$_POST['status'];
$sql1 = "UPDATE pemohonan SET idPemohonan ='$idPemohonan' , idPemohon ='$idPemohon' , idkursus ='$idkursus' , tarikhpemohon ='$tarikhharini' , status='$status'
where idPemohonan = '$idPemohonan' and idPemohon = '$idPemohon'";
$result1 = mysqli_query($dbc,$sql1) or die (mysqli_error());
$num_row1 = mysqli_affected_rows($dbc);
echo "<script language=\"JavaScript\">\n";
echo "alert('Status Pemohonan Telah Dihantar!');\n";
echo "window.location='senaraipemohon.php'";
echo "</script>";
mysqli_close($dbc);
?>
Your code is not working because you haven't sent in
<form action="prosesstatus.php" method="post">
Parameters:
$idPemohon = $_GET['idPemohon'];
$idkursus = $_GET['idkursus'];
$idPemohonan =
$_GET['idPemohonan'];
If you want use $_GET link should look like:
prosesstatus.php?idPemohon=value&idkursus=value&idPemohonan=value
Or you should add these parameters in
Input type hidden and change in php to $_POST
I agree with others than you should use MVC for example some kind of framework (Laravel, CodeIgniter)
Or separate as much as possible php and html because your code looks unprofessional.
Your MySQL queries are vulnerable to SQL injection and most likely file
include/connect.php
is not outside public folder which is not good practice to do.

Update query is not working correctly

I am making a code for editing a text area. The query runs correctly without any errors but the textarea is not updated. Can anyone help me with it please?
<html>
<body bgcolor="skyblue">
<form method= "post" enctype="multipart/form-data" action="upd.php">
<table align="center" width="795" border="2" bgcolor="#CCC">
<?php
$i=0;
$sel="select * from video";
$sel_query=mysqli_query($con, $sel);
while($row=mysqli_fetch_array($sel_query)){
$i++;
$var_id=$row['v_id'];
$var=$row['video'];
?>
<tr align="center">
<td align="right">
<br>
<h2>Upadte Video <?php echo $i; ?> Link: </h2>
<button type="submit" name="btn">
<a name="upd" href="upd.php?insert_brand=<?php echo $var_id; ?>&fram=<?php echo $var; ?>">Update</a>
</button>
<td align="left"><br><textarea name="vids" rows="4" cols="50"><?php echo $var; ?>"</textarea></td>
</td>
</tr>
<?php
}
?>
</table>
</form>
upd.php
<?php
include ("includes/db.php");
$check=#$_GET['insert_brand'];
if(isset($_POST['btn'])){
$vids=$_POST['vids'];
$upds="UPDATE `video` SET `video`='$vids' WHERE `v_id`='$check'";
$query=mysqli_query($con, $upds);
if($query){
echo 'The query is executed';
}
else{
echo 'There was an error'. mysqli_error($con);
}
}
?>
Have you tried mysql_real_escape_string() to retrieve textarea data.

Table doesn't align vertically

So I want to do something very simple, which I can't figure out properly. I'm currently making a forum and where I normally have errors (the back end) it all works now, probably through the black magic I used ;D,
So now, the thing is: I want to show all my subcategories, so I'm using the following table:
<div id="content_big">
<div class="content_top_oranje">
<p class="koptekst">
<?php echo 'Name';?>
</p>
<p style="float:left; margin-left:70%; margin-top:-30px; color:#fff; font-size:11px;font-family:Ubuntu;">
<?php echo 'Description';?>
</p>
</div>
<div class="content_mid">
<?php $kop='algemeen' ;
$query=$ db->conn->prepare("SELECT * FROM ht_forum_categorien WHERE kop = ?");
$query->bind_param('s', $kop);
$query->execute();
$result = $query->get_result();
while ($row = $result->fetch_assoc()) { ?>
<table style="width:100%;" border="1" cellspacing="0">
<tr>
<td>
<?php echo $row[ 'name']; ?>
</td>
<td style="margin-left:50px;">
<?php echo $row[ 'description]; ?>
</td>
</tr>
</table>
<?php
}
?>
</div>
</div>
But when I use that, this is the output I get:
How is it possible that all of the rows won't vertically align? And how to solve it?
Thanks. (I'm sorry the screenshot is in dutch, but I can't change the values in the DB, since it isn't mine
You have two fairly big problems in your code:
most importantly, and the problem you ran into: you're not generating a table. You're generating lots of tables. If you want one table, move your <table> and </table> tags outside of your loop and only generate <tr> with their content in your while loop.
a problem you didn't realise you had: the HTML you're using isn't faithful to the promise that your markup is semantic: that heading should be a heading element (h1, h2, h3, what have you), and as a table, really this shouldn't be divs and p and table at all, this should be a single table, with a heading row, styled as your heading, and then data rows.
So let's rewrite this to something that makes sense both from a PHP and from an HTML perspective:
<?php
...query your data. Do this first...
$result = ...;
if($result isn't empty) {
?>
<table>
<?php
echo "<thead><th>$kop</th><th>$description</th></thead>";
?>
<tbody>
<?php
while ($row = $result->fetch_assoc()) {
$name = $row['name'];
$desc = $row['description'];
echo "<tr><td>$name</td><td>$desc</td></tr>\n";
}
?>
</tbody>
</table>
<?php } ?>
So don't do the querying inside the table, do it first, then if there are results to show, decide whether or not to write the single table, generating the dynamic content in the tbody as table rows. And use CSS to style the thead cells the way you need.
For that matter, don't use all those inline style="..." bits. They're all identical, so you're just needlessly repeating static CSS. Use class="rowclass" or whatever name you think is appropriate, and then in your stylesheet or <style> block, define
.rowclass {
background-color: ...;
color: ...;
...
}
Try this
<div id="content_big">
<div class="content_top_oranje">
<p class="koptekst">
<?php echo 'Name';?>
</p>
<p style="float:left; margin-left:70%; margin-top:-30px; color:#fff; font-size:11px;font-family:Ubuntu;">
<?php echo 'Description';?>
</p>
</div>
<div class="content_mid">
<?php $kop='algemeen' ;
$query=$ db->conn->prepare("SELECT * FROM ht_forum_categorien WHERE kop = ?");
$query->bind_param('s', $kop);
$query->execute();
$result = $query->get_result();
?>
<table style="width:100%;" border="1" cellspacing="0">
<?php while ($row = $result->fetch_assoc()) { ?>
<tr>
<td>
<?php echo $row[ 'name']; ?>
</td>
<td style="margin-left:50px;">
<?php echo $row[ 'description']; ?>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>

PHP. session_start() [function.session-start]: Cannot send session cookie error

Im having problem in my web where it works perfectly on my local server which is a WAMPSERVER i can run my website completely but after adding to the web server it give me error saying
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/multisl/public_html/udrivetest/index.php:2) in /home/multisl/public_html/udrivetest/init.php on line 4
init.php
<?php
ob_start();
session_start();
mysql_connect("localhost","***","***");
mysql_select_db('****');
include 'function/user.func.php';
include 'function/car.func.php';
include 'function/image.func.php';
?>
header1.php
<head>
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {
font-size: 16px;
font-weight: bold;
}
.style5 {
font-size: 12px
}
.a {
color:#000000;
text-decoration:none;
}
-->
</style>
</head>
<body>
<div style="margin-left:10px;">U Drive.lk</div>
<div class="style5" style="text-align:right; padding:10px;">
Contact Us | Disclaimer | Site Map</div>
</div>
<div>
<div style="background-image:url(images/Car3.png); border:#FFFFFF; border-style:solid; border-width:2px; border-top:none; border-bottom:none; width:920px; height:450px; margin-left:auto; margin-right:auto;" align="center">
<br/>
<img src="images/Car6.png" width="920px" height="135px" />
<div style="margin-top:-22px; height:22px; margin-left:55px;" align="left"><a class="a">Home</a></div>
<div style="margin-top:-22px; height:22px; margin-left:200px;" align="left"><a class="a">Gallery</a></div>
<div style="margin-top:-22px; height:22px; margin-left:350px;" align="left"><a class="a">Leasing</a></div>
<div style="margin-top:-22px; height:22px; margin-left:490px;" align="left"><a class="a">Testimonial</a></div>
<div style="margin-top:-22px; height:22px; margin-left:640px;" align="left"><a class="a">Forum</a></div>
<div style="margin-top:-22px; height:22px; margin-left:790px;" align="left"><a class="a">FAQ</a></div>
<div style="margin-left:auto; margin-right:auto; margin-top:20px;" >
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','920','height','135','src','Flash/Flash Header2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','Flash/Flash Header2' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="920" height="135">
<param name="movie" value="Flash/Flash Header2.swf" />
<param name="quality" value="high" />
<embed src="Flash/Flash Header2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="920" height="135"></embed>
</object></noscript>
</div>
<div align="left">
<table width="100%" border="0" style="margin-top:10px;">
<tr>
<td width="20%" valign="top" ><div align="left"><img src="images/Buy_men.png" /> <img src="images/Sell_men.png" /> <img src="images/Rent_men.png" /></div>
<div style="color:#FFFFFF;margin-top:-90px; width:38px; margin-left:10px;">Buy</div>
<div style="color:#FFFFFF;margin-top:-18px; width:38px; margin-left:65px;">Sell</div>
<div style="color:#FFFFFF;margin-top:-20px; width:38px; margin-left:115px;"><a style="color:#FFFFFF;">Rent</a></div></td>
<td width="38%"><fieldset style="background-color:#cccccc">
<span class="style4">Quick Search</span>
</fieldset></td>
<td width="42%"><fieldset style="background-color:#cccccc">
<span class="style4">Login</span>
<?php include_once('login.php'); ?>
</fieldset></td>
</tr>
</table>
</div>
</div>
</div>
<div style="margin-left:auto; margin-right:auto; width:920px;">
login.php
<?php
if (logged_in()) {
echo '<br/> View User Profile <br/>Log Out';
} else {
?>
<form action="" method="post">
<table width="100%" border="0" style="margin-top:-5px;" >
<tr>
<td><div align="left">User Name :</div></td>
<td><input type="text" name="Quick_Name" size="25" /></td>
</tr>
<tr>
<td><div align="left">Password :</div></td>
<td> <input type="text" name="PassWord" size="25" /> <input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
Forgot your password / Register User
<?php
}
if (isset($_POST['Quick_Name'], $_POST['PassWord'])) {
$forgotEmail = $_POST['Quick_Name'];
$login_password = $_POST['PassWord'];
if (empty($forgotEmail) || empty($login_password)) {
$errors[] = 'Email and Password required';
} else {
$login = login($forgotEmail, $login_password);
if ($login === false) {
$errors[] = 'Unable to Log you in';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br/>';
}
} else {
$_SESSION['user_id'] = $login;
header('Location:index.php');
exit();
}
}
?>
index.php
<?php include 'init.php'; include 'widgets/header1.php'; ?>
<div>
</div>
</div>
</body>
</html>
Please Can any one help me out to solve this problem or give me a clue what I am doing here?
Thanks in Advance
In PHP, headers get sent as soon as the page starts to print something - which can occur unintentionally due to whitespace.
Based on your error message (output started at /home/multisl/public_html/udrivetest/index.php:2)
I am guessing this line of index.php:
<?php include 'init.php'; include 'widgets/header1.php'; ?>
appears on line 2 of the file? But you cannot have a line of whitespace above it, it needs to be line 1 since one of the includes is dealing with headers (cookie for session).
Otherwise the blank line 1 is "printing something" - a new line - which sends headers probably before you are intending.
Basically, check all files for not having blank lines above opening tags <?php and don't have blank lines below closing tags ?>.
This is most likely that there exists some whitespace that is sent before the session_start command, try removing the closing PHP tag (?>) and report back the results.
By doing this you remove the possibility of it outputting any invalid whitespace.
There should have some blank space sending back to client. It is a good practise to leave php closing tag ?> if your last line of code is a php code.
Make sure that you dont leave any blank space before and after the php opening tag and php closing tag
You can prevent any output to send to client by using object buffering with ob_start() .
put the ob_start at the very beginning of your php code can save you time.
I would like to consider removing ob_start() from init.php to index.php.
thanks

Categories