8 Replies - 885 Views - Last Post: 31 January 2011 - 09:57 AM Rate Topic: -----

#1 sunil bisht   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-January 11

problem in submission data

Posted 30 January 2011 - 11:22 PM

please help ......

my problem is when user fill the either left or right text box then the submitted data is submit on the database..
but its not working..code is
 <?php
         error_reporting(E_ALL ^E_NOTICE);
         $con = mysql_connect("localhost", "root","");
          if (!$con)
             {
               die('Could not connect: ' . mysql_error());
             }
             mysql_select_db("atsan_db", $con);
             $referrerid=$_POST["referrerid"];
             $sql="SELECT referrerid,firstname,lastname,`left`,`right` FROM p_name WHERE referrerid ='$referrerid'";            
             $result = mysql_query($sql) or die(mysql_error());
             echo "<table border='1'>
                  <tr>
                   <th>referrerid</th>
                   <th>Firstname</th>
                   <th>Lastname</th>
                   <th>left</th>
                   <th>right</th>
                 </tr>";

             while($row = mysql_fetch_array($result))
               {
                 echo "<tr>";
                 echo "<td>" . $row['referrerid'] . "</td>";
                 echo "<td>" . $row['firstname'] . "</td>";
                 echo "<td>" . $row['lastname'] . "</td>";
                 echo "<td>" . $row['left'] . "</td>";
                 echo "<td>" . $row['right'] . "</td>";
                 echo "</tr>";
                }
              echo "</table>";
       mysql_close($con);
    ?>


This post has been edited by macosxnerd101: 30 January 2011 - 11:25 PM
Reason for edit:: Removed duplicate code not between code tags


Is This A Good Question/Topic? 0
  • +

Replies To: problem in submission data

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12680
  • View blog
  • Posts: 45,864
  • Joined: 27-December 08

Re: problem in submission data

Posted 30 January 2011 - 11:26 PM

And your specific problems or errors are?
Was This Post Helpful? 1
  • +
  • -

#3 sunil bisht   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-January 11

Re: problem in submission data

Posted 30 January 2011 - 11:31 PM

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 ''left'='at112' WHERE referrerid = 'at105'' at line 1
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12680
  • View blog
  • Posts: 45,864
  • Joined: 27-December 08

Re: problem in submission data

Posted 30 January 2011 - 11:42 PM

PHP Magic Quotes are deprecated. Don't use them (ie., around left and right in the above query).

Also, I don't see where you compare left to any value in the above query. Please post the relevant query.
Was This Post Helpful? 0
  • +
  • -

#5 sunil bisht   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-January 11

Re: problem in submission data

Posted 30 January 2011 - 11:44 PM

View Postmacosxnerd101, on 30 January 2011 - 11:26 PM, said:

And your specific problems or errors are?

<?php
         error_reporting(E_ALL ^E_NOTICE);
         $con = mysql_connect("localhost", "root","");
          if (!$con)
             {
               die('Could not connect: ' . mysql_error());
             }
             mysql_select_db("atsan_db", $con);
              $referrerid=$_POST["referrerid"];
              $left=$_POST["left"];
              $right=$_POST["right"];
              
             if($left!="")
             {
              $sql="UPDATE p_name SET 'left'='$left'
               WHERE referrerid = '$referrerid'";
               mysql_query($sql);
                if (!mysql_query($sql,$con))
                  {
                    die('Error: ' . mysql_error());
                  }
             }
            if($right!="")
             {
             $sql="UPDATE p_name SET 'right'='$right'
                WHERE referrerid = '$referrerid'";
                 mysql_query($sql);
                if (!mysql_query($sql,$con))
                  {
                    die('Error: ' . mysql_error());
                  }
             }           
              mysql_close($con);
    ?>


This post has been edited by macosxnerd101: 30 January 2011 - 11:48 PM
Reason for edit:: Please use code tags

Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12680
  • View blog
  • Posts: 45,864
  • Joined: 27-December 08

Re: problem in submission data

Posted 30 January 2011 - 11:52 PM

I'm pretty sure there shouldn't be single quotes around the column name in your UPDATE query.
Was This Post Helpful? 2
  • +
  • -

#7 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: problem in submission data

Posted 31 January 2011 - 12:03 AM

*
POPULAR

grave accent (`) isn't same as single quote ('). Use the appropriate sign where needed. grave accent (`) is used around the field names in database query and quotes are used around the values. don't mix the two.
Was This Post Helpful? 5
  • +
  • -

#8 sunil bisht   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-January 11

Re: problem in submission data

Posted 31 January 2011 - 12:09 AM

thank u so much
Was This Post Helpful? 0
  • +
  • -

#9 TMKCodes   User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: problem in submission data

Posted 31 January 2011 - 09:57 AM

View Postatik97, on 31 January 2011 - 12:03 AM, said:

grave accent (`) isn't same as single quote ('). Use the appropriate sign where needed. grave accent (`) is used around the field names in database query and quotes are used around the values. don't mix the two.


Something like this.

$sql = "SELECT `referrerid`, `firstname`, `lastname`, `left`, `right` FROM `p_name` WHERE `referrerid` = '" . $referrerid . "'";

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1