Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy MySQL in PHP - POST w/Radio Buttons

    My php mysql code works fine until i start adding the cariables and POST for radio button selection ... I am getting no syntax errors ... I get the connected successfully, and no other output ... Please help!


    <?php
    $link = mysql_connect("localhost", "emorette11", "TQ4Wxm25", "emorette11_1")
    or die("Could not connect: " . mysql_error($link));
    print ("Connected successfully");
    mysql_select_db("emorette11_1");

    echo "<br />";
    $color = $_POST["color"];
    $material = $_POST["material"];
    $gender = $_POST["gender"];
    $size = $_POST["size"];
    $price = $_POST["price"];
    $id = $_POST["id"];


    if (isset($_POST["submit"]))
    {
    if (isset($_POST["record"]))
    {


    $radio = $_POST["record"];


    if ($radio=="add")
    {
    $sql="INSERT INTO EyeGlasses (Color, Material, Gender, Size, Price, ID) VALUES ('$color','$material','$gender','$size','$price','$id')";

    $result= mysql_query($sql,$link) or die(mysql_error());
    $showresult = mysql_query("SELECT * from EyeGlasses")
    or die("Invalid query: " . mysql_error());
    while ($row = mysql_fetch_array($showresult))
    {
    echo ("<br> Color = ". $row["Color"] . "<br> Material = " . $row["Material"] . "<br>");
    echo("Gender = " . $row["Gender"] . "<br> Size = " . $row["Size"] . "<br>");
    echo("Price = " . $row["Price"] . "<br> ID = " . $row["ID"] . "<br>");
    }
    }
    else if ($radio=="update")
    {
    $sql="UPDATE EyeGlasses SET Color='$color',Material='$material', Gender='$gender', Size='$size', Price='$price', ID='$id' WHERE ID='$id'";
    $result= mysql_query($sql,$link) or die(mysql_error());
    $showresult = mysql_query("SELECT * from EyeGlasses")
    or die("Invalid query: " . mysql_error());
    while ($row = mysql_fetch_array($showresult))
    {
    echo ("<br> Color = ". $row["Color"] . "<br> Material = " . $row["Material"] . "<br>");
    echo("Gender = " . $row["Gender"] . "<br> Size = " . $row["Size"] . "<br>");
    echo("Price = " . $row["Price"] . "<br> ID = " . $row["ID"] . "<br>");
    }
    }
    else
    {
    $sql="DELETE FROM EyeGlasses WHERE ID='$id'";
    $result= mysql_query($sql,$link) or die(mysql_error());
    $showresult = mysql_query("SELECT * from EyeGlasses")
    or die("Invalid query: " . mysql_error());
    while ($row = mysql_fetch_array($showresult))
    {
    echo ("<br> Color = ". $row["Color"] . "<br> Material = " . $row["Material"] . "<br>");
    echo("Gender = " . $row["Gender"] . "<br> Size = " . $row["Size"] . "<br>");
    echo("Price = " . $row["Price"] . "<br> ID = " . $row["ID"] . "<br>");
    }
    }}}
    ?>

  • #2
    Junsee
    Guest
    Can we see the code for the form?

    and would you mind adding the PHP tags around your code, it just makes it easier for us to read it!

    if you're not getting anything, I am guessing the radio button ($_POST["record"]) hasn't been set. Which could mean that someone didn't click a radio button at all on the form.
    Why not take this if statement out, and just assume that the $_POST["record"] is Null.

    But we still need to see the form code...


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •