eam768 Posted May 25, 2013 Share Posted May 25, 2013 The following code is connecting.. and just the sql part works until i add the variables and radio button input parts... please help! <?php$link = mysql_connect("localhost", "emorette11", "mypassword", "mydatabase")or die("Could not connect: " . mysql_error($link));print ("Connected successfully");mysql_select_db("mydatabase"); 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>"); }}}} ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 26, 2013 Share Posted May 26, 2013 well for one you are missing a semi colon in your coding. Tidied Code: <?php $link = mysql_connect("localhost", "emorette11", "mypassword", "mydatabase") or die("Could not connect: " . mysql_error($link)); print("Connected successfully"); mysql_select_db("mydatabase"); 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 />"); } } } } ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 26, 2013 Share Posted May 26, 2013 also you can shorten your code abit using ternary operators instead of abunch of IF's. $submit = isset($_POST['submit']) ? $_POST['submit'] : ''; $radio = isset($_POST['record']) ? $_POST['record'] : ''; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.