Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

MySQL in PHP - No syntax errors, but not working :-(

$
0
0

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>");
   }
}}}
 ?>

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles