Jump to content

My SQL Error


papillonstudios

Recommended Posts

Im getting this error, after i submit the form

 

heres the error

Error message = 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 ' url = WHERE id =' at line 1

 

Heres my code

 

<?php
//Checks to see if theyre allowed to edit their profile
if ($uCan['admin']) {
    //Double security incase the admin hasn't set a guest membergroup
    if ($uId) {

        //If the form hasn't been submitted, show it.
        if (!$_POST['update']) {
?>
<form method="post">
    <table width="75%">
        <?php
        //Selecting the News From trhe Table news
        $query = "SELECT * FROM `nav`";
        $result = mysql_query($query) or die(mysql_error());

        while($row = mysql_fetch_assoc($result)) {
            echo '<tr><td><input type="text" size="25" maxlength="200" name="linkname" value="' . $row ['linkname'] .'"></td><td> <input type="text" size="25" maxlength="200" name="url" value="' . $row ['url'] .'"> </td><td><input type="submit" name="update" value="Change Link "' . $row[' id'] . '></td></tr>';
        }  
        ?>
    </table>
</form>


<?php

        }
        //Or else it has been submitted...
        else {
            //Get information from the forms secure it all.
            
            $sitename = secure($_POST['linkname']);
         $url = secure($_POST['url']);

         $update = mysql_query("UPDATE nav SET linkname = " . $_GET['linkname'] . " , url = " . $_GET['url'] . " WHERE id = " . $_GET['id'] . ";");
         
   
         
            if ($update)
                echo 'Link ' . $row['id'] . ' had been updated, click <a href="index.php?action=upnav">here</a> ';
            
            else
               echo "Error message = ".mysql_error(); 

            //A query to update everything


      }
   }
}


?>

Link to comment
https://forums.phpfreaks.com/topic/163579-my-sql-error/
Share on other sites

You are not sanitizing your input which is very bad.  Also, I am not certain, but your values in the query should be surrounded by single quotes ' unless they are numeric.

 

edit: ok, maybe secure() is doing something, but why not use the friendly vars $url, $sitename instead of $_GET['url'], etc.?

Link to comment
https://forums.phpfreaks.com/topic/163579-my-sql-error/#findComment-863129
Share on other sites

You'll  have to repost what you currently have, but I remember thinking that the problem was that your query didn't have quotes around the values:

 

Yours:

$update = mysql_query("UPDATE nav SET linkname = " . $_GET['linkname'] . " , url = " . $_GET['url'] . " WHERE id = " . $_GET['id'] . ";");

Suggested:

$update = mysql_query("UPDATE nav SET linkname = '" . $_GET['linkname'] . "' , url = '" . $_GET['url'] . "' WHERE id = " . $_GET['id'] . ";");

(Though $_GET['id'] should be sanitized by doing something like: $_GET['id'] = intval($_GET['id']);  somewhere above

Link to comment
https://forums.phpfreaks.com/topic/163579-my-sql-error/#findComment-868132
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.