jigsawsoul Posted April 24, 2010 Share Posted April 24, 2010 How would i write this, as the var has ' ' ' so its not working right $js = "$('#$id').tipsy({gravity: 'n'});"; $query = "INSERT INTO uses (js) VALUES ('$js') WHERE id = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/ Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 $js = "$('#" . $id . "').tipsy({gravity: 'n'});"; $query = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047588 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 Using the above code give me these errors; Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/jigsaws2/public_html/tape/add2.php on line 33 Parse error: syntax error, unexpected T_STRING in /home/jigsaws2/public_html/tape/add2.php on line 33 <?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($_POST['use']); $use = ucwords($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\'});'; $query = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; if (mysql_query ($query)) { $_SESSION['message'] = "<font color=green><li>Your idea was added below</li><br /></font>"; header('Location: index.php'); } else { $_SESSION['message'] = "<font color=red><li>Couldnt Add 2</li><br /></font>"; header('Location: add.php'); } include('_resources/closedb.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047589 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 Try this. $js = "$('#" . $id . "').tipsy({gravity: 'n'});"; James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047590 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 Na just jumps straight to else saying Couldnt Add 2.. anyone Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047592 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 $js = "$('#" . $id . "').tipsy({gravity: 'n'});"; $query = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; if (mysql_query ($query)) { $_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'); } Post what the error is. James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047594 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 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 '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047596 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 $js = "\$('#" . $id . "').tipsy({gravity: 'n'});"; $query = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; if (mysql_query ($query)) { $_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'); } James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047598 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 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 '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047599 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 $js = '\$(\'#' . $id . '\').tipsy({gravity: \'n\'});'; We might be wasting time with the $js var it might be something else, are all the other querys working ok ? James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047600 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 Where is $id being set? James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047601 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 yeah the query above works fine... what else could it be Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047602 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 $query = "INSERT INTO uses (uses) VALUES ('$use')"; if (mysql_query ($query)) { $id = mysql_insert_id(); $id = mysql_insert_id(); Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047603 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 i replaced $js with $js = '\$(\'#' . $id . '\').tipsy({gravity: \'n\'});'; and had the 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 'WHERE `id` = '23'' at line 1 does this help? Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047604 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 Ok post full code I will fix it up for you. James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047605 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 much love <?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($_POST['use']); $use = ucwords($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 = '1'; $query = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; if (mysql_query ($query)) { $_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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047606 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 includes the right $js <?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($_POST['use']); $use = ucwords($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\'});'; $query = "INSERT INTO `uses` (`js`) VALUES ('$js') WHERE `id` = '$id'"; if (mysql_query ($query)) { $_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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047607 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2010 Share Posted April 24, 2010 Ok first problem, you have set $js to 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\'});'; $query_t = "INSERT INTO `uses` (`js`) VALUES ('$js')"; 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'); ?> James. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047608 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 yeah i know as i submit the code again above, the code you posted gave me same 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 '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047610 Share on other sites More sharing options...
TeddyKiller Posted April 24, 2010 Share Posted April 24, 2010 That means $use doesn't have a value. So.. $_POST['use'] musn't have a value Can't see where though. Or $js Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047612 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 I've check this, and both $use and $js both have a value everytime... Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047615 Share on other sites More sharing options...
TeddyKiller Posted April 24, 2010 Share Posted April 24, 2010 Have you echo'd them out to see if it does have a value? Do you know the exact offending line? Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047617 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 yeah i've echo them both out and each have the value they should have. what do you mean by Do you know the exact offending line? Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047618 Share on other sites More sharing options...
jigsawsoul Posted April 24, 2010 Author Share Posted April 24, 2010 Everything above the exit(); is fine and works great. <?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'); } exit(); $js = '\$(\'#' . $id . '\').tipsy({gravity: \'n\'});'; $query_t = "INSERT INTO `uses` (`js`) VALUES ('$js')"; 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047619 Share on other sites More sharing options...
TeddyKiller Posted April 24, 2010 Share Posted April 24, 2010 It might be unrelated, but try changing the $js in the query to a rando value eg: egesdsg See if that works, if it does.. then the offending line is the $js. Quote Link to comment https://forums.phpfreaks.com/topic/199585-whats-the-correct-way-to-write-this-please-pretty-simple-code/#findComment-1047620 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.