Hi.. I am new in php +ajax.....Now i am doing project in php+ajax+linux environment...i create a login page using php,ajax,mysql,, i have mysql tables are. register,slideshow,,,,,In register table having following field...
1.uid (autoincrement)2.first (firstname)3.last(surname)4.user(username),5.pass(password)
In slide show table having following field,,,
1.uid 2.pid(presentation id,autoincrment) 3.slideno 4.description 5.location(this is what image file is store that particular location)..
my login programs are..
//login.html
<html>
<head>
<script language="javascript" type="text/javascript">
//Browser Support Code
function ajaxFunction()
{
var ajaxRequest; // The variable that makes Ajax possible!
try
{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer Browsers
try
{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4)
{
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
document.getElementById('message').style.visibility = 'hidden';
}
}
var user= document.getElementById('user').value;
var pass= document.getElementById('pass').value;
var queryString = "?user=" + user + "&pass=" + pass;
document.getElementById('message').style.visibility = 'visible';
ajaxRequest.open("GET","login.php" + queryString, true);
ajaxRequest.send(null);
}
</script>
</head>
<body>
<div id="message" style="position:absolute; top:1%; left:95%; margin-left:-100px; font-size:14;background-color: red ;color: white;width: 165px; height: 25px; overflow: auto;visibility: hidden">Executing...</div>
<form>
<center>
<img src="" style="visibility:hidden" width="0%" height="0%">
<table border="0" bgcolor="#CCCCFF" cellspacing="1" cellpadding="3" width="287">
<tr>
<td align="left" colspan="2" width="275"><b><font size="5" color="#000080">Login</font></b></td>
</tr>
<tr>
<td align="right" width="81"><b><font color="#000080">User
Name:</font></b></td>
<td width="184">
<input type="text" id="user">
</td>
</tr>
<tr>
<td align="right" width="81"><b><font color="#000080">Password:</font></b></td>
<td width="184">
<input type="password" id="pass">
</td>
</tr>
<tr>
<td colspan="2" align="center" width="275"><input type="button" onclick="ajaxFunction()" value="Login" ></td>
</tr>
</table>
<div id="ajaxDiv">
</center>
</form>
</body>
</html>
//login.php
<?php
$user=$_GET['user'];
$pass=$_GET['pass'];
$conn = mysql_connect("localhost","root","") or die("could not connect server");
$db = mysql_select_db("thiru",$conn) or die("could not connect database");
$query= "select * from register";
$res = mysql_query($query) or die("query failed" . mysql_error());
$num_rows=mysql_num_rows($res);
while($rr=mysql_fetch_array($res))
{
if($user==$rr[3] && $pass==$rr[4])
{
//get uid
$insert=$rr[0];
//echo"welcome" .$user;
$flag=true;
}
}
if($flag==false)
{
echo"userid and password mismatch";
}
mysql_close($conn);
?>
The above program is successfully logged .. and i fetch uid in $insert variable...This is my quetion...
uid,pid,slideno,description,location will be stored automaticallyin slideshow table..while i upload file....
my upload proram is given below...
//upload.html file
<html>
<head>
<script type="text/javascript" language="javascript">
function upload()
{
var oForm = document.uploadform;
oForm.submit();
}
</script>
</head>
<body>
<div id="message" class="drag" style="position:absolute; top:50%; left:50%; margin-left:-100px; font-size:12;background: transparent;
width: 75px; height: 75px; overflow: auto; visibility: hidden">
</div>
<center>
<form name="uploadform" action="upload.php" method="POST" ENCTYPE="multipart/form-data" target="hiddenFrame">
Open :
<input style="font:normal 10px Verdana" size="35" align="left" type="file" name="code" id="code"> <br><button onClick="upload();return false">Upload</button>
</form>
<iframe src="about:blank" name="hiddenFrame" width="400" height="400"
frameborder="1" ></iframe>
</center>
</body>
</html>
//upload php file
<?php
$uploaddir='/var/www/html/upload/';
$uploadfile=$uploaddir.basename($_FILES['code']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['code']['tmp_name'], $uploadfile))
{
echo "File was successfully uploaded.\n";
print "</pre>";
$conn=mysql_connect("localhost","root","");
$db=mysql_select_db("thiru");
$query = "insert into slide(sloc)values('$uploadfile')";
$result=mysql_query($query);
echo"<br>";
mysql_close($conn);
$filename=$_FILES['code']['name'];
echo"filename:";
echo $filename;
echo"<br>";
}
else
{
echo "please choose a correct file!!";
}
?>
please send me the correct coding ..
Edit/Delete Message