Help - Search - Members - Calendar
Full Version: Help With Databases.
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Unit158
CODE
$name = "****";
$password = "****";
$database = "****";
$mysqli = new mysqli("localhost", $name, $password, $database);
    if (strcasecmp($_GET[cmd], "delete")) {
        $mysqli->query("DELETE FROM tickets WHERE ticketno=".$_GET[id]);
    }
$mysqli->close();

Ok, so this is half the code to a ticket management system I am building, and when I load the page, the whole table is cleared. No GET values, just the normal load of the page.
Before it would display the table's contents (in the other half of the code), but couldn't delete.
I am new to SQL databases and none of my friends have used it.
ClickSSL
As per your code if you dont passed cmd command in your url string then you will not able to GET this variable and value so plz first check have you pass cmd command in your URL ??......
there is not any problem with the connection therefore if you had any doubt in your database connection then add below code and check ...if connection is not proper then display error and also your query not execute properly then also display error.

$name = "****";
$password = "****";
$database = "****";
$mysqli = new mysqli("localhost", $name, $password, $database);
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

if (strcasecmp($_GET[cmd], "delete"))
{
$result=$mysqli->query("DELETE FROM tickets WHERE ticketno=".$_GET[id]);
if($result)
{
echo "Delete tickets successfully!!";
}
if(!$result)
{
printf("Errormessage: %s\n", $mysqli->error);
}
$mysqli->close();
}
else
{
echo "query is not execute";
}
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.