0

I want to send the values from one form to a php file that posts it to a database, then to another php file that posts the same values, how can I do this using php?

This is my php

<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database_name", $con);

$sql="INSERT INTO players (first_name, last_name, company, phone, email, zip, street, city, state, country, reasons, notes, callback)
VALUE
('$_POST[first_name]','$_POST[last_name]','$_POST[company]','$_POST[phone]','$_POST[email]','$_POST[zip]','$_POST[street]','$_POST[city]','$_POST[state]','$_POST[country]','$_POST[reasons]','$_POST[notes]','$_POST[callback]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>

Thank you for your help. (i'm sorry if this is a duplicate, i did not find anything on this)

  • how about after adding the records get the last insert id.. then put that id into a url query string.. then when you get to another page construct a new query using the id that was on the url.. – Sam Teng Wong Jul 16 '15 at 01:01
  • or put the value in a session if thats what you need –  Jul 16 '15 at 01:09
  • Don't use this code in production, especially with those wide open SQL Injection vulnerabilities there. [Read More about SQL Injection Prevention](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) – Darren Jul 16 '15 at 01:27
  • Thank you for your comments. – Alexandru-Valentin Cubaniti Jul 16 '15 at 14:30

1 Answers1

2

In submit.php file

<?php
    $con = mysql_connect("localhost","user","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("database_name", $con);

    $sql="INSERT INTO players (first_name, last_name, company, phone, email, zip, street, city, state, country, reasons, notes, callback)
    VALUE
    ('$_POST[first_name]','$_POST[last_name]','$_POST[company]','$_POST[phone]','$_POST[email]','$_POST[zip]','$_POST[street]','$_POST[city]','$_POST[state]','$_POST[country]','$_POST[reasons]','$_POST[notes]','$_POST[callback]')";

    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    //Add more
    $id = mysql_insert_id();
    mysql_close($con);
header('Location: review.php?id=' . $id);
    ?>

Then get data from review.php file

<?php
  $id = $_GET['id'];
  //SELECT * FROM tbl ... WHERE id = $id
  //Your code
?>
Thi Tran
  • 681
  • 5
  • 11