problem in updating a table... pls help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
monindra1984
Forum Newbie
Posts: 14
Joined: Wed Mar 18, 2009 10:35 am

problem in updating a table... pls help

Post by monindra1984 »

Dear frends..

i m editing a table by taking input from user.. After taking when i try to update is gives following 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 ' `TR 2.5`=, `CAR STAFF`=, `LY 3 TON`=, `TATA 4.5 TON`=, `ALS/ MOD ALS`=, `FOL BR' at line 1


The code had been given below.. pls help.. I am not able to debug it.. Moreover i m new to php and mysql and working on project. Got only two days to complete the project.. Need help.. SOS call

Code: Select all

 
<?php require_once('../Connections/Logistics.php'); ?>
 
<?php
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE contact_rate SET JEEP=%s, GYPSY=%s, BUS=%s, MC=%s, `1 TON`=%s, `TR 2.5`=%s, `CAR STAFF`=%s, `LY 3 TON`=%s, `TATA 4.5 TON`=%s, `ALS/ MOD ALS`=%s, `FOL BROWER`=%s, `SCANIA GTV`=%s, `LOADER SCANIA`=%s, `AMN SCANIA`=%s, URAL=%s, `LRV 3 TON`=%s, `LRV ALS`=%s, HRV=%s, KRAZ=%s, `LY 10 TON 6x6`=%s, `KOLOSTATRA 6X6`=%s, `TATRA 8X8`=%s, JCB=%s, `WH DOZER`=%s, TRACTOR=%s, `TATRA 10X10`=%s, `TATRA 10X 10 LV`=%s, `TATRA 10X 10 TLV`=%s, `TATRA 4X 4 MET SPL VEH`=%s, `TATRA 6X 6 CSV`=%s, `TATRA 6X 6 WKSP`=%s, `TATRA 8X 8 AMN`=%s, BMP=%s, `ALS THIRD LINE`=%s, `WATER BROWSER 3 TON`=%s, `WATER BROWSER 2.5 TON`=%s WHERE CAT=%s",
                       $_POST['JEEP'],
              $_POST['GYPSY'],  
              $_POST['BUS'],
                       $_POST['MC'],
                       $_POST['1 TON'],
                       $_POST['TR 2.5'],
                       $_POST['CAR STAFF'],
                       $_POST['LY 3 TON'],
                       $_POST['TATA 4.5 TON'],
                       $_POST['ALS MOD ALS'],
                       $_POST['FOL BROWER'],
                       $_POST['SCANIA GTV'],
                       $_POST['LOADER SCANIA'],
                       $_POST['AMN SCANIA'],
                       $_POST['URAL'],
                       $_POST['LRV 3 TON'],
                       $_POST['LRV ALS'],
                       $_POST['HRV'],
                       $_POST['KRAZ'],
                       $_POST['LY 10 TON 6x6'],
                       $_POST['KOLOSTATRA 6X6'],
                       $_POST['TATRA 8X8'],
                       $_POST['JCB'],
                       $_POST['WH DOZER'],
                       $_POST['TRACTOR'],
                       $_POST['TATRA 10X10'],
                       $_POST['TATRA 10X 10_LV'],
                       $_POST['TATRA 10X 10_TLV'],
                       $_POST['TATRA 4X 4 MET SPL VEH'],
                       $_POST['TATRA 6X 6 CSV'],
                       $_POST['TATRA 6X 6 WKSP'],
                       $_POST['TATRA 8X 8 AMN'],
                       $_POST['BMP'],
                       $_POST['ALS THIRD LINE'],
                       $_POST['WATER BROWSER 3 TON'],
                       $_POST['WATER BROWSER 2.5 TON'],
                       'CONTACT RATE');
 
  mysql_select_db($database_Logistics, $Logistics);
  $Result1 = mysql_query($updateSQL, $Logistics) or die(mysql_error());
 
  $updateGoTo = "../../../mainmenu.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
 
mysql_select_db($database_Logistics, $Logistics);
$query_contact = "SELECT * FROM contact_rate";
$contact = mysql_query($query_contact, $Logistics) or die(mysql_error());
//$row_Kpl = mysql_fetch_assoc($Kpl);
$totalRows_Kpl = mysql_num_rows($contact);
?>
 
 
 
<table align="center" cellpadding="2" border="2" cellspacing="2" bgcolor="353535" width="40%">
                <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
                    
                    <?php
                            // Creating text field with name by fetching date from the table.
                            while ($get_info = mysql_fetch_assoc($contact)) { 
                                foreach ($get_info as $column => $value) {
                                    if($value!=='CONTACT RATE'){
                        ?>
                    
                        <tr>
                            <td bgcolor="#FFFFFF" width="10%" > <?php echo $column?></td>
                        
                            <td bgcolor="#FFFFFF" width="30%">
                            <input type="text" name="<? echo $column;?>" value="<? echo $value;?>" size="20" style="background:#CCCCCC" >  
                            </td>
                        </tr>   
                        <?php }}};//mysql_free_result($result);?>
        
                        <tr>
                        <tr valign="baseline">
                            <td colspan="2" align="center"><input type="submit" value="Save record" /></td>
                        </tr>
                    <input type="hidden" name="MM_update" value="form1" />
                    <input type="hidden" name="CAT" value="<?php echo $contact['CAT']; ?>" />
                </form>
                <tr valign="baseline">
                    <form action="" method="post">
                    <td align="center" colspan="2"> 
                        <input type="submit" name="submit" value="Go back to view" />
                    </td>
                    </form>
                </tr>
            </table>
                 
 
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: problem in updating a table... pls help

Post by Darhazer »

It seems that $_POST['TR 2.5'] (and other fields as well) are empty...
So check if the form that is generated contains all the inputs you need

Or if it's supposed to be empty and to write an empty value in the database, use '%s' (with quotes) instead of just %s
monindra1984
Forum Newbie
Posts: 14
Joined: Wed Mar 18, 2009 10:35 am

Re: problem in updating a table... pls help

Post by monindra1984 »

Code: Select all

$sql="INSERT INTO elements (Name, Number, Url)
VALUES
("$_POST[‘name’]","$_POST[‘number’]","$_POST[‘url’]")";
shoulde b like this i think.. I m not sure..

Code: Select all

$sql="INSERT INTO elements (Name, Number, Url)
VALUES
($_POST[‘name’],$_POST[‘number’],$_POST[‘url’])";
victoria1879
Forum Newbie
Posts: 3
Joined: Sun Jul 19, 2009 12:14 pm

Re: problem in updating a table... pls help

Post by victoria1879 »

I don't know why but my posts where deleted,so I write it again:

SOS PHP

Έχω το εξής πρόβλημα: θέλω να φτιάξω μια φόρμα στην οποία θα εκχωρώ τιμές σε μια βάση.
Η φόρμα είναι η εξής:
<form>
NAME
<input type="text" name="Name" id="name"/>
<br />
Number:
<input type="text" name="Number" id="number"/>
<br />
Url:
<input type="text" name="Url" id="url"/>
<br/>
<a href="submit.php"> Submit </a>
</form>
Και η φόρμα submit είναι
<?php
$con = mysql_connect("localhost","victoria","victoria");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("name_number_url", $con);

$sql="INSERT INTO elements (Name, Number, Url)
VALUES
("$_POST[‘name’]","$_POST[‘number’]","$_POST[‘url’]")";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>

Και το error είναι

Parse error: parse error in C:\Program Files\EasyPHP 3.0\www\submit.php on line 12

Η σειρά 12 είναι ("$_POST[‘name’]","$_POST[‘number’]","$_POST[‘url’]")";
Έχω δοκιμάσει όλους τους συνδυασμούς με και χωρίς αυτάκια αλλα τίποτα. Και όπου έχω ψάξει όλοι αυτόν τον κώδικα λένε.

Αν εκει που είναι τα POST βάλω τιμές π.χ.
$sql="INSERT INTO elements (Name, Number, Url)
VALUES
(‘ΜΑΡΙΑ’,’123’,’ΜΠΛΑΜΠΛΑ’)";
Τρέχει κανονικά
monindra1984
Forum Newbie
Posts: 14
Joined: Wed Mar 18, 2009 10:35 am

Re: problem in updating a table... pls help

Post by monindra1984 »

copy the $_POST[] to a variable and then use then use that variable like..

$variable = $_POST['whatever'];
victoria1879
Forum Newbie
Posts: 3
Joined: Sun Jul 19, 2009 12:14 pm

Re: problem in updating a table... pls help

Post by victoria1879 »

I've already done this and it didn't work!!!

I have also use the GET instead of POST but nothing!!!
victoria1879
Forum Newbie
Posts: 3
Joined: Sun Jul 19, 2009 12:14 pm

Re: problem in updating a table... pls help

Post by victoria1879 »

ΟΚ I found the answer!!!thanks anyway!!!
Post Reply