Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7537891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:58:19+00:00 2026-05-30T06:58:19+00:00

I am doing a really simple script to delete a row out of a

  • 0

I am doing a really simple script to delete a row out of a database. I have done it before with almost identical code but for some reason this wont work!

Viewmessages.php has no problem running but when I try and delete the row using deletemessage.php I receive the an sql error, I only have one line of sql:

viewmessage (sending info to deletemessage.php):

echo "<a href='deletemessage.php?contactname=".$contactname."'>Delete</a>";

The following is the delete message code:

<?php
session_start();
if ( !isset($_SESSION['adminusername']))
{
header("Location:admin.php");
exit();
}


require "dbconn.php";

$contactname = $_GET['contactname'];

$query = "DELETE FROM message WHERE contactname =".$contactname;

$results = mysql_query($query) or die(mysql_error());

header("Location: viewmessages.php");
?>

I cant work out what the error is! $contactname in the viewmessages.php file definately speaks of the primary key for the table!

Any Ideas?>

EDIT: I know that the problem lies with the contactname in the sql… for some reason it is not recieving it well, I did an echo to see what it thought the contactname was and it was correct. I then changed the variable and put in a string of one values in contactname and it deleted the row correctly… so the problem is the GET_[‘contactname’] but I am not sure what….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:58:20+00:00Added an answer on May 30, 2026 at 6:58 am

    Enclose $contactname in quotes in the query, since it is a string. But escape it first! It is highly vulnerable to SQL injection the way it is now. I understand it may be an administrative page, but it is a very good habit to always observe, even when your users are trusted. (Especially since Mr O'Malley would break the SQL statement when you tried to delete him)

    $concatname = mysql_real_escape_string($_GET['contactname']);
    $query = "DELETE FROM message WHERE contactname ='".$contactname . "'";
    

    Always beware when deleting via a hyperlink. Looks like you are checking for admin privileges before allowing this to execute, but be sure these links are not accessible to the broad Internet, where they might get crawled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a really simple query in ASP.NET, but after I inserted the
I know this probably really simple but Im not sure what im doing wrong...
This is probably a simple question, but I really don't know what I'm doing
I'm doing some really simple math and saving the result to a MS SQL2008
I'm doing something really simple: slurping an entire text file from disk into a
I'm sure I am just doing something really dumb and not seeing it but
I'm trying out my first Spring project and must be doing something really stupid
I am really used to doing grep -iIr on the Unix shell but I
I have searched far and wide on this one, but haven't really found a
I've tried lots of code that I have found on this site, but none

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.