jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 changeing the js query to egesdsg worked prefect.. :'( Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047623 Share on other sites More sharing options...
TeddyKiller Posted April 24, 2010 Share Posted April 24, 2010 Ok, so the problem lies here $js = '\$(\'#' . $id . '\').tipsy({gravity: \'n\'});'; Echo it. $js = '\$(\'#' . $id . '\').tipsy({gravity: \'n\'});'; exit($js); If that comes out with a value. You could do this. $query_t = "INSERT INTO `uses` (`js`) VALUES ('$js')"; exit($query_t); Whats the results? Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047626 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 result = INSERT INTO `uses` (`js`) VALUES ('\$('#36').tipsy({gravity: 'n'});') Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047628 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 $js = '\$(\'#' . $id . '\').tipsy({gravity: \'n\'});'; $query_t = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; exit($query_t); result INSERT INTO `uses` (`js`) VALUES ('\$('#39').tipsy({gravity: 'n'});') WHERE `id` = '39' Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047631 Share on other sites More sharing options...
TeddyKiller Posted April 24, 2010 Share Posted April 24, 2010 INSERT INTO `uses` (`js`) VALUES ('\$('#36').tipsy({gravity: 'n'});') Now the problem is.. you are using single quotes, within single quotes. Causing it to close. So you could try.. $js = mysql_real_escape_string('\$(\'#' . $id . '\').tipsy({gravity: \'n\'});'); Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047632 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 what would be the correct way to write this sorry Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047635 Share on other sites More sharing options...
TeddyKiller Posted April 24, 2010 Share Posted April 24, 2010 Editted last post with a possbile fix Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047636 Share on other sites More sharing options...
PFMaBiSmAd Posted April 24, 2010 Share Posted April 24, 2010 Use mysql_real_escape_string() on the $js variable before you put it into the query statement so that any special sql characters in it (like the single-quotes) don't break the sql syntax. Your $js = line of code in the first post in this thread was probably okay. Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047638 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 @PFMaBiSmAd 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` = '43'' at line 1 <?php session_start(); $message .= $_SESSION["message"]; include('_resources/opendb.php'); $_SESSION['message'] = ""; if (empty($_POST['use'])) $_SESSION['message'] .= "<font color=red><li>You must submit in an idea.<br /></li></font>"; if (!empty($_SESSION['message'])) { $_SESSION['message'] .= "<br />"; header("Location: add.php"); exit(); } $use = mysql_real_escape_string(ucwords($_POST['use'])); $query = "INSERT INTO `uses` (`uses`) VALUES('$use')"; if (mysql_query($query)) { $id = mysql_insert_id(); } else { $_SESSION['message'] = "<font color=red><li>Couldnt Add 1</li><br /></font>"; header('Location: add.php'); } $js = "$('#$id').tipsy({gravity: 'n'});"; $js = mysql_real_escape_string($js); $query_t = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; if (mysql_query($query_t)) { $_SESSION['message'] = "<font color=green><li>Your idea was added below</li><br /></font>"; header('Location: index.php'); } else { exit(print(mysql_error())); $_SESSION['message'] = "<font color=red><li>Couldnt Add 2</li><br /></font>"; header('Location: add.php'); } include('_resources/closedb.php'); ?> Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047648 Share on other sites More sharing options...
TeddyKiller Posted April 24, 2010 Share Posted April 24, 2010 You cannot do an insert query where someones data is. I'm assuming you mean update? $query_t = "UPDATE `uses` SET `js`= '$js' WHERE `id` = '$id'"; Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/page/2/#findComment-1047650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.