MySQL PHP Forum
Selecting rows based on a "timeframe" (8 replies)
Hi
I need some help with creating a query.
I have a database with two tables in it: Employees and Vacation
In vacation I add employee_id (int), start (date) and end (date)
I want to be able to select a date (ex. 2012.02.06), and get a list of employees that are NOT on vacation.
This is for a system for placing employees in different departments at selected dates, and to exclude the ones on vacation from being selected.
I need some help with creating a query.
I have a database with two tables in it: Employees and Vacation
In vacation I add employee_id (int), start (date) and end (date)
I want to be able to select a date (ex. 2012.02.06), and get a list of employees that are NOT on vacation.
This is for a system for placing employees in different departments at selected dates, and to exclude the ones on vacation from being selected.
Mysql Spatial DB / constraint or SRID (1 reply)
Hi everyone
First sorry for my poor english.
I try to develop a new php script i made that use a postgres postgis database.
I want use php with mysql (do the same thing with mysql, because all my production/stable servers works with PHP and MySQL, and my knowledge on PostGres PostGIS is poor)
So i can create my databse with these settings:
CREATE TABLE IF NOT EXISTS `zones_inond` (
`gid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`ID` int(11) DEFAULT NULL,
`DATE_IMPOR` varchar(10) DEFAULT NULL,
`RISQUE` varchar(30) DEFAULT NULL,
`RISQUE_Color` varchar(150) DEFAULT NULL,
`the_geom` geometry DEFAULT NULL,
UNIQUE KEY `gid` (`gid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
So now i want to define my SRID and Dimension (with contraint like PostGres) but i can't find how to do it ?
How define SRID on my type geometry ? How to say mysql that geometry field is in Polygon with WGS84 ?
In postgres, i define this (Quantum GIS define for me all settings):
CONSTRAINT "INONDATION_SYNTHESE_explosee_WGS84_pkey1" PRIMARY KEY (gid ),
CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 2),
CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = 4326)
first is spatial index key
second is the dimension
third is the srid (spatial system reference for me WGS84)
First sorry for my poor english.
I try to develop a new php script i made that use a postgres postgis database.
I want use php with mysql (do the same thing with mysql, because all my production/stable servers works with PHP and MySQL, and my knowledge on PostGres PostGIS is poor)
So i can create my databse with these settings:
CREATE TABLE IF NOT EXISTS `zones_inond` (
`gid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`ID` int(11) DEFAULT NULL,
`DATE_IMPOR` varchar(10) DEFAULT NULL,
`RISQUE` varchar(30) DEFAULT NULL,
`RISQUE_Color` varchar(150) DEFAULT NULL,
`the_geom` geometry DEFAULT NULL,
UNIQUE KEY `gid` (`gid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
So now i want to define my SRID and Dimension (with contraint like PostGres) but i can't find how to do it ?
How define SRID on my type geometry ? How to say mysql that geometry field is in Polygon with WGS84 ?
In postgres, i define this (Quantum GIS define for me all settings):
CONSTRAINT "INONDATION_SYNTHESE_explosee_WGS84_pkey1" PRIMARY KEY (gid ),
CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 2),
CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = 4326)
first is spatial index key
second is the dimension
third is the srid (spatial system reference for me WGS84)
Huge tables.... SLOW! :/ (7 replies)
Hello people, I am working with a PHP aplication that works with a big mysql tables. There are 4 big tables (33M, 27M, 8M,4M) in the bd. To insert the information I work with the "load data local.." and very very FAST yes. But now I've to synchronize new data to this tables. Now I can't use this very FAST option. What I am doing is for every row:
update table ... set ... where X and Y and Z (I've created an index of X,Y,Z)
if(affectedRows==0) insert into ... values(...)
I don't know if there is any faster option or if I do a Java program will be faster than with PHP, don't know. I've timed every update/insert and it spends 0.05sec, is too much, with this rate I'll spend 40 days! Do you have some other ideas? thanks a lot! ;)
pd: sorry for my english!
update table ... set ... where X and Y and Z (I've created an index of X,Y,Z)
if(affectedRows==0) insert into ... values(...)
I don't know if there is any faster option or if I do a Java program will be faster than with PHP, don't know. I've timed every update/insert and it spends 0.05sec, is too much, with this rate I'll spend 40 days! Do you have some other ideas? thanks a lot! ;)
pd: sorry for my english!
PHP vs HTML (no replies)
Php script?
Regards,
Jegan
www.shoppingportal.in
Regards,
Jegan
www.shoppingportal.in
Creating a simple PHP forum tutorial (no replies)
############### Code
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="forum_question"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong><? echo $rows['topic']; ?></strong></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><? echo $rows['detail']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> <strong>Email : </strong><? echo $rows['email'];?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
$tbl_name2="forum_answer"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Email</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Answer</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
</tr>
</table></td>
</tr>
</table><br>
<?
}
$sql3="SELECT view FROM $tbl_name WHERE id='$id'";
$result3=mysql_query($sql3);
$rows=mysql_fetch_array($result3);
$view=$rows['view'];
// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
$result4=mysql_query($sql4);
}
// count more value
$addview=$view+1;
$sql5="update $tbl_name set view='$addview' WHERE id='$id'";
$result5=mysql_query($sql5);
mysql_close();
?>
<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="add_answer.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="18%"><strong>Name</strong></td>
<td width="3%">:</td>
<td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td>:</td>
<td><input name="a_email" type="text" id="a_email" size="45"></td>
</tr>
<tr>
<td valign="top"><strong>Answer</strong></td>
<td valign="top">:</td>
<td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Cheap Flights to Miami || Miami Flights
Cheap Flights to Ottawa || Ottawa Flights
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="forum_question"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong><? echo $rows['topic']; ?></strong></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><? echo $rows['detail']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> <strong>Email : </strong><? echo $rows['email'];?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
$tbl_name2="forum_answer"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Email</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Answer</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
</tr>
</table></td>
</tr>
</table><br>
<?
}
$sql3="SELECT view FROM $tbl_name WHERE id='$id'";
$result3=mysql_query($sql3);
$rows=mysql_fetch_array($result3);
$view=$rows['view'];
// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
$result4=mysql_query($sql4);
}
// count more value
$addview=$view+1;
$sql5="update $tbl_name set view='$addview' WHERE id='$id'";
$result5=mysql_query($sql5);
mysql_close();
?>
<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="add_answer.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="18%"><strong>Name</strong></td>
<td width="3%">:</td>
<td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td>:</td>
<td><input name="a_email" type="text" id="a_email" size="45"></td>
</tr>
<tr>
<td valign="top"><strong>Answer</strong></td>
<td valign="top">:</td>
<td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Cheap Flights to Miami || Miami Flights
Cheap Flights to Ottawa || Ottawa Flights
PHP forum tutorial (no replies)
Overview
In this tutorial create 5 files
1. create_topic.php
2. add_topic.php
3. main_forum.php
4. view_topic.php
5. add_answer.php
Steps
1. Create table name "forum_question" and "forum_answer" in database "test".
2. Create file create_topic.php.
3. Create file add_topic. php.
4. Create file main_forum.php
5. Create file view_topic.php
6. Create file add_answer.php
############### Code
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="forum_question"; // 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");
// get data that sent from form
$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['name'];
$email=$_POST['email'];
$datetime=date("d/m/y h:i:s"); //create date time
$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo "<a href=main_forum.php>View your topic</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
Gurgaon restaurants || restaurants in Delhi
In this tutorial create 5 files
1. create_topic.php
2. add_topic.php
3. main_forum.php
4. view_topic.php
5. add_answer.php
Steps
1. Create table name "forum_question" and "forum_answer" in database "test".
2. Create file create_topic.php.
3. Create file add_topic. php.
4. Create file main_forum.php
5. Create file view_topic.php
6. Create file add_answer.php
############### Code
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="forum_question"; // 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");
// get data that sent from form
$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['name'];
$email=$_POST['email'];
$datetime=date("d/m/y h:i:s"); //create date time
$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo "<a href=main_forum.php>View your topic</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
Gurgaon restaurants || restaurants in Delhi
Creating PHP guestbook (no replies)
Overview
In this tutorial create 3 files
1. guestbook.php
2. addguestbook.php
3. viewguestbook.php
Step
1. Create table name "guestbook" in database "test".
2. Create file guestbook.php.
3. Create file addguestbook. php.
4. Create file viewguestbook.php
CREATE TABLE `guestbook` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`comment` longtext NOT NULL,
`datetime` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
############### Code
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="guestbook"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);
//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page
}
else {
echo "ERROR";
}
mysql_close();
?>
Gurgaon restaurants || restaurants in Delhi
In this tutorial create 3 files
1. guestbook.php
2. addguestbook.php
3. viewguestbook.php
Step
1. Create table name "guestbook" in database "test".
2. Create file guestbook.php.
3. Create file addguestbook. php.
4. Create file viewguestbook.php
CREATE TABLE `guestbook` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`comment` longtext NOT NULL,
`datetime` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
############### Code
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="guestbook"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);
//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page
}
else {
echo "ERROR";
}
mysql_close();
?>
Gurgaon restaurants || restaurants in Delhi
Form Validation Using Dreamweaver (no replies)
############### Code
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form action="" method="post" name="form1">
<table width="350" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="105">Full Name</td>
<td width="16">:</td>
<td width="222"><input name="fullname" type="text" id="fullname">
* </td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td><input name="email" type="text" id="email">
* </td>
</tr>
<tr>
<td>Phone number </td>
<td>:</td>
<td><input name="phone_number" type="text" id="phone_number">
* </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</form></td>
</tr>
</table>
At your panel bar open your tag inspector panel (press F9 or window > Tag Inapector)
Select tab "Behaviors"
Select onSubmit
Click on a plus sign then select "Validate Form"
Cheap Flights to Las Vegas || Flights to Las Vegas
Cheap Flights to New York || New York Flights
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form action="" method="post" name="form1">
<table width="350" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="105">Full Name</td>
<td width="16">:</td>
<td width="222"><input name="fullname" type="text" id="fullname">
* </td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td><input name="email" type="text" id="email">
* </td>
</tr>
<tr>
<td>Phone number </td>
<td>:</td>
<td><input name="phone_number" type="text" id="phone_number">
* </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</form></td>
</tr>
</table>
At your panel bar open your tag inspector panel (press F9 or window > Tag Inapector)
Select tab "Behaviors"
Select onSubmit
Click on a plus sign then select "Validate Form"
Cheap Flights to Las Vegas || Flights to Las Vegas
Cheap Flights to New York || New York Flights
PHP Limit upload file size (no replies)
Overview
In this tutorial create 2 files
1. limit_upload.php
2. limit_upload_ac.php
Step
1. Create file limit_upload.php
2. Create file limit_upload_ac.php
3. Create folder "upload" for store uploaded files.
4. CHMOD your upload folder to "777" by using your ftp software(change permission).
############### Code
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="limit_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>File Upload (Limit file size 50 K)</strong></td>
</tr>
<tr>
<td align="center">Select file
<input name="ufile" type="file" id="ufile" size="35" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Create file limit_upload_ac.php
############### Code
<?php
// Define file size limit
$limit_size=50000;
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
{
// Store upload file size in $file_size
$file_size=$HTTP_POST_FILES['ufile']['size'];
if($file_size >= $limit_size){
echo "Your file size is over limit<BR>";
echo "Your file size = ".$file_size;
echo " K";
echo "<BR>File size limit = 50000 k";
}
else {
//copy file to where you want to store file
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Copy Error";
}
}
}
?>
Cheap Flights to New York || New York Flights
Cheap Flights to Las Vegas || Flights to Las Vegas
In this tutorial create 2 files
1. limit_upload.php
2. limit_upload_ac.php
Step
1. Create file limit_upload.php
2. Create file limit_upload_ac.php
3. Create folder "upload" for store uploaded files.
4. CHMOD your upload folder to "777" by using your ftp software(change permission).
############### Code
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="limit_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>File Upload (Limit file size 50 K)</strong></td>
</tr>
<tr>
<td align="center">Select file
<input name="ufile" type="file" id="ufile" size="35" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Create file limit_upload_ac.php
############### Code
<?php
// Define file size limit
$limit_size=50000;
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
{
// Store upload file size in $file_size
$file_size=$HTTP_POST_FILES['ufile']['size'];
if($file_size >= $limit_size){
echo "Your file size is over limit<BR>";
echo "Your file size = ".$file_size;
echo " K";
echo "<BR>File size limit = 50000 k";
}
else {
//copy file to where you want to store file
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Copy Error";
}
}
}
?>
Cheap Flights to New York || New York Flights
Cheap Flights to Las Vegas || Flights to Las Vegas
Select table and row in table from database populated dropdowns (7 replies)
Greetings all,
I have a pretty complicated situation, so let me try and spell it out for you
I have a website where I am creating pages for events I'm hosting using MySQL and php to put the content on my pages. Right now, I'm working on an interface to edit information that I've put into the database already.
In order to edit the information, I have to select one of nine tables from a database and then select the events listed in that table that I've already posted and then edit the fields that I need to change without overwriting what I want to leave alone.
Is it possible to do this with a few pages of php?
Thanks for your help. I know this isn't the easiest of situations,
-Martin
I have a pretty complicated situation, so let me try and spell it out for you
I have a website where I am creating pages for events I'm hosting using MySQL and php to put the content on my pages. Right now, I'm working on an interface to edit information that I've put into the database already.
In order to edit the information, I have to select one of nine tables from a database and then select the events listed in that table that I've already posted and then edit the fields that I need to change without overwriting what I want to leave alone.
Is it possible to do this with a few pages of php?
Thanks for your help. I know this isn't the easiest of situations,
-Martin
echo image from database (2 replies)
I have a database that i connect to just fine. Displays all the data except the image files. I am still new to mysql database and could use some help. This is my script:
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "<table>";
echo "<td><td height='20'></td></tr>";
echo "<td><td><span class='enter-search'>Please enter a search...</span></td></tr>";
exit;
"</table>";
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to database
mysql_connect("localhost","xxx","xxxxxxx");
//database
mysql_select_db("xxxxxxx") or die("Unable to select database");
// Build SQL Query
$query = "SELECT * FROM xxx WHERE xxx like \"%$trimmed%\" or xxx like \"%$trimmed%\" or xxx like \"%$trimmed%\" or smImage like \"%$trimmed%\"
order by xxx, xxx, xxx, smImage";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
echo "<span class='sorry-no-results'>Sorry, your search: "" . $trimmed . "" returned zero results</span> <br/>";
}
if(isset($_GET["s"])) {
$s = $_GET["s"];
}
else {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
/*echo "Results";*/
$count = 1 + $s ;
// display the results returned
while ($row= mysql_fetch_array($result)) {
$xxx = $row["xxx"];
$xxx = $row["xxx"];
$xxx = $row["xxx"];
$smImage = $row['smImage'];
echo "<table>";
echo "<tr><td class='image-col' row-span='4'>" .$row['smImage'] ."</td>";
echo "<td class='col2-header'>" .$row['xxx'] ."</td></tr>";
echo "<tr><td class='col2'>" .$row['xxx'] ."</td></tr>";
echo "<tr><td class='col2'>" .$row['xxx'] ."</td></tr>";
echo "<tr><td class='row-space'></td></tr>";
echo "</table>";
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <span class='prev-next'><a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a></span> ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <span class='prev-next'><a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a></span> ";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo " <span class='show-results'>Showing results $b to $a of $numrows</span>";
?>
Thank you in advance
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "<table>";
echo "<td><td height='20'></td></tr>";
echo "<td><td><span class='enter-search'>Please enter a search...</span></td></tr>";
exit;
"</table>";
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to database
mysql_connect("localhost","xxx","xxxxxxx");
//database
mysql_select_db("xxxxxxx") or die("Unable to select database");
// Build SQL Query
$query = "SELECT * FROM xxx WHERE xxx like \"%$trimmed%\" or xxx like \"%$trimmed%\" or xxx like \"%$trimmed%\" or smImage like \"%$trimmed%\"
order by xxx, xxx, xxx, smImage";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
echo "<span class='sorry-no-results'>Sorry, your search: "" . $trimmed . "" returned zero results</span> <br/>";
}
if(isset($_GET["s"])) {
$s = $_GET["s"];
}
else {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
/*echo "Results";*/
$count = 1 + $s ;
// display the results returned
while ($row= mysql_fetch_array($result)) {
$xxx = $row["xxx"];
$xxx = $row["xxx"];
$xxx = $row["xxx"];
$smImage = $row['smImage'];
echo "<table>";
echo "<tr><td class='image-col' row-span='4'>" .$row['smImage'] ."</td>";
echo "<td class='col2-header'>" .$row['xxx'] ."</td></tr>";
echo "<tr><td class='col2'>" .$row['xxx'] ."</td></tr>";
echo "<tr><td class='col2'>" .$row['xxx'] ."</td></tr>";
echo "<tr><td class='row-space'></td></tr>";
echo "</table>";
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <span class='prev-next'><a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a></span> ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <span class='prev-next'><a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a></span> ";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo " <span class='show-results'>Showing results $b to $a of $numrows</span>";
?>
Thank you in advance
PHP Upload single file (no replies)
Overview
In this tutorial create 2 files
1. upload.php
2. upload_ac.php
Step
1. Create file upload.php.
2. Create file upload_ac.php.
3. Create folder "upload" for store uploaded files.
4. CHMOD your upload folder to "777" by using your ftp software(change permission).
############### Code
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
############### Code
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}
?>
Cheap Flights to New York || New York Flights
In this tutorial create 2 files
1. upload.php
2. upload_ac.php
Step
1. Create file upload.php.
2. Create file upload_ac.php.
3. Create folder "upload" for store uploaded files.
4. CHMOD your upload folder to "777" by using your ftp software(change permission).
############### Code
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
############### Code
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}
?>
Cheap Flights to New York || New York Flights
PHP Multiple files upload (no replies)
Overview
In this tutorial create 2 files
1. multiple_upload.php
2. multiple_upload_ac.php
Step
1. Create file multiple_upload.php
2. Create file multiple_upload_ac.php
3. Create folder "upload" for store uploaded files.
.4. CHMOD your upload folder to "777" by using your ftp software(change permission).
############### Code
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>multiple Files Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Create file multiple_upload_ac.php
############### Code
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];
//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";
///////////////////////////////////////////////////////
// Use this code to display the error or success.
$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
$filesize3=$HTTP_POST_FILES['ufile']['size'][2];
if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "We have recieved your files";
}
else {
echo "ERROR.....";
}
//////////////////////////////////////////////
// What files that have a problem? (if found)
if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}
if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}
if($filesize3==0) {
echo "There're something error in your third file";
echo "<BR />";
}
?>
Cheap Flights to Las Vegas || Flights to Las Vegas
In this tutorial create 2 files
1. multiple_upload.php
2. multiple_upload_ac.php
Step
1. Create file multiple_upload.php
2. Create file multiple_upload_ac.php
3. Create folder "upload" for store uploaded files.
.4. CHMOD your upload folder to "777" by using your ftp software(change permission).
############### Code
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>multiple Files Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Create file multiple_upload_ac.php
############### Code
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];
//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";
///////////////////////////////////////////////////////
// Use this code to display the error or success.
$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
$filesize3=$HTTP_POST_FILES['ufile']['size'][2];
if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "We have recieved your files";
}
else {
echo "ERROR.....";
}
//////////////////////////////////////////////
// What files that have a problem? (if found)
if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}
if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}
if($filesize3==0) {
echo "There're something error in your third file";
echo "<BR />";
}
?>
Cheap Flights to Las Vegas || Flights to Las Vegas
mysql_select_db(): supplied resource is not a valid MySQL-Link (4 replies)
Hi, I am a newbie with PHP and MySQL but have done a fair bit of VB and ASP coding in the past. I am trying to learn the rudiments of updating a MySQL database from a PHP form and copied some code from the w3school site which I have amended. However it always returns "Unable to select database" at the mysql_select_db(): step with the message shown in the header here. The database is definitely called 'test' and the user is definitely called 'webdb'. Can anyone spot what I have done wrong? Many thanks.
<?php $username='webdb'; $password=''; $database='test'; $con=odbc_connect('TestMySQLPHP',$username,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con) or die('Unable to select database'); mysql_close($con); ?>
<?php $username='webdb'; $password=''; $database='test'; $con=odbc_connect('TestMySQLPHP',$username,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con) or die('Unable to select database'); mysql_close($con); ?>
mysql fetch array error expects parameter 1 (1 reply)
Hi Guys,
Fairly new to php....
Trying to fill a dropdown box with names from a database but keep getting this error when I run the code below:
I've no idea how to fix it and tried a few things already to no avail.... any help would be great
<?php
//Connects to the DB ****
$connect = mysqli_connect("localhost","root","","samplerehab") or die("Couldn't Connect!");
$sql = "SELECT * FROM patient";
$result = mysqli_query($connect, $sql) or die(mysqli_error($connect));
$patientdisplay = "<select name =\"patientname\"> <option selected =\"selected\">Please choose a patient</option>";
if (mysqli_num_rows($result) > 0) {
while($row = mysql_fetch_array($result))
{
$pps = $row('pps');
$lname =$row('lname');
$fname =$row('fname');
$patientdisplay .= "<option value=\"".$pps."\">".$lname.",".$fname."</option>";
}
}
$patientdisplay .= "</select>";
?>
Fairly new to php....
Trying to fill a dropdown box with names from a database but keep getting this error when I run the code below:
I've no idea how to fix it and tried a few things already to no avail.... any help would be great
<?php
//Connects to the DB ****
$connect = mysqli_connect("localhost","root","","samplerehab") or die("Couldn't Connect!");
$sql = "SELECT * FROM patient";
$result = mysqli_query($connect, $sql) or die(mysqli_error($connect));
$patientdisplay = "<select name =\"patientname\"> <option selected =\"selected\">Please choose a patient</option>";
if (mysqli_num_rows($result) > 0) {
while($row = mysql_fetch_array($result))
{
$pps = $row('pps');
$lname =$row('lname');
$fname =$row('fname');
$patientdisplay .= "<option value=\"".$pps."\">".$lname.",".$fname."</option>";
}
}
$patientdisplay .= "</select>";
?>
Alternating table row colors (no replies)
Overview
In this tutorial create 1 file
1. alternating_color.php
Step
1. Create table "test_mysql in database "test".
2. Create file alternating_color.php.
Create table "test_mysql"
CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`lastname` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=7 ;
--
-- Dumping data for table `test_mysql`
--
INSERT INTO `test_mysql` VALUES (1, 'Billly', 'Blueton', 'bb5@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (2, 'Jame', 'Campbell', 'jame@somewhere.com');
INSERT INTO `test_mysql` VALUES (3, 'Mark', 'Jackson', 'mark@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (4, 'Linda', 'Travor', 'lin65@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (5, 'Joey', 'Ford', 'fordloi@somewhere.com');
INSERT INTO `test_mysql` VALUES (6, 'Sidney', 'Gibson', 'gibson@phpeasystep.com');
Create file alternating_color.php
View In Browser
############### Code
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select databse
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Define $color=1
$color="1";
echo '<table width="400" border="1" align="center" cellpadding="2" cellspacing="0">';
while($rows=mysql_fetch_array($result)){
// If $color==1 table row color = #FFC600
if($color==1){
echo "<tr bgcolor='#FFC600'>
<td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td>
</tr>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr bgcolor='#C6FF00'>
<td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo '</table>';
mysql_close();
?>
Gurgaon restaurants || restaurants in Delhi
Flights to New York || New York Flights
In this tutorial create 1 file
1. alternating_color.php
Step
1. Create table "test_mysql in database "test".
2. Create file alternating_color.php.
Create table "test_mysql"
CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`lastname` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=7 ;
--
-- Dumping data for table `test_mysql`
--
INSERT INTO `test_mysql` VALUES (1, 'Billly', 'Blueton', 'bb5@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (2, 'Jame', 'Campbell', 'jame@somewhere.com');
INSERT INTO `test_mysql` VALUES (3, 'Mark', 'Jackson', 'mark@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (4, 'Linda', 'Travor', 'lin65@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (5, 'Joey', 'Ford', 'fordloi@somewhere.com');
INSERT INTO `test_mysql` VALUES (6, 'Sidney', 'Gibson', 'gibson@phpeasystep.com');
Create file alternating_color.php
View In Browser
############### Code
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select databse
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Define $color=1
$color="1";
echo '<table width="400" border="1" align="center" cellpadding="2" cellspacing="0">';
while($rows=mysql_fetch_array($result)){
// If $color==1 table row color = #FFC600
if($color==1){
echo "<tr bgcolor='#FFC600'>
<td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td>
</tr>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr bgcolor='#C6FF00'>
<td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo '</table>';
mysql_close();
?>
Gurgaon restaurants || restaurants in Delhi
Flights to New York || New York Flights
Encrypting Password using md5() function (no replies)
Syntax
$password="123456";
md5($password);
Use md5(); to encrypts password to make it more secure
Overview
Look at these two databases, it's the same person and same info, the first one we don't encrypt his password but the second one we encrypted his password
when you encryte "john856" using this code, you'll see this result
"ad65d5054042fda44ba3fdc97cee80c6" This is not a random result, everytime you encrypt the same password you will get the same result.
$password="john856";
$encrypt_password=md5($password);
echo $encrypt_password;
Example - Login
This is an example Login with encrypted password but don't forget to encrypt password and insert into database in sign up process.
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// encrypt password
$encrypted_mypassword=md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);
You can learn to create login system here
Cheap Flights to New York || New York Flights
Cheap Flights to Las Vegas || Flights to Las Vegas
$password="123456";
md5($password);
Use md5(); to encrypts password to make it more secure
Overview
Look at these two databases, it's the same person and same info, the first one we don't encrypt his password but the second one we encrypted his password
when you encryte "john856" using this code, you'll see this result
"ad65d5054042fda44ba3fdc97cee80c6" This is not a random result, everytime you encrypt the same password you will get the same result.
$password="john856";
$encrypt_password=md5($password);
echo $encrypt_password;
Example - Login
This is an example Login with encrypted password but don't forget to encrypt password and insert into database in sign up process.
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// encrypt password
$encrypted_mypassword=md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);
You can learn to create login system here
Cheap Flights to New York || New York Flights
Cheap Flights to Las Vegas || Flights to Las Vegas
Simple Ad Rotation Script (no replies)
Overview
In this script (very easy script), we have 3 ads for rotation
first ad we want it to display 70%
second ad we want to display 20%
and the last one we want to display 10%
What to do
1. Random number 1-100
- if result = 1-70 (we have opportunity to display ad 1, 70%)
- if result = 71-90 (we have opportunity to display ad 2, 20%)
- if result = 91-100 (we have opportunity to display ad 3, 10%)
Example
In this script use rand(1, 100); to random number between 1 -100 and keep result in variable name "$result_random" if result = 85 ad 2 will display.
############### Code
<?php
// random number 1 - 100
$result_random=rand(1, 100);
// if result less than or equal 70, display ad 1 (70%)
if($result_random<=70){
echo "Display ad1";
}
// if result less than or equal 90, display ad 2 (20%)
elseif($result_random<=90){
echo "Display ad2";
}
// if result less than or equal 100, display ad 3 (10%)
elseif($result_random<=100){
echo "Display ad3";
}
?>
Flights to Perth || Cheap Flights to Perth
Cheap Flights to Las Vegas || Flights to Las Vegas
In this script (very easy script), we have 3 ads for rotation
first ad we want it to display 70%
second ad we want to display 20%
and the last one we want to display 10%
What to do
1. Random number 1-100
- if result = 1-70 (we have opportunity to display ad 1, 70%)
- if result = 71-90 (we have opportunity to display ad 2, 20%)
- if result = 91-100 (we have opportunity to display ad 3, 10%)
Example
In this script use rand(1, 100); to random number between 1 -100 and keep result in variable name "$result_random" if result = 85 ad 2 will display.
############### Code
<?php
// random number 1 - 100
$result_random=rand(1, 100);
// if result less than or equal 70, display ad 1 (70%)
if($result_random<=70){
echo "Display ad1";
}
// if result less than or equal 90, display ad 2 (20%)
elseif($result_random<=90){
echo "Display ad2";
}
// if result less than or equal 100, display ad 3 (10%)
elseif($result_random<=100){
echo "Display ad3";
}
?>
Flights to Perth || Cheap Flights to Perth
Cheap Flights to Las Vegas || Flights to Las Vegas
if else statement not working (2 replies)
Greetings all.
I'm having trouble with this password confirmation on a php form.
here's the code:
if ($loginpass = 'password') {
echo "Payment Status has been sucessfully updated. Please wait to be redirected to the Application Status Page.";
echo "<meta http-equiv=\"refresh\" content=\"3;URL=../OnlineEntryTYVM.php\">";
} else {
echo "Incorrect Password. Please Try Again. Changes Will Not Be Made";
echo "<meta http-equiv=\"refresh\" content=\"3;URL=PaymentVerify.php\">";
}
in the form, $loginpass = $_POST['password']; where 'password' is the column in the database i have with the password for my form stored. For some reason, when I put in the incorrect password to test the thing, it redirects me to the successful page and echos the successful meta, not the one from the else statement. However, it does not change the information if the password isn't correct, so its just echoing the wrong page.
Thanks for the help,
-Martin
I'm having trouble with this password confirmation on a php form.
here's the code:
if ($loginpass = 'password') {
echo "Payment Status has been sucessfully updated. Please wait to be redirected to the Application Status Page.";
echo "<meta http-equiv=\"refresh\" content=\"3;URL=../OnlineEntryTYVM.php\">";
} else {
echo "Incorrect Password. Please Try Again. Changes Will Not Be Made";
echo "<meta http-equiv=\"refresh\" content=\"3;URL=PaymentVerify.php\">";
}
in the form, $loginpass = $_POST['password']; where 'password' is the column in the database i have with the password for my form stored. For some reason, when I put in the incorrect password to test the thing, it redirects me to the successful page and echos the successful meta, not the one from the else statement. However, it does not change the information if the password isn't correct, so its just echoing the wrong page.
Thanks for the help,
-Martin
