Yay
03-04-2010, 05:29 PM
Hi there,
I'm basically trying to edit records via a form, not sure what's wrong with my PHP. I'm pretty sure that my SQL query is correct:
<!-- Jack Griffiths ICT assessment — February/January 2010. -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Pyongyang Pair — Database Control Panel</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="style.css" media="screen" />
</head>
<body>
<!-- NAVIGATION -->
<div id="footer_wrap">
<div id="footer">
<div class="link1_wrap open">
<a href="/records/add.php">Add new Record</a>
</div>
<div class="link2_wrap open">
<a href="/records/amend.php">Amend Records</a>
</div>
</div>
</div>
<!-- begin of website -->
<!-- header -->
<div id="wrapperadd">
<!-- logo -->
<div id="logo"><a href="/home.php"><img class="noborder" src="/img/logo.png" alt="CP Logo" /></a></div>
<!-- welcome message -->
<h1>Amend Record</h1>
<h2><?php echo $_GET['name'];?></h2>
<!-- content -->
<?php
$con =mysql_connect("localhost", "root", "root");
if(!$con){
die("<span class=\"alert\">Connection to the database failed.</span>");
}
if(isset($_POST['update'])){
$name ='';
$dob ='';
$email ='';
$Member_ID =$_GET['id'];
$name =$_POST['name'];
$dob =$_POST['dob'];
$email =$POST['email'];
$street =$_POST['address1'];
$city =$_POST['address2'];
$country =$_POST['address3'];
$favmus =$_POST['music'];
$memberid =$_POST['id'];
$name =$_GET['Name'];
$dob =$_GET['dob'];
$email =$_GET['email'];
$street =$_GET['street'];
$city =$_GET['city'];
$country =$_GET['country'];
$favmus =$_GET['favmus'];
mysql_select_db("pp");
$sql_update = "UPDATE members SET ";
$sql_update .= "members.Name = '" . $_REQUEST['name'] . "', ";
$sql_update .= "members.dob = '" . $_REQUEST['dob'] . "', ";
$sql_update .= "members.mail = '" . $_REQUEST['email'] . "', ";
$sql_update .= "members.city = '" . $_REQUEST['city'] . "', ";
$sql_update .= "members.street = '" . $_REQUEST['street'] . "', ";
$sql_update .= "members.country = '" . $_REQUEST['country'] . "', ";
$sql_update .= "members.favourite_music = '" . $_REQUEST['favourite_music'] . "' ";
$sql_update .= "WHERE (members.Member_ID = '" . $_REQUEST['Member_ID'] . "')";
mysql_query($sql_update);
echo "<span class=\"notice\">You have successfully updated $name's record. <a href=\"/home.php\">Click here to go to the homepage</a>.</span>";
mysql_close($con);
}
?>
<?php
if (!$con)
{
//checks for db fail. if there is, terminate the script, output error message
die('connection failed ' .mysql_error());
}
// else, carry on with the form processing
else
{
//if there is something in the field sent from the post check it and see if you can add it to the database
if(isset($_POST['update'])){
}else{
//display the error messages
}
}
// end.
?>
<div style="margin-top: -5em;"></div>
<form action="amend.php" name="form" method="post">
<table border="0px solid #555555" style="margin-top: -5em;">
<tr><td><h2 align="left" class="addtext"><img src="/img/1.png" class="step" alt="Step 1" /> Basic Information</h2></td></tr>
<tr>
<td><h3>Name <h3></td>
<td><input type=xt class="form" name="name" value="<?php echo $_GET['name']; ?>" width="650px" maxlength="30" id="name"></td><br>
</tr>
<tr>
<td><h3>E-mail <h3></td>
<td><input type=xt value="<?php echo $_GET['email']; ?>" class="form" name="mail" width="650px" maxlength="80" id="mail" tooltipText="Enter the given e-mail address here. Triple check this."></td><br>
</tr>
<tr>
<td><h3>DOB <h3></td>
<td><input type=xt class="form" name="name" value="<?php echo $_GET['dob']; ?>" width="650px" maxlength="30" id="name"></td><br>
</tr>
<tr><td><h2 align="left" class="addtext"><img src="/img/2.png" class="step" alt="Step 2" /> Address</h2></td></tr>
<tr>
<td><h3>House number/name and Street <h3></td>
<td><input type=xt value="<?php echo $_GET['street']; ?>" class="form" name="address1" width="650px" maxlength="100" id="address1" tooltipText="Enter the house name or number and street name of the member. Remember formatting (new lines)."></td><br>
</tr>
<tr>
<td><h3>City/Town <h3></td>
<td><input type=xt value="<?php echo $_GET['city']; ?>" class="form" name="address2" width="650px" maxlength="100" id="address2" tooltipText="Enter the city of the member. Remember formatting (new lines)."></td><br>
</tr>
<img src="lightbulb.png" alt="" class="lightbulb" />
<tr>
<td><h3>Country <h3></td>
<td><select type=xt value="<?php echo $_GET['country']; ?>" class="form" name="address3" width="650px" maxlength="100" id="address3" tooltipText="Select the member's country. If their country is not on this list, please ignore this field.">
<option value="United States" selected="selected">United States</option>
<option value="Canada">Canada</option>
<option value="United Kingdom" >United Kingdom</option>
<option value="Ireland" >Ireland</option>
<option value="Australia" >Australia</option>
<option value="New Zealand" >New Zealand</option>
<br />
</td><br>
</tr>
<tr><td><h2 align="left" class="addtext"><img src="/img/3.png" class="step" alt="Step 3" /> Miscellaneous</h2></td></tr>
<tr>
<td><h3>Favourite Music/Genre <h3></td>
<td><select type="xt" value="<?php echo $_GET['favmus']; ?>" class="form" name="music" width="650px" maxlength="30" id="music" tooltipText="Select the member's favourite music.">
<option value="Acid">Acid</option>
<option value="Alternative">Alternative</option>
<option value="Dance">Dance</option>
<option value="Indie">Indie</option>
<option value="Pop">Pop</option>
<option value="Rock">Rock</option>
<option value="Soft Rock">Soft Rock</option>
<option value="Zouk">Zouk</option>
<option value="Other">Other</option></td><br>
</tr>
<tr><td><h2 align="left" class="addtext"><img src="/img/4.png" class="step" alt="Step 4" /> Finish</h2></td></tr>
<input type="hidden" name="update" value="1" /><br /><span align="left">
<td><input type="submit" class="submit" style="margin-left: 0em;" value="Update Record" name="update"></td>
</span>
</div>
</table>
</form>
</body>
</html>
I'm basically trying to edit records via a form, not sure what's wrong with my PHP. I'm pretty sure that my SQL query is correct:
<!-- Jack Griffiths ICT assessment — February/January 2010. -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Pyongyang Pair — Database Control Panel</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="style.css" media="screen" />
</head>
<body>
<!-- NAVIGATION -->
<div id="footer_wrap">
<div id="footer">
<div class="link1_wrap open">
<a href="/records/add.php">Add new Record</a>
</div>
<div class="link2_wrap open">
<a href="/records/amend.php">Amend Records</a>
</div>
</div>
</div>
<!-- begin of website -->
<!-- header -->
<div id="wrapperadd">
<!-- logo -->
<div id="logo"><a href="/home.php"><img class="noborder" src="/img/logo.png" alt="CP Logo" /></a></div>
<!-- welcome message -->
<h1>Amend Record</h1>
<h2><?php echo $_GET['name'];?></h2>
<!-- content -->
<?php
$con =mysql_connect("localhost", "root", "root");
if(!$con){
die("<span class=\"alert\">Connection to the database failed.</span>");
}
if(isset($_POST['update'])){
$name ='';
$dob ='';
$email ='';
$Member_ID =$_GET['id'];
$name =$_POST['name'];
$dob =$_POST['dob'];
$email =$POST['email'];
$street =$_POST['address1'];
$city =$_POST['address2'];
$country =$_POST['address3'];
$favmus =$_POST['music'];
$memberid =$_POST['id'];
$name =$_GET['Name'];
$dob =$_GET['dob'];
$email =$_GET['email'];
$street =$_GET['street'];
$city =$_GET['city'];
$country =$_GET['country'];
$favmus =$_GET['favmus'];
mysql_select_db("pp");
$sql_update = "UPDATE members SET ";
$sql_update .= "members.Name = '" . $_REQUEST['name'] . "', ";
$sql_update .= "members.dob = '" . $_REQUEST['dob'] . "', ";
$sql_update .= "members.mail = '" . $_REQUEST['email'] . "', ";
$sql_update .= "members.city = '" . $_REQUEST['city'] . "', ";
$sql_update .= "members.street = '" . $_REQUEST['street'] . "', ";
$sql_update .= "members.country = '" . $_REQUEST['country'] . "', ";
$sql_update .= "members.favourite_music = '" . $_REQUEST['favourite_music'] . "' ";
$sql_update .= "WHERE (members.Member_ID = '" . $_REQUEST['Member_ID'] . "')";
mysql_query($sql_update);
echo "<span class=\"notice\">You have successfully updated $name's record. <a href=\"/home.php\">Click here to go to the homepage</a>.</span>";
mysql_close($con);
}
?>
<?php
if (!$con)
{
//checks for db fail. if there is, terminate the script, output error message
die('connection failed ' .mysql_error());
}
// else, carry on with the form processing
else
{
//if there is something in the field sent from the post check it and see if you can add it to the database
if(isset($_POST['update'])){
}else{
//display the error messages
}
}
// end.
?>
<div style="margin-top: -5em;"></div>
<form action="amend.php" name="form" method="post">
<table border="0px solid #555555" style="margin-top: -5em;">
<tr><td><h2 align="left" class="addtext"><img src="/img/1.png" class="step" alt="Step 1" /> Basic Information</h2></td></tr>
<tr>
<td><h3>Name <h3></td>
<td><input type=xt class="form" name="name" value="<?php echo $_GET['name']; ?>" width="650px" maxlength="30" id="name"></td><br>
</tr>
<tr>
<td><h3>E-mail <h3></td>
<td><input type=xt value="<?php echo $_GET['email']; ?>" class="form" name="mail" width="650px" maxlength="80" id="mail" tooltipText="Enter the given e-mail address here. Triple check this."></td><br>
</tr>
<tr>
<td><h3>DOB <h3></td>
<td><input type=xt class="form" name="name" value="<?php echo $_GET['dob']; ?>" width="650px" maxlength="30" id="name"></td><br>
</tr>
<tr><td><h2 align="left" class="addtext"><img src="/img/2.png" class="step" alt="Step 2" /> Address</h2></td></tr>
<tr>
<td><h3>House number/name and Street <h3></td>
<td><input type=xt value="<?php echo $_GET['street']; ?>" class="form" name="address1" width="650px" maxlength="100" id="address1" tooltipText="Enter the house name or number and street name of the member. Remember formatting (new lines)."></td><br>
</tr>
<tr>
<td><h3>City/Town <h3></td>
<td><input type=xt value="<?php echo $_GET['city']; ?>" class="form" name="address2" width="650px" maxlength="100" id="address2" tooltipText="Enter the city of the member. Remember formatting (new lines)."></td><br>
</tr>
<img src="lightbulb.png" alt="" class="lightbulb" />
<tr>
<td><h3>Country <h3></td>
<td><select type=xt value="<?php echo $_GET['country']; ?>" class="form" name="address3" width="650px" maxlength="100" id="address3" tooltipText="Select the member's country. If their country is not on this list, please ignore this field.">
<option value="United States" selected="selected">United States</option>
<option value="Canada">Canada</option>
<option value="United Kingdom" >United Kingdom</option>
<option value="Ireland" >Ireland</option>
<option value="Australia" >Australia</option>
<option value="New Zealand" >New Zealand</option>
<br />
</td><br>
</tr>
<tr><td><h2 align="left" class="addtext"><img src="/img/3.png" class="step" alt="Step 3" /> Miscellaneous</h2></td></tr>
<tr>
<td><h3>Favourite Music/Genre <h3></td>
<td><select type="xt" value="<?php echo $_GET['favmus']; ?>" class="form" name="music" width="650px" maxlength="30" id="music" tooltipText="Select the member's favourite music.">
<option value="Acid">Acid</option>
<option value="Alternative">Alternative</option>
<option value="Dance">Dance</option>
<option value="Indie">Indie</option>
<option value="Pop">Pop</option>
<option value="Rock">Rock</option>
<option value="Soft Rock">Soft Rock</option>
<option value="Zouk">Zouk</option>
<option value="Other">Other</option></td><br>
</tr>
<tr><td><h2 align="left" class="addtext"><img src="/img/4.png" class="step" alt="Step 4" /> Finish</h2></td></tr>
<input type="hidden" name="update" value="1" /><br /><span align="left">
<td><input type="submit" class="submit" style="margin-left: 0em;" value="Update Record" name="update"></td>
</span>
</div>
</table>
</form>
</body>
</html>