berry05 Posted December 16, 2008 Share Posted December 16, 2008 insert2.php <?php //ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="textgame"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE; $password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE; $password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE; if(!$username) die('username not set'); if(!$password1) die('Password1 not set'); else $password1 = md5($password1); if(!$password2) die('Password2 not set'); else $password2 = md5($password2); $query = "SELECT * FROM users WHERE username='$username' AND password1='$password1' AND password2='$password2'"; $result = mysql_query($query) or die( mysql_error()); $count=mysql_num_rows($result); if($count==1){ session_start(); //session_register("username"); $_SESSION['username'] = $username; $queryy = "SELECT gold FROM users WHERE username='$username'"; $result1 = mysql_query($queryy); $row = mysql_fetch_assoc($result1); $_SESSION['gold'] = $row['gold']; //session_register("inventory"); $Query = "SELECT item FROM users_items WHERE username='$username'"; $Result = mysql_query($Query); $Row = mysql_fetch_array($Result); $_SESSION['inventory'] = $Row['inventory']; } header("location:index2.php"); } else { echo "Wrong Username or Password"; } ?> why is that showing up? my brackets are in the right places.. it says its on line 38 too.. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/ Share on other sites More sharing options...
trq Posted December 16, 2008 Share Posted December 16, 2008 Pretty hard to tell what your code is doing because there is no indentaion. It would also appear you have a bunch of out of place else clauses. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716351 Share on other sites More sharing options...
berry05 Posted December 16, 2008 Author Share Posted December 16, 2008 one thing...whats a else clauses? isnt that } else { Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716352 Share on other sites More sharing options...
trq Posted December 16, 2008 Share Posted December 16, 2008 one thing...whats a else clauses? isnt that } else { Yes. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716355 Share on other sites More sharing options...
berry05 Posted December 16, 2008 Author Share Posted December 16, 2008 it has something to do with $Query = "SELECT item FROM users_items WHERE username='$username'"; $Result = mysql_query($Query); $Row = mysql_fetch_array($Result); $_SESSION['inventory'] = $Row['inventory']; because when i change that line to normal i dont get the error....but the reason why i change it is to try to get the inventory thing working but its not working and i dont know what to do about it...ive been worknig on the same thing for 2 days now.... check it out.. http://www.phpfreaks.com/forums/index.php/topic,230022.0.html ive been working on it and working on it and i think this is it... $Query = "SELECT item FROM users_items WHERE username='$username'"; $Result = mysql_query($Query); $Row = mysql_fetch_array($Result); $_SESSION['inventory'] = $Row['inventory']; but i get the else error... Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716374 Share on other sites More sharing options...
trq Posted December 16, 2008 Share Posted December 16, 2008 but i get the else error... Your getting a parse error. Indent your code so it is readable and you might find it. There is no parse errors in.... $Query = "SELECT item FROM users_items WHERE username='$username'"; $Result = mysql_query($Query); $Row = mysql_fetch_array($Result); $_SESSION['inventory'] = $Row['inventory']; There is a bug however. Your only selecting item in your query yet you expect inventory to be within your $Row array. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716377 Share on other sites More sharing options...
berry05 Posted December 16, 2008 Author Share Posted December 16, 2008 i found the bug and fixed it! thxs for noticing that! hopefully it will work once i find the darn parse error..i couldn't find anything wrong...do you think i have some php 4 codes in there? im using php 5 btw.. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716384 Share on other sites More sharing options...
ngreenwood6 Posted December 16, 2008 Share Posted December 16, 2008 try removing the } after header("location:index2.php"); If that doesnt work please post your updated code and error. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716390 Share on other sites More sharing options...
berry05 Posted December 16, 2008 Author Share Posted December 16, 2008 insert2.php <?php //ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="textgame"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE; $password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE; $password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE; if(!$username) die('username not set'); if(!$password1) die('Password1 not set'); else $password1 = md5($password1); if(!$password2) die('Password2 not set'); else $password2 = md5($password2); $query = "SELECT * FROM users WHERE username='$username' AND password1='$password1' AND password2='$password2'"; $result = mysql_query($query) or die( mysql_error()); $count=mysql_num_rows($result); if($count==1){ session_start(); //session_register("username"); $_SESSION['username'] = $username; $queryy = "SELECT gold FROM users WHERE username='$username'"; $result1 = mysql_query($queryy); $row = mysql_fetch_assoc($result1); $_SESSION['gold'] = $row['gold']; //session_register("inventory"); $Query = "SELECT item FROM users_items WHERE username='$username'"; $Result = mysql_query($Query); $Row = mysql_fetch_array($Result); $_SESSION['inventory'] = $Row['item']; } header("location:index2.php"); } else { echo "Wrong Username or Password"; } ?> error: Parse error: syntax error, unexpected '}' in C:\wamp\www\test\login\insert2.php on line 39 Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716394 Share on other sites More sharing options...
CroNiX Posted December 16, 2008 Share Posted December 16, 2008 It took me 5 seconds to find your problem, well the one you are talking about anyway. Searching your piece of code, you have 2 opening braces '{' and 3 closing braces '}'. Obviously you have a mismatch which would have been super easy for you to see (and probably wouldn't have done it in the first place) had you properly indented your code. You also have if(condition) ... else ... else ... You can't have 2 elses like that. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716403 Share on other sites More sharing options...
ngreenwood6 Posted December 16, 2008 Share Posted December 16, 2008 try this code and let me know what happens: <?php //ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="textgame"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE; $password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE; $password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE; if(!$username) { echo "username not set"; } elseif(!$password1) { echo "Password1 not set"; } else { $password1 = md5($password1); } if(!$password2) { echo "Password2 not set"; } else { $password2 = md5($password2); $query = "SELECT * FROM users WHERE username='$username' AND password1='$password1' AND password2='$password2'"; $result = mysql_query($query) or die( mysql_error()); $count=mysql_num_rows($result); if($count==1) { session_start(); //session_register("username"); $_SESSION['username'] = $username; $queryy = "SELECT gold FROM users WHERE username='$username'"; $result1 = mysql_query($queryy); $row = mysql_fetch_assoc($result1); $_SESSION['gold'] = $row['gold']; //session_register("inventory"); $Query = "SELECT item FROM users_items WHERE username='$username'"; $Result = mysql_query($Query); $Row = mysql_fetch_array($Result); $_SESSION['inventory'] = $Row['item']; } header("location:index2.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716408 Share on other sites More sharing options...
berry05 Posted December 16, 2008 Author Share Posted December 16, 2008 sweet! u found the error!! and the other problem...is fixed!! thxs guys so much! im so happy now aha thxs again! Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716411 Share on other sites More sharing options...
ngreenwood6 Posted December 16, 2008 Share Posted December 16, 2008 You are better off to code in the method that I showed you because it is much more readable. I am sure there is an even better way but I would at least go this far for readability in the future. Makes problem solving easier. Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716412 Share on other sites More sharing options...
berry05 Posted December 16, 2008 Author Share Posted December 16, 2008 ok...ya your right too...it is easier coding that way ...just in case of errors or bugs you can find them easier... thxs! Quote Link to comment https://forums.phpfreaks.com/topic/137135-solved-parse-error-syntax-error-unexpected-in-cwampwwwtestlogininsert2php/#findComment-716415 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.