pinochio Posted September 27, 2009 Share Posted September 27, 2009 I am trying to create guestbook that will trabsfer all the data into a database. However, when I click submit button I can see part of my code in the browser. This is my code: <?php if (empty($_GET["Name"]) || empty($_GET["Email"])) die("<p> You must enter name and email. You need to go back to the Guestbook.</p>"; $DBConnect = @mysqli_connect("root", "", "") Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ";" . . mysqli_connect_error()) . "</p>"; $DBName = "guestbook"; //creating database if (!@mysqli_select_db($DBConnect, $DBName)) { SQLString = "CREATE DATABASE $DBName"; $QueryResult = @mysqli_query($DBConncet, $SQLString); Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBCoonect) . ": " . mysqli_error($DBConnect)) . "</p>"; echo "<p>You are the first visitor!</p>" mysqli_select_db($DBConnect, $DBName); $TableName = "visitors"; $SQLString = "SELECT * FROM $TableName"; $QueryResult = mysqli_query($DBConnect, $SQLString); if (!$QueryResult) { $SQLString = "CREATE $TableName (countID SMALLINT NOT NULL AUTO INCREMENT PRIMARY KEY , guest_name VARCHAR(40), guest_email VARCHAR(40))"; $QueryResult = @mysqli_query($DBConnect, $SQLString) or die("<p>Unable to create table .</p>" . "<p>Error Code " . mysqli_errno($DBConnect) . ":" . mysqli_error($DBConnect)) . "</p>"; } $Name = addslashes($_GET["Name"]); $Email = addslashes($_GET["Email"]); $SQLString = "INSERT INTO $TableName VALUES(NULL, "$Name", "$Email")"; $QueryResult = @mysqli_query($DBConnect, $SQLString) or die("<p>Unable to execute query.</p>" . "<p>Error Code " . mysqli_errno($DBConnect) . ":" . mysqli_error($DBConnect)) . "</p>"; echo "<p>Thank you for signing our guestook.</p>"; mysqli_close($DBConnect); ?> <p><a href="SeeGuestbook.html">BACK</a></p> </body> </html> Thank you! Quote Link to comment Share on other sites More sharing options...
khr2003 Posted September 28, 2009 Share Posted September 28, 2009 which part of the code do you see in the browser? Quote Link to comment Share on other sites More sharing options...
pinochio Posted September 28, 2009 Author Share Posted September 28, 2009 I spent some time debugging my code, so right now it looks or less problematic comparing to what I had an hour ago..... However, when I run it this is what I get: Parse error: syntax error, unexpected ';' in c:\program files\apache group\Apache\htdocs\CT\getguestbook.php on line 5 Thanks a lot!!!! Quote Link to comment Share on other sites More sharing options...
Handy PHP Posted September 28, 2009 Share Posted September 28, 2009 Missing end parenthesis on line 5: die("<p> You must enter name and email. You need to go back to the Guestbook.</p>"; Should be: die("<p> You must enter name and email. You need to go back to the Guestbook.</p>"); Additional errors will likey happen with each of your die functions since your parenthesis are misplaced. Handy PHP Quote Link to comment Share on other sites More sharing options...
pinochio Posted September 28, 2009 Author Share Posted September 28, 2009 this is what i got right now: Parse error: syntax error, unexpected '=' in c:\program files\apache group\Apache\htdocs\CT\getguestbook.php on line 14 Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted September 28, 2009 Share Posted September 28, 2009 Quickly looking ur missing (atlaest) a dollar sign in fron of the variable in this line SQLString = "CREATE DATABASE $DBName"; shud be $SQLString = "CREATE DATABASE $DBName"; Quote Link to comment Share on other sites More sharing options...
Handy PHP Posted September 28, 2009 Share Posted September 28, 2009 Might be a good idea to get a decent code editor that highlights and color codes your code to make it easier to find errors. Also, if you have any more errors, it would help to see the updated code if you could post it. Handy PHP Quote Link to comment Share on other sites More sharing options...
pinochio Posted September 28, 2009 Author Share Posted September 28, 2009 what might be wrong with this statement? if (!@mysqli_select_db($DBConnect, $DBName)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysqli_query($DBConncet, $SQLstring); or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBCoonect) . ":" . mysqli_error($DBConnect)) . "</p>"; echo "<p>You are the first visitor!</p>" mysqli_select_db($DBConnect, $DBName); there is a problem with syntax, unexpected T_LOGICAL_OR, but I can't find where the problem is Thanks a lot! Quote Link to comment Share on other sites More sharing options...
Handy PHP Posted September 28, 2009 Share Posted September 28, 2009 $QueryResult = @mysqli_query($DBConncet, $SQLstring); or die("<p>Unable to execute the query.</p>" semi-colon preceding an OR statement. Generally, your error message will give you a line number for the error. Generally, the problem is on the line right before the error was found... You had a semi-colon on line 3 which made the OR statement on line 4 return an error. You might want to consider NOT breaking your lines up so much since this seems to be causing you a lot of problems. Breaking your lines up can make reading your code easier sometime but in this case, it actually makes it harder to read. Perhaps if you indent the code after the first break it would make it clearer what belongs with what. Like so: if (!@mysqli_select_db($DBConnect, $DBName)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysqli_query($DBConncet, $SQLstring) or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBCoonect) . ":" . mysqli_error($DBConnect)) . "</p>"; echo "<p>You are the first visitor!</p>" mysqli_select_db($DBConnect, $DBName); Also, you have some typing errors: line 3: $QueryResult = @mysqli_query($DBConncet, $SQLstring); Should Be: $QueryResult = @mysqli_query($DBConnect, $SQLstring) And Line 5 . "<p>Error code " . mysqli_errno($DBCoonect) Should Be: . "<p>Error code " . mysqli_errno($DBConnect) You really need to try and pay more attention to your code. There isn't a spellchecker for PHP, just an error message! Handy PHP Quote Link to comment 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.