0

i do not know why the following code will not work for inserting data into mysql.

if (!$link = mysql_connect('server', 'user', 'password')) {
    echo '700';
    exit;
}

if (!mysql_select_db('vendors', $link)) {
    echo '701';
    exit;
}
$sql2 = "INSERT INTO transactions (TransID, payment_status, last_name, first_name, payer_email, address_name, address_state, address_zip, address_country, verify_sign, payment_gross, ipn_track_id, business, reciver_email) VALUES ('kris', 'kris', 'kris', 'kris', 'kris','kris', 'kris', 'kris', 'kris', 'kris', 'kris', 'kris', 'kris', 'kris')";

$result2 = mysql_query($sql2, $link);

What is wrong with the code? php is giving no errors.

4
  • I am unable to echo errors as this is part of a paypal ipn system im just storing the data paypal sends into a script before the ipn process it Commented Feb 26, 2015 at 5:21
  • 1
    you are passing 'kris' in TransID field, is it varchar or int? Commented Feb 26, 2015 at 5:42
  • Use error_reporting(E_ALL); to see what error occurs?. Also check the column's datatype for each field. Commented Feb 26, 2015 at 5:44
  • use mysqli or PDO, PHP will remove mysql at the end of the year. Commented Feb 26, 2015 at 5:44

3 Answers 3

2

Please try not to use mysql_connect instead use mysqli_connect or PDO_MySQL read this

Also use die to find if there is any errors in your code

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

Otherwise(recommended way)-

Procedural style

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO Persons (firstname, lastname, email)
VALUES ('Happy', 'John', '[email protected]')";

if (mysqli_query($conn, $sql)) {
    echo "New Person created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);

MySQLi Object-oriented style

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO Persons (firstname, lastname, email)
VALUES ('Happy', 'John', '[email protected]')";

if ($conn->query($sql) === TRUE) {
    echo "New Person created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
Sign up to request clarification or add additional context in comments.

Comments

0

Try changing this

 $result2 = mysql_query($sql2, $link);

Into this

$result2 = mysql_query($sql2, $link)or die(mysql_error());

Comments

0

You have to write the code like below to get the errors in your code

$result = mysql_query($sql2,$link) or die(mysql_error());

this or die(mysql_error()) will give you errors in query

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.