In your php file
convert this
if(isset($_FILES) && $_FILES<>""){
to
if(isset($_FILES)){
In your php file
convert this
if(isset($_FILES) && $_FILES<>""){
to
if(isset($_FILES)){
Sorry for late reply, try this code I hope it will fix your problem.
<?php
include 'Images_db_connect.php';
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","75");
if(isset($_FILES['file']['name']) && $_FILES['file']['name']<>""){
$typ = $_FILES['file']['type'];
if($typ == "images/gif" || $typ == "images/png" || $typ == "images/jpeg" || $typ == "images/pgif" || $typ == "images/ppng" || $typ == "images/pjpeg"){
$uploddir = "images/";
$uploadimages = $uploaddir.$_FILES['file']['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadimages)){
$imagename = 'image name';
$caption = 'caption';
$category = 'category_name';
$sql = "INSERT into photos (image_name, caption, image_path, category) VALUES ('$imagename', '$caption', '$uploadimages', '$category')";
mysql_query($sql) or die(mysql_error());
echo "File successfully copied";
}
else{
echo "Copy unsuccessful";
}
}
else{
echo "Incorrect file type";
}
}
else{
echo "No file selected";
}
yes it is due to quots. :)
try using this :-/
if($typ == "images/gif" || $typ == "images/png" || $typ == "images/jpeg" || $typ == "images/pgif || $typ" == "images/ppng" || $typ == "images/pjpeg"){
Try this code
<?php
include 'Images_db_connect.php';
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","75");
if(isset($_POST['Submit'])){
$typ = $_FILES['file']['type'];
if(isset($_FILES['file']['name'])){
if($typ == "images/gif" || $typ == "images/png" || $typ == "images/jpeg" || $typ == "images/pgif ||$typ" == "images/ppng" || $typ == "images/pjpeg"){
$uploddir = "images/";
$uploadimages = $uploaddir.$_FILES['file']['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadimages)){
$imagename = 'image name';
$caption = 'caption';
$category = 'category_name';
$sql = "INSERT into photos (image_name, caption, image_path, category) VALUES ('$imagename', '$caption', '$uploadimages', '$category')";
mysql_query($sql) or die(mysql_error());
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>File Uploaded Successfully!</h1>";
}
mysql_close();
?>
can you mention error on line 12, i mean statement
Line 11 is still wrong $FILES is wrong.
if(isset($_POST['Submit']))
bracket is missing.
correct these two errors if it is still not working tell me or if a error is given please mention it.
Ajax is the solution for your problem.
If you don't want database included then try using google search for your site, I don't know exactly how to put it on the site, but google is your friend. And if you want to use database apache2triad is your friend. download it, install it and then i will lead you further.
please send me the complete code.
thanks a lot langsor it is working now, you are a real legend.
on line 11 $FILES is wrong $_FILES is correct, I will give you details but right now i am in a hurry. See ya later.
thanx langsor
it is not working in both...
set the form action to search.php and set the id of search field to searchterm.
<?php
//connect your server
mysql_connect("localhost","username","password");
//connect your db
mysql_select_db("database");
$term = $_POST['searchterm'];
//in the below line replace tbl with the table name and the column with the column name(you want to search) in that table
$dat = mysql_query("SELECT * FROM tbl WHERE colum LIKE '%$term'") or die(mysql_error());
if($data = mysql_fetch_array($dat))
echo mysql_num_rows($dat)." result(s) found";
do{
echo $data['id']; // replace id with the column you want to display as result
}
while($data = mysql_fetch_array($dat));
}
else{
echo "Sorry no results found :(";
}
?>
use this code in your search.php
also read this
or create sessions variables of county and state and then access them on the page you want to show info. Or else use the method of dickersonka
if(isset($_POST['Submit']))
Where is starting bracket of if body?? :)
$term = $_POST['searchterm'];
$dat = mysql_query("SELECT * FROM tbl WHERE colum LIKE '%$term'") or die(mysql_error());
if($data = mysql_fetch_array($dat))
echo mysql_num_rows($dat)." result(s) found";
do{
// display results with echo
}
while($data = mysql_fetch_array($dat));
}
else{
echo "Sorry no results found :(";
}
It is happening because GB Library, required for using this function is not installed with php on your pc.
It is not working without any error, I am not receiving data in the database, but 1.php is working without ajax but not working with ajax.
Why this code is not working.
<!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=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
var http="";
if(navigator.appName == "Microsoft Internet Explorer"){
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
http = new XMLHttpRequest();
}
function insert(){
document.getElementById('error').innerHTML = "Please wait a second";
var tp = document.getElementById('type').value;
var it = document.getElementById('item').value;
http.open('GET', '1.php?type='+tp+'&item='+it);
http.send = null;
if(http.readyState == 4){
document.getElementById('error').innerHTML = "Data Inserted";
}
}
</script>
<style type="text/css">
<!--
body,td,th {
font-family: Comic Sans MS;
}
-->
</style></head>
<body>
<form action="javascript:insert()" method="get">
<table width="422" cellspacing="3" cellpadding="3">
<tr>
<td width="66">Type</td>
<td width="333"><input name="type" type="text" id="type" /></td>
</tr>
<tr>
<td>Item</td>
<td><input name="item" type="text" id="item" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Insert" onclick="insertg();"/></td>
</tr>
</table>
</form>
<div id="error"></div>
</body>
</html>
And the 1.php
<?php
mysql_connect("localhost","name","password") or die(mysql_error());
mysql_select_db("database")or die(mysql_error());
$type = $_GET['type'];
$item = $_GET['item'];
if($type <> ""){
mysql_query("INSERT INTO likings (type, item) VALUES('$type', '$item')") or die(mysql_error());
}
?>
Instead of exploding and getting the extension use the mime type of the images (images/gif for firefox and safari, images/pgif for IExplorer). Because if you use the method of getting extension then the users will upload any thing after changing the files extension. e.g if a file is doc.docx they will rename it as doc.gif then your code will accept it.
<?php
$typ = $_FILES['file']['type'];
if(isset($FILES['file']['name'])){
if($typ == "images/gif" || $typ == "images/png" || $typ == "images/jpeg" || $typ == "images/pgif ||$typ" == "images/ppng" || $typ == "images/pjpeg"){
$uploddir = "images/";
$uploadimages = $uploaddir.$_FILES['file']['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadimages)){
//insert data or other collected info into db.
}
}
}
?>
Using this code you don't have to worry about getting extension or lowering extension. Just use a check of file size. This code will allow user to upload .jpg, .gif, .png files.
Can you show your code or at least auery?
On your page give same id to all the combo boxes and place [] after their id. On your php page use this.
// I assume the id of all the boxes to be [B]boxes[][/B]
<?php
$boxes = $_POST['boxes'];
foreach($boxes as $k){
echo $k; // will display the selected value of each combo box
// Or what you want to do with the boxes
}
?>
Don't Know exactly, you can google it.
I think that's the only way.
You cannot send email from your localhost, you will need a testing server who supports mail function like, www.111mb.net, they will offer you 400mb space without any charges you can test your mail function there. you Just need to create an account on that site.
I want to know what are the usages of $_SERVER and $_ENV in php. Or for what they can be used.
Means the same what I said. :)
I don't have the code but i can tell you what's the logic behind it i think there is a table in your database in which you are storing your user login or other information, in that table create a new column and update that column on page load with the users name or id on that time. and when you want to display the recent visitors display the 10 results and select them as no one gets repeated.
No one is here to help Me :(
Instead of importing variable values from file why don't you import values from database it will be easy to edit their values from admin panel.
Insted of actual date format use timestamp format returned by php time() function. Then you will be able to use >, < and equal to.
the command used for this purpose is.
mysql_query("UPDATE tbl set field='$value' WHERE id='$id'");
Hello Every one I have a problem in my website that i want to generate the user ids like 0u3012ewd0 as we see on many sites but don't have any idea how to do this.
Please help me in this problem
Thanks alot.
Hey
I host a website for a sports team, theres a nominations page where each member, when logged in, can cast a vote to whoever in the team they want to be captain for a tournament.The Problem is when someone votes i store the id, name and there vote (nothing complicated), however when i want to retreive the data im using this.
if ($_SESSION['loggedin'] == true) { $login_test = true; $getvotes = "SELECT vote FROM `votes` where vote=1"; $collect = mysql_query($getvotes) or die (mysql_error()); $one = mysql_num_rows($collect); $getvotes = "SELECT vote FROM `votes` where vote=2"; $collect = mysql_query($getvotes) or die (mysql_error()); $two = mysql_num_rows($collect); $getvotes = "SELECT vote FROM `votes` where vote=3"; $collect = mysql_query($getvotes) or die (mysql_error()); $three = mysql_num_rows($collect); $getvotes = "SELECT vote FROM `votes` where vote=4"; $collect = mysql_query($getvotes) or die (mysql_error()); $four = mysql_num_rows($collect); }
the variable $one, $two ect.. are just the user id of the person being voted for.
This works fine however, i need to add 32 more candidates. This amount of query would take forever.Is there any way i can collect it as an array the then sort it.
any help would be greatly appreciatedThanks
try this
if ($_SESSION['loggedin'] == true) {
$login_test = true;
$getvotes = "SELECT vote FROM `votes` ORDER by vote ASC";
$collect = mysql_query($getvotes) or die (mysql_error());
$one = mysql_num_rows($collect);
thanks alot MVied and vicky i will try your methods. thanks
Hello I have designed a website in which users can create their account and then add or delete their likings, favoorite songs, what i want is that i want them to be able to arrange their likings by moving up and down. for this i need a procedure for swapping the two rows of table so that they can arrange their liking and songs. Please help me, if you have any other idea please share with me.
Thanks in advance.
Try this code
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="images"; // Database name
$tbl_name="categories"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = mysql_query("SELECT id,category_name FROM categories ORDER BY category_name");
$row = mysql_fetch_array($sql);
?>
<select name="Categor_name">
<?php do{ ?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['category_name']; ?> </option>
<?php } while($row = mysql_fetch_array($sql));?>
</select>
can you help me in getting the time of server instead of users pc.
hey guys,
I have made a database using mysql and php. I have also put in a search option. But what i want is that if the item which is being searched for is not in the databse it should return "Database Not Found". I am not able to execute this.
Please help me on this.
i assume the name of variables to be dat and data
$dat = mysql_query("SELECT * ........."); // the query you used
if(!$data = mysql_fetch_array($dat)){
echo "No results found";
}
try
$dat = mysql_query("SELECT * FROM table");
$data = mysql_fetch_array($dat);
do
{
if($data['text']==""){
continue;
}
echo $data['text'];
}
while($data = mysql_fetch_array($dat));
text is the field which you want to check if it is empty or not.
try
<script language="javascript" type="text/javascript">
function foc(){
document.getElementById('textfieldid').focus();
}
</script>
<body onload="foc();">
I don't know asp but in javascript it looks something like this.
document.placeholder.src = "hello.gif"
Hello,
I have designed a website which let the users create account and use our services, my client asked me to design a page which will show all the online members at that time, the solution i have figured out is that i have create a column in my user table in database, when a user login it changes to 1 and when the user signs out it changes to 0. the problem is if the user close the browser and leave the site without signing out it still shows the user as online. I am using sessions in php please help me how to avoid this.
Thanks in advance
I am recommending it because he is using fetch array before while loop, and then the program comes to loop and encounters the fetch array again and moves to next index in array. that's why if he is using fetch array before loop he should use do while.