mySQL and PHP Can't delete row in my table =(

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SlayerApocalypse666
    Banned
    • Aug 2006
    • 324

    #1

    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, 11:42 AM.
  • dAnceguy117
    new hand moves = dab
    FFR Simfile Author
    • Dec 2002
    • 10097

    #2
    Re: mySQL and PHP Can't delete row in my table =(

    just skimming quickly, sorry for incompleteness

    Originally posted by SlayerApocalypse666

    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

    Comment

    Working...