0

I'm building an application that have to add a row in a MyPHP database with some data, included for each row an always different, small JPEG image. At the moment it is structured like this:

JavaScript

function fn_addrow() {
    document.write('<form action="ADVBKMNGR-EventClass_MANAGE.php?Mode=ADD" method="POST" enctype="multipart/form-data">')
    document.write('<table width="500"><th width="150"></th><th width="350"></th>')
    document.write('<TR>')

    // Form building

    document.write('<input type="submit" value="Ok proceed">')
    document.write('</form>')
}

PHP

elseif($WorkMode == 'ADD'):
    $ID_ev = $_POST[ID_evcls];
    $ID_ds = $_POST[Desc];

    // Write all the data in a new row
    $query='INSERT INTO '.$db_tabscelta.' (`Cod_App`, `ID_eventclass`, `Descrizione`, `Active`, `Logo_Eve`) VALUES ("'.$Station_ID.'","'.strtoupper($ID_ev).'","'.$ID_ds.'","1","'.mysql_real_escape_string($datimmagine).'")';
    $result = mysql_db_query("AdVisual_02_", $query ,$connessione); 
    unlink($ID_logo);
    imagedestroy($ID_logo);

The call at the PHP side works, the record is added, but my problem is that at the end I remain on the PHP page, while I would like to return to the calling page and redisplay the whole table. And, the address of the PHP is displayed in the user screen, and I would NOT like this at all.

Does anybody have suggestions?

Very important: I've tried the way with the XMLHttpRequest() command. It's fine, but I'm not able to upload the image at all.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
  • Please use the `if() { ... } elseif() { ... }` syntax in your PHP. The `:` colon syntax will make your code very hard to read – Bojangles Mar 24 '13 at 12:11
  • You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Mar 24 '13 at 12:47

2 Answers2

0

I think this for what you searching for form that submits through ajax even file upload is present

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

0

Store the value of

$_SERVER['HTTP_REFERER']

Once you land on page. This will give you the URL

After finishing the job redirect to this URL

Confused
  • 1,602
  • 15
  • 25