I have been trying to create a simple DB that I can update using PHP but for some reason its not working. Here is the code.
Config file
<?php
$con = mysql_connect("localhost","usrname","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname");
?>
List of Entries in the DB. I am able to see all of them.
<?
//connect to mysql
include("config.php");
echo "<a href='new.php'>New Gig</a>";
echo "<br><br>";
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the events
$result = mysql_query("SELECT * FROM events ORDER by id");
//run the while loop that grabs all the events scripts
while($r=mysql_fetch_array($result))
{
//grab the location and the ID of the events
$location = $r["location"].": ".$r["day"].",".$r["month"].".".$r["date"];//take out the location
$id = $r["id"];//take out the id
//make the location a link
echo "$location - <a href='edit.php?cmd=edit&id=$id'>Edit</a> ";
echo " - <a href='delete.php?cmd=delete&id=$id'>Delete</a>";
echo "<br>";
}
}
?>
Edit the DB. Here is where the problem is located. Dont know what to do.
<?
include("config.php");
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM events WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Location:<br><INPUT TYPE="TEXT" NAME="location" VALUE="<?php echo $myrow["location"] ?>" SIZE=30><br><br>
Day:<br><INPUT TYPE="TEXT" NAME="day" VALUE="<?php echo $myrow["day"] ?>" SIZE=30><br><br>
Month:<br><INPUT TYPE="TEXT" NAME="month" VALUE="<?php echo $myrow["month"] ?>" SIZE=30><br><br>
Date:<br><INPUT TYPE="TEXT" NAME="date" VALUE="<?php echo $myrow["date"]?>" SIZE=30><br><br>
Time:<br><INPUT TYPE="TEXT" NAME="time" VALUE="<?php echo $myrow["times"] ?>" SIZE=30><br><br>
Venu Site:<br><INPUT TYPE="TEXT" NAME="venuesite" VALUE="<?php echo $myrow["venuesite"] ?>" SIZE=30><br><br>
Details:<br><TEXTAREA NAME="details" ROWS=10 COLS=30><? echo $myrow["details"] ?></TEXTAREA><br><br>
Post Date with Time and Secongs:<br><INPUT TYPE="TEXT" NAME="post_date" VALUE="<?php echo $myrow["post_date"] ?>" SIZE=30><br><br>
Experiation Date:<br><INPUT TYPE="TEXT" NAME="expiration_date" VALUE="<?php echo $myrow["expiration_date"] ?>" SIZE=30><br><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$loc = $_POST["location"];
$day = $_POST["day"];
$month = $_POST["month"];
$date = $_POST["date"];
$time = $_POST["times"];
$venu = $_POST["venusite"];
$details = $_POST["details"];
$post_date = $_POST["post_date"];
$exp_date = $_POST["expiration_date"];
$sql = "UPDATE events SET location ='$loc',day ='$day',month ='$month',date ='$date',times ='$time',venusite ='$venu',details ='$details',post_date ='$post_date',expiration_date ='$exp_date' WHERE id = $ids";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
//mysql_close($con);
}
}
?>