hello fiend i need help
i have create a lot of pages with same methode and work fine on local but never work online i want know if oder way exist when i have data in form and i clic on submit data insert into table and users directly navigate (go to other)
for exemple add product to cart when user click on add to cart he go directly on cart pages to see whar he has in virtual cart here is part of code item insert the variable insertgoto make problem 'i dont know if you undestund what i mean my english is not good '

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "achat")) {
  $insertSQL = sprintf("INSERT INTO panier (client, article, SKU, quantite) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['client'], "text"),
                       GetSQLValueString($_POST['titre'], "text"),
                       GetSQLValueString($_POST['sku'], "text"),
                       GetSQLValueString($_POST['quantite'], "int"));

  mysql_select_db($database_marketbase, $marketbase);
  $Result1 = mysql_query($insertSQL, $marketbase) or die(mysql_error());

  $insertGoTo = "../myspace/panier.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<form name="achat" method="POST" action="<?php echo $editFormAction; ?>">
        <label for="titre"></label>
        <input name="titre" type="text" id="titre" value="<?php echo $row_X920['titre']; ?>">
        <label for="prix"></label>
        <input name="prix" type="text" id="prix" value="<?php echo $row_X920['prix']; ?>">
        <label for="quantite"></label>
        <input name="quantite" type="text" id="quantite" value="1">
        <input name="client" type="hidden" id="client" value="<?php echo $_SESSION['MM_Username']; ?>">
        <input name="sku" type="hidden" id="sku" value="<?php echo $row_X920['sku']; ?>">
        <input type="submit" name="button" id="button" value="Add to Cart">
        <input type="hidden" name="MM_insert" value="achat">
      </form>

Recommended Answers

All 3 Replies

If I got it right your script works fine on local PC but does not work when on online server? But what does not work - inserting into the database or redirection to another page?

If insertion does not work you have to make sure the connection to the database on the online server has been successfuly established. You are checking for errors already on line 9 but I will suggest you insert some debug code like this:

mysql_select_db($database_marketbase, $marketbase);
// *** DEBUG CODE 1
$res = mysql_query("SHOW TABLES");
while($row = mysql_fetch_row($res)) {
    echo $row[0] . "<br>";
}
// *** the above debug code should display all the tables in your database
// *** if not, something is wrong with the connection

If redirection does not work you should check the path you get generated. Do something like this between lines 15 and 16:

// *** DEBUG CODE 2
die($insertGoTo);
// *** the above code will print out the path for redirection and stop the script
// *** check the path if it is correct

header(sprintf("Location: %s", $insertGoTo));

hi thank you to answer me insert worked fine on server too just before 1 hours dont work too so for the moment i want only solver the redirection i have post for the insert into in the forum, so for the moment just rediraction

 $insertGoTo = "../myspace/order-line.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    echo $insertGoTo;
  }
  die ($insertGoTo);
  header(sprintf("Location: %".$insertGoTo));
}

OK. Please mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.