Go Back   Flash Flash Revolution > General Discussion > Technology
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 05-20-2013, 12:32 PM   #1
SlayerApocalypse666
Banned
FFR Veteran
 
Join Date: Aug 2006
Posts: 324
Default mySQL and PHP Can't delete row in my table =(

GNU nano 2.2.6 File: /var/www/TestPage.php
//I'm not sure about the part in Orange.
<?php

echo "Displaying Database<div>";
$con=mysqli_connect("127.0.0.1","phil","Pass","Website");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Films");

while($row = mysqli_fetch_array($result))
{
echo $row['id'] . " " . $row['name'];
echo "<br>";
}

mysqli_close($con);
?>

<html>
<body BGCOLOR="000000" TEXT="0800FF">
<center><h1>TestPage</h1></center>
<img src="Images\Banner.png" width="1700" height="200">
<form action="insert.php" method="post">
Nom: <input type="text" name="name">
<input type="submit">
</form>
<form action="remove.php" method="post">
Id: <input type="text" name="id">
<input type="submit">
</form>

</center>
</body>
</html>


I tried a billion ways to do this(at this point the code is a hellpit and needs hardcore fixing), plz send me working code lmao =(.
<?php
//mysql_query($sql);
$con=mysqli_connect("127.0.0.1","phil","pass","Website");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$id_m = $_POST['id'];
$sql = "DELETE Films ".
"WHERE id = $id_m" ;

//$sql = "DELETE FROM Films WHERE id=$id_m";
mysql_query($sql,$con);

mysqli_close($con);
header( 'Location: TestPage.php' ) ;

?>

And this is the working code to add stuff to the table...if u wanna take a look.

<?php
//echo $_POST['id'];
$con=mysqli_connect("127.0.0.1","phil","pass","Website");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO Films (name)
VALUES
('$_POST[name]')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
header( 'Location: TestPage.php' ) ;

?>

Last edited by SlayerApocalypse666; 05-20-2013 at 12:42 PM..
SlayerApocalypse666 is offline   Reply With Quote
Old 05-20-2013, 07:36 PM   #2
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default Re: mySQL and PHP Can't delete row in my table =(

just skimming quickly, sorry for incompleteness

Quote:
Originally Posted by SlayerApocalypse666 View Post

I tried a billion ways to do this(at this point the code is a hellpit and needs hardcore fixing), plz send me working code lmao =(.
<?php
//mysql_query($sql);
$con=mysqli_connect("127.0.0.1","phil","pass","Website");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$id_m = $_POST['id'];

// pretty sure '$id_m' needs to be wrapped in single quotes, even though it's a variable
$sql = "DELETE FROM Films WHERE id='$id_m'";
mysql_query($sql,$con);

mysqli_close($con);
header( 'Location: TestPage.php' ) ;

?>
ok I basically didn't make any changes lmfao.

- you had the correct MySQL syntax in the line you commented out (DELETE FROM... WHERE...)

- variable name inside a query needs to have single quotes if the value is a string, I'm p sure


good luck! I'll check back in if I have time ever
dAnceguy117 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 08:48 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution