xxreenaxx1 Posted February 3, 2011 Share Posted February 3, 2011 When I try to run a program, I am getting an error message. Not sure why and the code that has the error is shown below. Error message is syntax error, unexpected T_STRING setcookies("username","$username",time()+86400); Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/ Share on other sites More sharing options...
trq Posted February 3, 2011 Share Posted February 3, 2011 Mind showing us a few lines prior? Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169333 Share on other sites More sharing options...
xxreenaxx1 Posted February 3, 2011 Author Share Posted February 3, 2011 Here you go <?php //session_start();//Starting session $host="localhost"; // Host name $username="root"; // username $password=""; // password $db_name="Examination"; // Databasename $tbl_name="User"; // Tablename $username = $_POST["username"]; $password = $_POST["password"]; $login=$_GET["login"] setcookies("username","$username",time()+86400); if($login="yes"){ // Connection to the server and database mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE Use_Name='$username' and Use_Password='$password'"; $result=mysql_result($sql,0); if($result!=1){ echo"invlaid login";} else{ echo"welcome".$_COOKIE["username"]."whoever"; $_SESSION["username"] = $username; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169335 Share on other sites More sharing options...
trq Posted February 3, 2011 Share Posted February 3, 2011 Your missing a ; off of $login=$_GET["login"] Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169341 Share on other sites More sharing options...
xxreenaxx1 Posted February 3, 2011 Author Share Posted February 3, 2011 Thanks for that. Now I am getting an error with the last time ?> Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169345 Share on other sites More sharing options...
trq Posted February 3, 2011 Share Posted February 3, 2011 Simple syntax errors really aren't something you should be posting on help forums about, your now missing a closing } If you indent your code these error will stand out. Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169348 Share on other sites More sharing options...
xxreenaxx1 Posted February 3, 2011 Author Share Posted February 3, 2011 Ohh.. But I am just having trouble with PHP though someone out there could help me. Will do Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169353 Share on other sites More sharing options...
jamesxg1 Posted February 3, 2011 Share Posted February 3, 2011 <?php //session_start();//Starting session $host="localhost"; // Host name $username="root"; // username $password=""; // password $db_name="Examination"; // Databasename $tbl_name="User"; // Tablename $username = $_POST["username"]; $password = $_POST["password"]; $login = $_GET["login"]; setcookies("username", $username, time()+86400); if($login == "yes") { // Connection to the server and database $connection = mysql_connect($host, $username, $password) or die(mysql_error()); mysql_select_db($db_name, $connection)or die(mysql_error()); $sql = "SELECT * FROM $tbl_name WHERE Use_Name='$username' and Use_Password='$password'"; $result = mysql_query($sql); if(mysql_num_rows($result) == 0) { echo "invlaid login"; } elseif(mysql_num_rows($result) == 1) { echo "welcome" . $_COOKIE["username"] . "whoever"; $_SESSION["username"] = $username; } ?> Should do the trick. James. Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169375 Share on other sites More sharing options...
xxreenaxx1 Posted February 3, 2011 Author Share Posted February 3, 2011 Thank you for the help Got it fixed Quote Link to comment https://forums.phpfreaks.com/topic/226553-syntax-error-unexpected-t_string/#findComment-1169452 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.