adamjones Posted October 20, 2008 Share Posted October 20, 2008 Ok. So on my CMS, I have tips that popup. Basically, when a user closes a tip, they are sent to 'turntip1off.php', and it should set 'tips' in the database to 'off', but I am getting an error. This is a snippet from my CMS, where the tips appear; <?php $host="localhost"; $username="wowdream_domaine"; $password="password"; $db_name="wowdream_domaine"; $tbl_name="members"; 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 username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ if ($rows['tips1'] == on) { echo "<p id='tip' class='alert'> <span class='txt'><span class='icon'></span><strong>Tip:</strong> You should always 'Sign Out' before leaving the Admin Panel.</span> <a href='turntip1off.php'><span class='bg'></span>Close</a> </p>"; } else { echo ""; } } ?> And this is the 'turntip1off.php' code; <?php $host="localhost"; $username="wowdream_domaine"; $password="password"; $db_name="wowdream_domaine"; $tbl_name="members"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="UPDATE `$tbl_name` WHERE username='$myusername' and password='$mypassword' SET `tips1`='off' WHERE `tips1`='on'"; $result=mysql_query($sql); if($result){ header("location:admin.php"); } else { echo "ERROR"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/ Share on other sites More sharing options...
DarkWater Posted October 20, 2008 Share Posted October 20, 2008 ...What error are you actually getting? Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670323 Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 Well, seen as it's just 'echo "ERROR";', I'm getting 'ERROR'. What should I type instead to make it display the error? Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670327 Share on other sites More sharing options...
DarkWater Posted October 20, 2008 Share Posted October 20, 2008 Change that line to 'mysql_error();' and show me the new output. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670329 Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/wowdream/public_html/domaine/admin/beta/turntip1off.php on line 20 Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670333 Share on other sites More sharing options...
johntp Posted October 20, 2008 Share Posted October 20, 2008 Why dont you try in turntrip1off. <?php $host="localhost"; $username="wowdream_domaine"; $password="password"; $db_name="wowdream_domaine"; $tbl_name="members"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql= "UPDATE $tbl_name SET tips1 = 'off' WHERE username='$myusername' AND password= '$mypassword'"; $result=mysql_query($sql); if($result){ header("location:admin.php"); } else { echo "ERROR"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670337 Share on other sites More sharing options...
trq Posted October 20, 2008 Share Posted October 20, 2008 This line... if ($rows['tips1'] == on) { ought be.... if ($rows['tips1'] == 'on') { for starters. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670339 Share on other sites More sharing options...
DarkWater Posted October 20, 2008 Share Posted October 20, 2008 Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/wowdream/public_html/domaine/admin/beta/turntip1off.php on line 20 You weren't supposed to put the damn quotes. =/ Just change that whole line to: mysql_error(); Remove the echo and everything. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670343 Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 @ johntp: This is ust redirecting me to 'admin.php' and not actually updating the database. @ thorpe: Thanks. Changed it - but it's still not working. @ DarkWater: I did. It just came up blank with no error. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670344 Share on other sites More sharing options...
PFMaBiSmAd Posted October 20, 2008 Share Posted October 20, 2008 Once you get the code modified so that the mysql_error() statement will tell you why the query failed, it will report an sql syntax error. This is the syntax prototype of an UPDATE query (taken from the mysql manual) - UPDATE [LOW_PRIORITY] [iGNORE] tbl_name SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] The items are shown in the order they need to appear in to make a valid statement. []'s enclose optional items, but when they are present, they must be in the order shown in the syntax prototype. For your query - UPDATE tbl_name SET col_name1=expr1 WHERE where_condition Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670346 Share on other sites More sharing options...
johntp Posted October 20, 2008 Share Posted October 20, 2008 Lets get it to show your error change your turntip1off to this <?php $host="localhost"; $username="wowdream_domaine"; $password="password"; $db_name="wowdream_domaine"; $tbl_name="members"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $query = "UPDATE $tbl_name SET tips1='off' WHERE username= '$myusername' AND password='$mypassword'"; mysql_query($query) or die('Error, insert query failed: '.mysql_error()); header("Location: admin.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670351 Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 It's not displaying an error- it just goes to 'admin.php'. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670355 Share on other sites More sharing options...
johntp Posted October 20, 2008 Share Posted October 20, 2008 and still not updating the tips1? Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670358 Share on other sites More sharing options...
DarkWater Posted October 20, 2008 Share Posted October 20, 2008 $myusername and $mypassword are not set, therefore they aren't being put into the query. It's not technically an SQL error, it's just a logical error on your part. Set the variables. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670359 Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 They are set in 'checklogin.php'- the page they are directed to after they login. They wouldn't be able to access the admin panel without it! Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670362 Share on other sites More sharing options...
johntp Posted October 20, 2008 Share Posted October 20, 2008 but you still have to call for the variables on each page. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670365 Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 Right. Ok. Seems to be working. Cheers for your help. Quote Link to comment https://forums.phpfreaks.com/topic/129300-solved-flippin-php-errors/#findComment-670375 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.