Confirmation will not connect to db

#1
<?php
// Confirmation page setup
//Create connection
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$telephone = $_POST['telephone']; 

$con = mysql_connect("localhost", "test2", "123", "CIT647StudentsConcertsProfiles"); //'mysql.default_host', 'mysql_user', 'mysql_password'

//check connection
if (!$con) {
die ("Connection failed: " . mysql_error());
}
echo "Connected successfully test2.";

// selected database
mysql_select_db("CIT647StudentsConcertsProfiles" . $con);

//Create Random Unique ID for RowNum field in Database Table
$pattern ="1234567890";
$rownum = $pattern{rand (0,10)};
for ($i = 1; $i < 10; $i++)
{
$rownum = $pattern{rand(0,10)};
}

// sql to create test table
$sql = "INSERT INTO CIT647StudentsConcertProfilesTable (rownum, firstname, lastname, telephone) 
  VALUES ($rownum, '$_POST[firstname]', '$_POST[lastname]', $_POST[telephone])";

//store from names in variables
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$telephone = $_POST['telephone'];

if (myql_query($sql . $con)) {
  echo "Records added successfully test2.";  
} else {
  echo "ERROR: Not able to execute $sql. " . mysql_error($con);  
}

//close the connection
mysql_close($con);

?>

<html>
  <head>
    <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
  <link rel="stylesheet" href="assets/css/main.css" />
  <!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
  <!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
  
  </head>
  <body>
    <center><img src="images/Pic01Main.jpg" alt="SNHU-a-Palooza The Concert" /></center>  
  
<!-- create confirmation page -->
<br><center><h1>We've received your information</h1></center>
<br>
<center>Thank you for submitting your information for the concert.<br>
Make sure to print a copy of the following information for your records.<br>
a ticket for you when you arrive at the ticket booth.<br>
<br>
Your ticket confirmation number is as follows:<br>
<br>

  <?php
  
  echo "Confirmation Number: " . $rownum . "<br>";
  echo "First Name: " . $firstname . "<br>";
  echo "Last Name: " . $lastname . "<br>";
  echo "Telephone Number: " . $telephone . "<br>"; 
   ?>
  
  <br>
  <input type="button"
         onClick="window.print()"
         value = "Print This Page" />
  <br> <a href=index.html>Return to the homepage</a></center>
  </body>
</html>
#2

This is obsolete and dangerous code that has been completely removed from PHP You need to use PDO.

1 Like
#3

What is pdo? I don’t know how to use pdo

#4

https://phpdelusions.net/pdo

2 Likes
#5

PDO should be what you are using.

And for future reference, a code dump and a title is not sufficient for a post.