Here is what I have for my php coding.
<?php
$USER_NAME = ' ';
$USER_PASSWORD = ' ';
$DB_SERVER = " ";
$DB_NAME = $USER_NAME."_db";
$conn = mysqli_connect($DB_SERVER, $USER_NAME, $USER_PASSWORD, $DB_NAME);
$result = mysqli_query($conn," SELECT * FROM employee,workson where workson.ESSN = employee.SSN and workson.Projnum ='" . $_GET["PNO"] . "'");
$notincluded = mysqli_query($conn, "SELECT SSN, FName, Lname FROM employee where NOT EXISTS (SELECT * FROM workson WHERE employee.SSN = workson.ESSN and workson.Projnum ='" . $_GET["PNO"] . "')") ;
if (!$conn) {
echo "Could not connect: ";
echo mysqli_connect_error(); }
?>
<table border = "1">
<b>Employee List: <b>
<td>Project Number</td>
<td>SSN</td>
<td>First Name</td>
<td>Last Name</td>
<td>Working Hours</td>
<td>Delete</td>
<td>Update</td>
</tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["Projnum"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["SSN"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["FName"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["Lname"]; ?></td>
<td style = "text-align:center; vertical-align: middle;"> <?php echo $row["NoHours"]; ?> </td>
<td>Delete</td>
<td>Update Hours</td>
</tr>
<?php
$i++;
}
?>
</table>
<br>
<br>
<form method=POST action="http://mkimas.student.ust.hk/cgi-bin/mini_project_5.php">
<b> Employee not included : </b>
<?php
$notincluded = mysqli_query($conn,
"SELECT SSN, FName, Lname FROM employee where NOT EXISTS (SELECT * FROM workson WHERE employee.SSN = workson.ESSN and workson.Projnum ='" . $_GET["PNO"] . "')") ;
$employees = mysqli_fetch_all($notincluded);
$projnum = $_GET["PNO"];
print("<select name='Employees' id='employees'>");
foreach($employees as $employee){
//You can use the index 0, which corresponds with the first selected column in query
print("<option value='$employee[0]'>$employee[0]</option>");
}
print("</select>")
?>
<br>
Input the amount of hours and which project number new employee worked on: <br>
Hours: <input name=hours type =text> <br>
<input type=submit value="Submit">
</form>
For the second part of my php, a selection list of employees not included in the table above is printed. Then, I have the php file that has a SQL query that inserts the not included employee.
<?php
echo "Start \n";
echo "<hr>";
$USER_NAME = " ";
$USER_PASSWORD = " ";
$DB_SERVER = " ";
$DB_NAME = $USER_NAME."_db";
$ESSN = $_POST["Employees"];
$Projnum = $_POST["projnum"];
$NoHours = $_POST["hours"];
$conn = mysqli_connect($DB_SERVER, $USER_NAME, $USER_PASSWORD, $DB_NAME);
if (!$conn) {
echo "Could not connect: ";
echo mysqli_connect_error(); }
$sql="insert into workson(ESSN, Projnum, NoHours) values('$ESSN', '$Projnum', '$NoHours')";
$result=mysqli_query($conn,$sql);
if($result){
echo "insert success"; }
else{
echo "insert fail"; }
mysqli_close($conn);
?>
Somehow, my coding always outputs "insert fail". What might be the problem?
Have you tried :
$sql="INSERT INTO workson(ESSN, Projnum, NoHours) VALUES (".$ESSN.", ".$Projnum.", ".$NoHours.")";
Could you dump the result ?
Regards,
Related
I have a group project for my web programming class, we are creating a simple music website and have created a database using phpmyadmin for each genre, we have a add to playlist button that should add the selected song to the empty database but we can not figure out why it is not working.
<div id="navbar">
<table>
<tr>
<td>
<font size="6"><b>Home</font>
</td>
<td>
<font size="6"><b>Pop</font>
</td>
<td>
<font size="6"><b>Hip-Hop</font>
</td>
<td>
<font size="6"><b>Rock</font>
</td>
<td>
<font size="6"><b>Country</font>
</td>
<td>
<font size="6"><b>Alternative</font>
</td>
<td>
<font size="6"><b>My Playlist</font>
</td>
</tr>
</table>
</div>
<!-- End of navbar div -->
<br>
<!-- PHP code here to display the appropriate databse table (genre/playlist) -->
<?php
$dbc = mysqli_connect("localhost", "root", "", "Music Website") or die("Bad Connect:" . mysqli_connect_error());
$sql = "SELECT * FROM AltMusic";
$result = mysqli_query($dbc, $sql) or die("Bad Query: $sql");
echo "<table id = 'database'>";
echo "<tr id = 'tableHead'>
<td class = 'titleCells'>Title</td>
<td class = 'titleCells'>Artist</td>
<td class = 'titleCells'>Album</td>
<td class = 'titleCells'>YouTube</td>
<td class = 'titleCells'>Genre</td>
<td class = 'titleCells'>Add to Playlist</td>
</tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td class = 'cells'>{$row['Title']}</td>
<td class = 'cells'>{$row['Artist']}</td>
<td class = 'cells'>{$row['Album']}</td>
<td class = 'cells'><a href='" . $row['YouTube'] . "'target = _blank>" .
$row['YouTube'] . "</a></td>
<td class = 'cells'>{$row['Genre']}</td>
<td id = 'add' class = 'cells'>" ?>
<form action='' method='POST'>
<input type='submit' name='submit' value="+"/>
</form><?
if (isset($_POST['submit'])) {
$sql2 = "INSERT INTO Playlist(`ID`, `Title`, `Artist`, `Album`, `YouTube`,
`Genre`)
SELECT `ID`, `Title`, `Artist`, `Album`, `YouTube`, `Genre`FROM Pop
WHERE ";
}
echo "</td>
</tr>";
}
echo "</table>";
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
echo "<br> Title: " . $row['Title'] . " Artist: " . $row["Artist"] . " Album: " .
$row["Album"] . "YouTube: " . $row["YouTube"] . "Genre: " . $row["Genre"] . "Add to Playlist: " .
$row["Add to Playlist"] . "<br>";
}
} else {
echo "0 results";
}
$dbc->close();
?>
<!-- Bookmark to allow uesrs to return to the top of the page once at the bottom -->
<a href=#top>
<font size="6">Back to top</font>
</a>
I have tried to use isset($_POST("") to add it but it can only figure out how to fetch the entire array instead on one single selection.
Please consider that I, as well as all of the members in my groups are fairly new to web programming. If I have not posted correctly or not given specific enough ideas about what I am trying to do please let me know in a considerate way. Thank you for any help you can provide.
I am having an issue where I insert the record and it gets inserted also email part works but when confirmation page shows it only shows last record in the array 3 times. I figured putting it in for loop well show all the records. I am not sure what I am doing wrong will keep figuring out the issue.
process_insert.php
<html>
<head>
<title></title>
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "blog_samples";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$rows_count = count($_POST["name"]);
$message = '';
for($i=0;$i<$rows_count;$i++){
// PREVENTING SQL INJECTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$employee_name = mysqli_real_escape_string($conn,$_POST["employee_name"][$i]);
$name = mysqli_real_escape_string($conn,$_POST["name"][$i]);
$code = mysqli_real_escape_string($conn,$_POST["code"][$i]);
$quantity = intval($_POST["quantity"][$i]);
$price = mysqli_real_escape_string($conn,$_POST["price"][$i]);
$sql = "INSERT INTO order_table ( employee_name, name, code, quantity, price)
VALUES ('$employee_name', '$name', '$code', '$quantity', '$price')";
$query = mysqli_query($conn,$sql);
if(mysqli_affected_rows($conn)>0) {
$message .=
"employee_name: " . $employee_name . "
" ."name: ". $name ."
". "code: " . $code . "
" ."quantity: ". $quantity . "
". "price: " . $price . "";
}
}
if ( ! empty($message)) {
$to = "xgrh#gmail.com";
$subject = "Supplies";
$headers = "From: user#gmail.com";
mail($to,$subject,$message,$headers);
}
?>
<h1 align="center">Supply Request Confirmation</h1>
<p align="center">Thank you, <?php echo $employee_name; ?><br><br>
Your request has been sent.
Please print this page out for your copy.</p>
<div align="center">
<h2>Request Information</h2>
</div>
<table style="width: 45%" align="center">
<tr>
<td class="style">Date Request: <?php $date = new DateTime();
echo $date->format('m/d/Y H:i:s') . "\n"; ?></td>
</tr>
<?php for($i=0;$i<$rows_count;$i++){?>
<tr>
<td class="style">name: <?php echo $name; ?></td>
</tr>
<tr>
<td class="style"> code: <?php echo $code; ?></td>
</tr>
<tr>
<td class="style"> Quantity: <?php echo $quantity; ?></td>
</tr>
<tr>
<td class="style"> price: <?php echo $price; ?></td>
</tr>
<?php } ?>
</table>
<div align="center"><button onClick="window.print()">Print this page</button></div>
</body>
</html>
This occurs because the variables $name, $code, $amount, and $price have the last values of your $_POST. You can use the $_POST values of the last cycle or create a variable with this values.
Try this instead:
<html>
<head>
<title></title>
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "blog_samples";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$rows_count = count($_POST["name"]);
$message = '';
$data = array();
for($i=0;$i<$rows_count;$i++){
// PREVENTING SQL INJECTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$employee_name = mysqli_real_escape_string($conn,$_POST["employee_name"][$i]);
$name = mysqli_real_escape_string($conn,$_POST["name"][$i]);
$code = mysqli_real_escape_string($conn,$_POST["code"][$i]);
$quantity = intval($_POST["quantity"][$i]);
$price = mysqli_real_escape_string($conn,$_POST["price"][$i]);
array_push($data, array(
'employee_name' => $employee_name,
'name' => $name,
'code' => $code,
'quantity' => $quantity,
'price' => $price,
));
$sql = "INSERT INTO order_table ( employee_name, name, code, quantity, price)
VALUES ('$employee_name', '$name', '$code', '$quantity', '$price')";
$query = mysqli_query($conn,$sql);
if(mysqli_affected_rows($conn)>0) {
$message .=
"employee_name: " . $employee_name . "
" ."name: ". $name ."
". "code: " . $code . "
" ."quantity: ". $quantity . "
". "price: " . $price . "";
}
}
if ( ! empty($message)) {
$to = "xgrh#gmail.com";
$subject = "Supplies";
$headers = "From: user#gmail.com";
mail($to,$subject,$message,$headers);
}
?>
<h1 align="center">Supply Request Confirmation</h1>
<p align="center">Thank you, <?php echo $employee_name; ?><br><br>
Your request has been sent.
Please print this page out for your copy.</p>
<div align="center">
<h2>Request Information</h2>
</div>
<table style="width: 45%" align="center">
<tr>
<td class="style">Date Request: <?php $date = new DateTime();
echo $date->format('m/d/Y H:i:s') . "\n"; ?></td>
</tr>
<?php foreach ($data as $value) {?>
<tr>
<td class="style">name: <?php echo $value['name']; ?></td>
</tr>
<tr>
<td class="style"> code: <?php echo $value['code']; ?></td>
</tr>
<tr>
<td class="style"> Quantity: <?php echo $value['quantity']; ?></td>
</tr>
<tr>
<td class="style"> price: <?php echo $value['price']; ?></td>
</tr>
<?php } ?>
</table>
<div align="center"><button onClick="window.print()">Print this page</button></div>
</body>
</html>
I am in the process of converting my old PHP from mysql to mysqli and am running into this error during my conversion. The code worked without throwing errors under mysql but for some reason I get the 'Undefined variable: prevcat in /xx/xx/xx/xx/xx/xx/vluchtbijtoestel.php on line 102' error now. I've tried adding $prevcat = $cat to the variables list but that then breaks the code.
My code:
<?php
define('DB_SERVER', "xxx");
define('DB_USER', "xxx");
define('DB_PASSWORD', "xxx");
define('DB_TABLE', "xxx");
// Define your colors for the alternating rows
$color1 = "#F0F8FF";
$color2 = "#FFFFFF";
$row_count = 0;
// The procedural way
$mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_TABLE);
$mysqli->set_charset("utf8");
$mysqli->set_charset("utf8");
$mysqli->query("SET NAMES 'utf8'");
if (mysqli_connect_errno($mysqli)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
$query = "
SELECT vg.gegevenID, lvm.luchtvaartmaatschappij, lvm.sm_logo, vg.vertrekdatum2, vg.vertrekluchthaven, vg.aankomstluchthaven, vg.toestel, vg.inschrijvingnmr, vlg.vliegtuignaam, vg.vluchtnmr, t.toestel AS toestelnaam, lh.luchthavencode, lh.luchthavennaam, lh.countryflag, lh2.luchthavencode AS aankomstluchthavencode, lh2.countryflag AS countryflagaankomst, vlg.erlr, vlg.firstflight, DATEDIFF(vlg.firstflight,vg.vertrekdatum2) Age1, lh2.luchthavennaam AS aankomstnaam, CONCAT(t.toestel,' ', vlg.erlr) as toestelmeterlr
FROM (tbl_vliegtuiggegevens vlg
INNER JOIN (tbl_luchtvaartmaatschappij lvm INNER JOIN tbl_vluchtgegevens vg ON lvm.luchtvaartmaatschappijID = vg.luchtvaartmaatschappij) ON (vlg.inschrijvingnmr = vg.inschrijvingnmr) AND (vlg.lvmID = lvm.luchtvaartmaatschappijID)) INNER JOIN tbl_toestel t ON vg.toestel = t.toestelID
LEFT JOIN tbl_luchthaven lh
ON vg.vertrekluchthaven = lh.luchthavenID
LEFT JOIN tbl_luchthaven lh2
ON vg.aankomstluchthaven = lh2.luchthavenID
GROUP BY lvm.luchtvaartmaatschappij, toestelmeterlr, vg.inschrijvingnmr, vg.vertrekdatum2
ORDER BY lvm.luchtvaartmaatschappij, toestelmeterlr, vg.vertrekdatum2 DESC, vg.inschrijvingnmr; ";
$result = mysqli_query($mysqli, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($mysqli), E_USER_ERROR);
echo "
<table width='100%' border='0'>
<tr>
<td colspan='3'><strong>Luchtvaartmaatschappij</strong></td>
<td width='17%'> </td>
<td width='12%'> </td>
<td width='19%'> </td>
<td width='28%'> </td>
</tr>
<tr>
<td width='2%'> </td>
<td colspan='3'><strong>Toestel</strong></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td width='3%'> </td>
<td width='19%'><strong>vertrekdatum</strong></td>
<td><strong>vliegroute</strong></td>
<td><strong>registratie</strong></td>
<td><strong>vliegtuignaam</strong></td>
<td><strong>vliegtuig leeftijd op reisdatum</strong></td>
</tr>
</table>
";
if($result) {
while($row = mysqli_fetch_assoc($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
$date1 = date_create($row['firstflight']);
$date2 = date_create($row['vertrekdatum2']);
$interval = date_diff($date1, $date2);
$cat = $row['luchtvaartmaatschappij'];
$subcat = $row['toestelmeterlr'];
$item = $row['inschrijvingnmr'];
if($cat != $prevcat){
echo " <table width='100%' border='0'>";
echo " <tr>";
echo " <td><br /><hr></td>";
echo " </tr>";
echo " <tr>";
echo " <td><strong><span class='style4'><img src='http://globe-trekking.com/vg/img/logos/sm/".$row['sm_logo']."'> " .$cat. "</strong></span> <br /></td>";
echo " </tr>";
echo "</table>";
echo '<span style="color: #0A0094; font-size: 16px;"> '. $subcat.'</span><br />';//if the category has changed, we also want to show the new subcat
}elseif($subcat != $prevsubcat){
echo '<br /><span style="color: #0A0094; font-size: 16px;"> ' .$subcat.'</span><br />';
}
echo " <table width='1093' border='0' cellspacing='0'>";
echo " <tr>";
echo " <td width='75'> </td>";
echo " <td width='200' bgcolor='$row_color'>" .date("d-M-Y H:i", strtotime($row['vertrekdatum2']))."</td>";
echo " <td width='70' bgcolor='$row_color'><img src='http://globe-trekking.com/vg/img/flags/".$row['countryflag']."'> <abbr title=\"".htmlspecialchars($row['luchthavennaam'])."\">".$row['luchthavencode']."</abbr></td>";
echo " <td width='70' bgcolor='$row_color'> naar </td>";
echo " <td width='130' bgcolor='$row_color'><img src='http://globe-trekking.com/vg/img/flags/".$row['countryflagaankomst']."'> <abbr title=\"".htmlspecialchars($row['aankomstnaam'])."\">".$row['aankomstluchthavencode']."</abbr></td>";
echo " <td width='150' bgcolor='$row_color'>".$row['inschrijvingnmr']."</td>";
echo " <td width='250' bgcolor='$row_color'>".$row['vliegtuignaam'] ."</td>";
echo " <td width='250' bgcolor='$row_color'>" . $interval->y . " jaar en " . $interval->m." maanden </td>";
echo " </tr>";
echo "</table>";
$prevcat = $cat;
$prevsubcat = $subcat;
// Add 1 to the row count
$row_count++;
}
}
mysqli_close($mysqli);
?>
put your code .. you are using $precat and $prevsubcat in your if conditions before declaring and defining it.
$prevcat = $cat;
$prevsubcat = $subcat;
after
$cat = $row['luchtvaartmaatschappij'];
$subcat = $row['toestelmeterlr'];
like this
$cat = $row['luchtvaartmaatschappij'];
$subcat = $row['toestelmeterlr'];
$prevcat = $cat;
$prevsubcat = $subcat;
Put
$prevcat = '';
$prevsubcat = '';
Juste before "While" expression
Regards
I am printing values in the address bar using the get variable,it works perfectly, then my problem is i want store the printed values into a mysql table, but it only stores null values, please help me where i am going wrong in below attached code.
<?php
session_start();
include('header.php');
?>
<form name="cart.php">
<table>
<tr>
<th> ID </th>
<th> Vehicle Description </th>
<th> Price </th>
</tr>
<tr>
<td><?php echo $_GET['id']; ?> </td>
<td><?php echo $_GET['name']; ?> </td>
<td><?php echo $_GET['price']; ?> </td>
</tr>
</table>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$x=$_GET['id'];
$y=$_GET['name'];
$z=$_GET['price'];
$sql = "INSERT INTO products (id,description,price)
VALUES ('$x', '$y', '$y')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<form><input type="button" value="Go back" onClick="window.location.href='automobile_list.php'"></form>
</form>
<?php
include('footer.php');
?>
<?php
session_start();
include('header.php');
$x=$_GET['id'];
$y=$_GET['name'];
$z=$_GET['price'];
?>
<form name="cart.php">
<table>
<tr>
<th> ID </th>
<th> Vehicle Description </th>
<th> Price </th>
</tr>
<tr>
<td><?php echo $x; ?> </td>
<td><?php echo $y; ?> </td>
<td><?php echo $z; ?> </td>
</tr>
</table>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO products (id,description,price)
VALUES ('$x', '$y', '$y')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<form><input type="button" value="Go back" onClick="window.location.href='automobile_list.php'"></form>
</form>
<?php
include('footer.php');
?>
use the above code you will get your code working.
the problem is in query
so update that line as:
$sql = "INSERT INTO products (id,description,price)
VALUES ('".$x."', '".$y."', '".$y."')";
here is my code
<?
if ((!$_POST['id']) || (!$_POST['format']) || (!$_POST['title'])) {
header ("Location: /show_addrecord.html");
exit;
}
$db_name = "testdb2";
$table_name = "my_music";
$connection = #mysql_connect ("localhost", "spike", "9sj7En4")
or die (mysql_error());
$db = #mysql_select_db ($db_name, $connection) or die(mysql_error());
//create SQL statement and issue query
$id = mysql_escape_string($_POST['id']);
$format = mysql_escape_string($_POST['format']);
$title = mysql_escape_string($_POST['title']);
$artist_fn = mysql_escape_string($_POST['artist_fn']);
$artist_ln = mysql_escape_string($_POST['artist_ln']);
$rec_label = mysql_escape_string($_POST['rec_label']);
$my_notes = mysql_escape_string($_POST['my_notes']);
$date_acq = mysql_escape_string($_POST['date_acq']);
$sql = "INSERT INTO $table_name
(id, format, title, artist_fn, artist_ln, rec_label, my_notes, date_acq) VALUES
('$_POST[id]',
'$_POST[format]',
'$_POST[title]',
'$_POST[rec_label]',
'$_POST[artist_fn]',
'$_POST[artist_ln]',
'$_POST[my_notes]',
'$_POST[date_acq]')";
$result = #mysql_query($sql, $connection) or die(mysql_error());
?>
<html>
<head>
<title>Add a Record</title>
</head>
<body>
<table cellspacing=3 cellpadding=3>
<tr>
<td valign=top>
<p><strong>ID:</strong><br>
<? echo "$_POST[id]"; ?></p>
</td>
<td>
<p><strong>Date Acquired (YYYY-MM-DD):</strong><br>
<? echo "$_POST[date_acq]"; ?></p>
</td>
<td valign=top>
<p><strong>Format:</strong><br>
<? echo "$_POST[format]"; ?>
</p>
</td>
</tr>
<tr>
<td valign=top>
<p><strong>Title:</strong><br>
<? echo "$_POST[title]"; ?></p>
</td>
<td valign=top>
<p><strong>Record Label</strong><br>
<? echo "$_POST[rec_label]"; ?></p>
</td>
</tr>
<td valign=top>
<p><strong>Artist's First Name:</strong><br>
<? echo "$_POST[artist_fn]"; ?>
</p>
</td>
<td valign=top>
<p><strong>Artist's Last Name:</strong><br>
<? echo "$_POST[artist_ln]"; ?></p>
</td>
</tr>
<tr>
<td valign=top colspan=2 align=center>
<p><strong>My Notes:</strong><br>
<? echo stripslashes($_POST[my_notes]); ?></p>
<p>Add Another</p>
</td>
</tr>
</table>
</body>
</html>
Most likely, there is a typo, either in the field list, or in the name of the column in the database. Or, hopefully somewhat less likely, the column actually doesn't exist.
Double check your database table.
However, while unlikely, it does appear that there has been a related bug reported here (http://bugs.mysql.com/bug.php?id=1689) for MySQL version 4.0.16 I doubt that this affects you, but it may be worth looking into.
Please. Use mysqli and prepared statements.
<?
if ((!$_POST['id']) || (!$_POST['format']) || (!$_POST['title'])) {
header ("Location: /show_addrecord.html");
exit;
}
$db_name = "testdb2";
$table_name = "my_music";
$connection = #mysqli_connect("localhost", "spike", "9sj7En4") or die (mysqli_error());
$db = #mysqli_select_db($connection, $db_name) or die(mysqli_error());
// BTW, using $tablename here is also wrong on several levels. Avoid.
$sql = "
INSERT INTO $table_name
(id, format, title, artist_fn, artist_ln, rec_label, my_notes, date_acq) VALUES
(?,?,?,?,?,?,?,?)
";
$stmt = mysqli_prepare($connection, $sql);
mysqli_stmt_bind_param($stmt, "ssssssss",
$_POST['id'],
$_POST['format'],
$_POST['title']),
$_POST['artist_fn'],
$_POST['artist_ln'],
$_POST['rec_label']),
$_POST['my_notes'],
$_POST['date_acq']
);
$result = #mysqli_stmt_execute($connection, $sql) or die(mysqli_error());
mysqli_stmt_close($stmt);
?>