Jump to content

Update Multiple Fields


frostyhorse

Recommended Posts

For my project, I need to let members update multiple fields at once. There's a total of four fields that I want them to be able to update on their own free will.

 

This is what I have started on:

 

<?
session_name('usersession');
session_start();
?>

<html>
<head>
<title>Equine Revolution's Equine Registry</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body>
<center>
<table id="main">
<tr><td>
<p><h1>Update A Horse</h1>
<?
if(!isset($peacock))
{
include('menu2.php');
include('loginform.php');

exit();
}

else {
include('menu1.php');
echo '

<p>
<form action="update2.php" method="post">
Horse Id: <input type="text" name="id" /><br>
Horse Name: <input type="text" name="id" /><br>
For Stud: <input type="text" name="stud" /> <br>
<input type="submit" />
</form>
</p>';
}
?>

<p>
<?
include('foot.php');
?>
</p>
</td></tr>

<tr><td></td></tr>

</table>
</center>

</body>
</html>

 

Right now they -should- be able to say yes, this stallion can breed or no, this stallion cannot breed. I know how to add in the other fields for breeding information, for sale or not, and sale information.

 

This is what I have written for the update2.php page:

 

<?php
$con = mysql_connect("fdb2.awardspace.com","erregistry_db","carmengj99");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("erregistry_db");

$sql="UPDATE registry SET stud='$_POST['stud'],
WHERE id='$_POST['id'],
AND name='$_POST['name'],";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Horse has been updated.";

mysql_close($con)
?>
<a href="update.php">Update Another Horse</a>

 

Right now I get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/www/erregistry.awardspace.us/update2.php on line 10 and not exactly sure what it is... =/

 

I first need help fixing the error and the writing it so the three other fields mentioned above can be updated, too.

Link to comment
Share on other sites

You can't use array indices inside of double quotes like you can with regular variables. Also, you are missing the end single quotes for all of them and you have an extra comma at the end. Try it like this:

$sql="UPDATE registry SET stud='".$_POST['stud']."',
WHERE id='".$_POST['id']."',
AND name='".$_POST['name']."'";

Link to comment
Share on other sites

I changed that and am no getting an error, "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='Blue Falcon W', AND name=''' at line 2"

 

I put in '3' for the ID, 'Blue Falcon W' for the name, and 'yes' for the stud, which I want to update.

Link to comment
Share on other sites

Hi frostyhorse,

 

Use the following it will work.

 

$sql="UPDATE registry SET stud='$_POST[stud]'

WHERE id='$_POST[id]'

AND name='$_POST[name]' ";

 

There is no need to put ',' .When we  update multiple column at a time then we put ',' between the diffrent column name.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.