...

Hi! I’m Starx

experienced Software Developer. And this is my blog
Start Reading About me
Blog Page
May 18, 2010

How can I check data has been inserted successfully?

Question by nectar

I have two insert statements. The second one will be executed only after successful execution of first one. What I would like to do is:

$sqlone="Insert into .....";
$sqltwo="Insert into.....";

If (mysql_query($sqlone))
{
   If (mysql_query($sqltwo))
   {
      Show message Data inserted in both tables.
   }
}

Answer by Starx

Try this

$query1 = '...';
$query2 = '...';
$query3 = '...';
if(mysql_query($query1)) {
     if(mysql_query($query2)) {
          if(mysql_query($query3)) {
              echo "success";
          }
          else { echo "error"; }
     }
     else { echo "error"; }
}
else { echo "error"; }
Read more

How can I use a php array in a mysql search query?

Question by ThinkingInBits

I was going to use the scuttle solution on: http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html for handling searches on my website. I was wondering how I could take the search input from a user and turn it into a single query.

For instance, let’s say a user inputted ‘blue dogs’ in their search query… How could I dynamically update the query to include (‘blue’, ‘dogs’) in union and intersection queries?

Answer by Sarfraz

You can do like:

$search_string = implode(',', $search_array);

Now in your query you can use the IN clause:

$query = "select * from table where field IN ('".$search_string."')";

Answer by Starx

for example your user input is “blue dogs”, then on the page

$searchstring = "blue dogs"; // or fetch the input
$arr = explode(" ",$searchstring); //this is explode the text by every "space" character

you have the user inputed string in array $arr now, now use it in query like you usually do

Read more

Looking for a jquery plugin to serialize a form to an object

Question by John

I’m looking for a jQuery function or plugin that serializes form inputs to an object using the naming convention for deep-serialization supported by param() in jQuery 1.4:

<form>
  <input name="a[b]" value="1"/>
  <input name="a[c]" value="2"/>
  <input name="d[]" value="3"/>
  <input name="d[]" value="4"/>
  <input name="d[2][e]" value="5"/>
</form>

$('form').serializeObject(); // { a: { b:"1",c:"2" }, d: ["3","4",{ e:"5" }] }

Prototype’s Form.serialize method can do exactly this. What’s the jQuery equivalent? I found this plugin but it doesn’t follow this naming convention.

Answer by John

Since there didn’t seem to be any existing libraries that accomplished what I was seeking, I mashed up bits from a couple of existing libraries that did similar things:

  • The jQuery.deparam function from jQuery BBQ
  • The jQuery.serializeObject function mentioned in the question.

Both are by Ben Alman. Thanks, Ben!

The result: http://gist.github.com/405448

Answer by Starx

try using jquery form plugin. I haven’t tested it, but I think it will fix your problem

http://jquery.malsup.com/form/

Read more
May 17, 2010

Results page in other window

Question by xRobot

I have this simple form:

<form method="post" action".">
<input type="text" name="title">
<input type="submit" name"send">
</form>

I want that when a user click on submit, then will be open another window of browser with the results. Is it possible ?

Answer by andr

If you just need to open a new window:

<form method="post" action="..." target="_blank">
...

If you want a popup or lightbox or anything scripty:

<form method="post" action="..." onsubmit="yourFunction()">

Answer by Starx

Use this

<form method="post" action"thepagetodisplay.php">
<input type="text" name="title" id="title">
<input type="submit" name"send">
</form>

on thepagetodisplay.php

extract($_POST);
echo $title;
Read more

output all data from db to a php page

Question by Sarit

I’m a real beginner with PHP & mysql.
Just for studying and for a simple example at school I would like to work this simple query and possibly output all the rows (or maybe even one) to a very basic output on a php page:

<?php
$user= "root";
$host="localhost";
$password="";
$database = "PetCatalog";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn’t connect to server");
$query = "SELECT * FROM Pet";
$result = mysql_query($cxn,$query) or die ("Couldn’t execute query.");
$row = mysqli_fetch_assoc($result);
echo "$result";
?>

this is the error message i’ve been getting:

Warning: mysql_query() expects parameter 1 to be string, object given in C:xampplitehtdocsmyblogquery.php on line 18
Couldn’t execute query.

What should I do?
Thanks!

Answer by Starx

<?php
$user= "root";
$host="localhost";
$password="";
$database = "PetCatalog";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn’t connect to server");
$query = "SELECT * FROM Pet";
$result = mysql_query($query) or die ("Couldn’t execute query.");
while($row = mysqli_fetch_array($result)) {
          print_r($row);
}
?>

This should solve your problem

Read more
May 12, 2010

execute javascript method after completing code behind method?

Question by James123

I want execute below callback() method after completion of document.getElementById('btnDownload').click(); method . Now callback()executing immediatly. I want wait “Click()” process done then Execute callback(); method.

function LoadPopup() {
        //  find the popup behavior
        this._popup = $find('mdlPopup');
        // show the popup
        this._popup.show();

        // synchronously run the server side validation ...
        document.getElementById('btnDownload').click();
       callback();         
    }

 function callback() {
        this._popup = $find('mdlPopup');
        //  hide the popup
        this._popup.hide();
        alert("hi");

}

Answer by Starx

Your question is not clear. But I will give you a example.

For example, you wan to load a page by clicking on a image then after the page load is complete you want to do something you can something like this

$('#buttonid').click(function() {
    //this is the callback function of click event
    //if you want some other callback functions then you need something like this
    $("#somediv").load("page.php", function() {
       //callback function code of .load event
       alert('page loaded');
       });
 });

What you are asking is to have a callback function inside the default callback function of click event and a bit impossible from my point of view.

Read more
...

Please fill the form - I will response as fast as I can!