View Full Version : Editing mysql records in PHP

03-04-2010, 06: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">

<title>Pyongyang Pair Database Control Panel</title>

<!-- Stylesheets -->
<link rel="stylesheet" href="style.css" media="screen" />


<div id="footer_wrap">
<div id="footer">

<div class="link1_wrap open">
<a href="/records/add.php">Add new Record</a>

<div class="link2_wrap open">
<a href="/records/amend.php">Amend Records</a>


<!-- 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 -->

$con =mysql_connect("localhost", "root", "root");

die("<span class=\"alert\">Connection to the database failed.</span>");


$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'];


$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'] . "')";


echo "<span class=\"notice\">You have successfully updated $name's record. <a href=\"/home.php\">Click here to go to the homepage</a>.</span>";





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

//if there is something in the field sent from the post check it and see if you can add it to the database


//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>
<td><h3>Name &nbsp;&nbsp;&nbsp;<h3></td>
<td><input type=xt class="form" name="name" value="<?php echo $_GET['name']; ?>" width="650px" maxlength="30" id="name"></td><br>

<td><h3>E-mail &nbsp;&nbsp;&nbsp;<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>

<td><h3>DOB &nbsp;&nbsp;&nbsp;<h3></td>
<td><input type=xt class="form" name="name" value="<?php echo $_GET['dob']; ?>" width="650px" maxlength="30" id="name"></td><br>

<tr><td><h2 align="left" class="addtext"><img src="/img/2.png" class="step" alt="Step 2" /> Address</h2></td></tr>
<td><h3>House number/name and Street &nbsp;&nbsp;&nbsp;<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>

<td><h3>City/Town &nbsp;&nbsp;&nbsp;<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>

<img src="lightbulb.png" alt="" class="lightbulb" />

<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 />


<tr><td><h2 align="left" class="addtext"><img src="/img/3.png" class="step" alt="Step 3" /> Miscellaneous</h2></td></tr>

<td><h3>Favourite Music/Genre &nbsp;&nbsp;&nbsp;<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><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>




03-04-2010, 07:02 PM
I'm pretty sure that my SQL query is correct

You should find out for sure. Always check queries to see if they return true or false.

03-04-2010, 07:43 PM
You should find out for sure. Always check queries to see if they return true or false.

It works, I've echoed the SQL out, then ran it in phpmyadmin. Only problem is it thinks I want to update the record with nothingness if nothing is inbetween the single brackets.

I don't think this is the problem to the script not working; however.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum