Hi, I am creating a rather large project for school using PHP and I'm having some trouble getting a particular query to work.
When I print out various tables used in my database, I want to be able to also print out a link that loads another page that allows that row to be deleted. Before trying to implement this on my project, I'm trying to get it to work with a very tiny test database. The test database only has a firstname and lastname fields.
Thus, in showtable.php there is a loop that prints out all the fields as follows:
echo("<td>".$row["firstname"]);
echo("<td>".$row["lastname"]);
echo("<td><a href=\"administration.php?dbtable=names&delname=".$row[lastname]."\"> DELETE </a>");
delname is the name of the last name to delete.
Ok, so then administration.php gets called and it contains the following code:
<?php
$connection = @mysql_connect("localhost", "XXXX", "XXXX") or die("Death!");
$pickdatabase = @mysql_select_db("test", $connection)
or die("Database Connection Problem!");
$delquery = "delete from $dbtable where lastname=$delname";
echo("<a href=\"mysqltest.php\">Back</a>");
$runit=mysql_query($delquery, $connection) or die("Query failed");
Every time I run it, it prints out that the Query failed. But I noticed that the url for administration.php ends with "delname=%20lastname"
lastname being the lastname that was passed. The strange thing is that when I print out the last name it prints out the right name without the %20 Does anyone know where this %20 is coming from and...do you think that is why the query is failing? Is something wrong syntactically? Anyone else ever had this problem?