Akenatehm Posted November 30, 2008 Share Posted November 30, 2008 Hey Guys, I was wondering if you could check over the following scripts and see if they are set out well and if the syntax in them is valid. <?php include "connect.php"; $author=$_POST['author']; $time=$_POST['time']; $insert = "INSERT INTO `chatrooms` (author,time) VALUES ($author,$time)"; $result= "SELECT `chat_id` FROM chatrooms where time = $time AND author = $author"; while($row = mysql_fetch_array($result)) { $create = "CREATE TABLE "chat_".$result."" ( username text, message text )"; } ?> <?php include "connect.php"; <?php if(isset($_POST['submit'])) { $message=$_POST['message']; $username=$_POST['username']; $chat_id=$_POST['chat_id']; if(strlen($message)<1) { print "Please Enter a Message."; } else { $insert = "INSERT INTO /$chat_id' (username,message) VALUES ($username, $message)"; } } ?> Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/ Share on other sites More sharing options...
genericnumber1 Posted November 30, 2008 Share Posted November 30, 2008 You have two open php tags in the second code block, and you fudged your quotes in the $create variable in the first.... why not just try to run this and see if it generates any errors instead of posting here about it ? Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/#findComment-702048 Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Because I want to check if I am going i nthe right direction and working code might not always be good and neat code. How can I fix the quotes in the $create variable? Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/#findComment-702049 Share on other sites More sharing options...
SN1P3R_85 Posted November 30, 2008 Share Posted November 30, 2008 Sounds like you didn't even write this code. Php freaks is so people can get help with a specific problem. You have to narrow it down, and then ask a specific question. You can't just expect people to debug a huge piece of code when you didn't even tell them what the problem is. Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/#findComment-702067 Share on other sites More sharing options...
revraz Posted November 30, 2008 Share Posted November 30, 2008 Put single quotes around all your variables in your SQL statements unless they are INTs. Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/#findComment-702074 Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 I wrote this code myself, and expected their to be errors. Rather than wasting time, I thought I would get it checked over first. Thanks Revraz. Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/#findComment-702075 Share on other sites More sharing options...
Mark Baker Posted November 30, 2008 Share Posted November 30, 2008 I wrote this code myself, and expected their to be errors. Rather than wasting time, I thought I would get it checked over first. Rather than wasting a lot of other people's time, there are ways of doing some basic checks yourself. From a command line: php -l <filename> will identify any fatal errors that will prevent the script identified by <filename> from even compiling. Few people ever bother to use it, but it can save hours of time when you would otherwise get an http 500 error from a server when trying to run a script which can't compile. Get in the habit of setting your script so that it displays all errors right at the very top of the script, even before setting config or db connections or any other includes Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/#findComment-702185 Share on other sites More sharing options...
Mark Baker Posted November 30, 2008 Share Posted November 30, 2008 And use an editor for your scripts that does syntax highlighting. You get used to the colours used for different elements in your code, and will quickly learn to recognise when you've missed a closing quote for a string or similar. Link to comment https://forums.phpfreaks.com/topic/134819-script-syntaxes-ok/#findComment-702195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.