Tuesday, April 30, 2013

Submitting a date to Database from datepicker || PHP mysql insert date format



$date = mysql_real_escape_string($_POST['date']);
$new_date = date('Y-m-d',strtotime($date));

$sql="INSERT INTO some_table (date)
VALUES
('$new_date')";

Example 2 

//get the correct format
$new_date = date('Y-m-d',strtotime($_POST['date']));

//then you can insert that date

$insert = 'INSERT INTO some_table (field1) VALUES("'.mysql_real_escape_string($new_date).'")';

Tuesday, April 23, 2013

php check if record already exists




<?php

mysql_connect('localhost', 'admin', 'abc456');
mysql_select_db('web');
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>
<?php

$suid = $_SESSION['userid'];
$check = mysql_query("SELECT id FROM arts WHERE id = '$suid'");
$chid = mysql_fetch_array( $check );

if ($chid == true)
   {
  header('Location: userprofile.php');
   }
  else {
 header('Location: edit-profile.php');
       }
?>

Monday, April 22, 2013

jquery ajax form submit loading image

1. Insert this code below head tag

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>

2. And Form code change like this

<form action="" method="post" name="register">
<input name="submit" type="submit" value="register" style="width:100px;" onclick="$('#loading').show();">
</form>
<div id="loading" style="display:none;"><img src="ajax_progress2.gif" alt="" /></div>

Example:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
</head>
<body>
<br>
<form action="" method="post" name="register">
<label>username:</label><input name="name" type="text"><br>
<label>password:</label><input name="password" type="password"><br>
<label>email:</label><input name="email" type="text"><br>
<input name="submit" type="submit" value="register" style="width:100px;" onclick="$('#loading').show();">
</form>
<div id="loading" style="display:none;"><img src="ajax_progress2.gif" alt="" /></div>
</body>
</html>

Ajax loader images





Thursday, April 18, 2013

How to get the word of a sentence in PHP?


Example 1

<?php

$pizza  "piece1 piece2 piece3 piece4 piece5 piece6";

$pieces explode(" "$pizza);
echo 
echo $pieces[0]// piece1
echo $pieces[1]// piece2
?>

output:
piece1 piece2

Example 2

<?php
$myvalue = 'Test me more';
$arr = explode(' ',trim($myvalue));
echo $arr[1]; // will print Test
?>
output: me