0

I’ve tried to send data from the web form to the server.However, inputted data doesn’t connect to the server. I assume I have got error somewhere within mysql connect but not sure where and what I do wrong.

 <!DOCTYPE HTML>

<html>
<head>

<title> Payment details </title>
<link rel="stylesheet" type="text/css" href="./.css">
</head>
<body>
<h3> Your payment was successful! </h3>

<?php 

$firstname = $_POST['name'];
$noaddress = $_POST['noaddress'];
$address = $_POST['address']; 
$postcode = $_POST['postcode'];

print "<p> Your name is $firstname ";
print "and your chosen product will be delivered to the $noaddress $adresss $postcode </p>" ;  

$connect = mysql_connect(“”,“”,“”); 
if (!connect) 
{ die('Connection Failed:'.mysql_error());}
{mysql_select_db(“Payment”, $connect);}


$user_info = "INSERT INTO Payment_details (Name, Card_Number, CVV, Street/House_Name, Postcode) VALUES ('$_POST[name]','$_POST[Card_number]', '$_POST[CVV]','$_POST[address]','$_POST[postcode]')" ; 
if (!mysql_query($user_info, $connect)) { die('Error: ' . mysql_error()); }

echo "Your information was added to the database.";

mysql_close($connect);


    ?>                                                                                                                                           
</body>

</html>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Yalla
  • 9
  • 2
  • please add your code to the question and NOT as a link to a picture on another site. Please make sure that you add the code from the form in addition to the PHP – Professor Abronsius Jun 19 '20 at 12:42
  • FYI - your code is vulnerable to SQL injection so because you are dealing with `payment details` you need to address this as a matter of urgency if this is to go live and work with actual user's details – Professor Abronsius Jun 19 '20 at 12:45
  • What version of PHP are you running? The `mysql_`api was deprecated years ago and removed from PHP 7+ so is that why you cannot connect to the db server? – Professor Abronsius Jun 19 '20 at 12:46
  • I know this is the testing website for my further PG project to find vulnerabilities on the website. I am using PHP version: 7.3.6 DO you know how I should change my code so will be starting to work? Thank you for your help! – Yalla Jun 19 '20 at 12:55
  • NONE of the calls to the old `mysql_*` api will work - turn error reporting on and you will see there are errors. You will need to start using the `mysqli` or `PDO` apis – Professor Abronsius Jun 19 '20 at 12:57
  • Does this answer your question? [Why shouldn't I use mysql\_\* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Dharman Jun 19 '20 at 14:52

0 Answers0