lewisstevens1 Posted April 12, 2009 Share Posted April 12, 2009 Hello i need some help updating a field in my database, i dont know what i am doing wrong...heres my code. <?php $con = mysql_connect("localhost","*********","**********"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("**********", $con); mysql_query("UPDATE available SET sex= 'Male' WHERE id = '1'");mysql_close($con); ?> available = table | sex = field I on the front page it says if they are male or female, what i want is it to change when they click a button, it has to be on a seperate page, so i thought just add the Male/Female words in a database and then just recall that, i can recall that, though when i update the field, it does nothing. if i add a field it will show it twice. What can i do? please can someone help Many thanks Lewis Stevens Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/ Share on other sites More sharing options...
ratcateme Posted April 12, 2009 Share Posted April 12, 2009 try this code <?php $con = mysql_connect("localhost","*********","**********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("**********", $con); mysql_query("UPDATE available SET sex= 'Male' WHERE id = '1'",$con) or die(mysql_error($con)); mysql_close($con); that will exit if there is a error with your query. and hopefully tell you what is going wrong Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808233 Share on other sites More sharing options...
lewisstevens1 Posted April 12, 2009 Author Share Posted April 12, 2009 Parse error: syntax error, unexpected T_VARIABLE in /home/stonersg/public_html/darkfamily/process.php on line 10 Line 10: mysql_query("UPDATE available SET sex='Male' WHERE id = '1'" $con) or die(mysql_error($con)); Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808238 Share on other sites More sharing options...
ratcateme Posted April 12, 2009 Share Posted April 12, 2009 you missed in my code there is a , after the query and before $con the line you posted missed that out Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808240 Share on other sites More sharing options...
lewisstevens1 Posted April 12, 2009 Author Share Posted April 12, 2009 Ah...sorry, such a silly mistake lol. Well, no error, though no change to the database either. =S What do you think could be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808242 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 Mmm ratcateme or anyone? still able to help? please? Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808253 Share on other sites More sharing options...
ratcateme Posted April 13, 2009 Share Posted April 13, 2009 well try this mysql_query("UPDATE available SET sex= 'Male' WHERE id = '1'",$con) or die(mysql_error($con)); echo mysql_affected_rows($con); mysql_close($con); are you sure there is a row with an ID of 1 and a sex of Female? other wise you wont see anything Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808266 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 Well i using sorta same code as the one to get the data to display before the update the next code will make more sense if you read the private message i sent you. $result = mysql_query("SELECT * FROM available WHERE id='1'"); while($row = mysql_fetch_array($result)) { echo "<td><font color='green'> ". $row['deathknight'] . "<br></font></td>"; mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808270 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 Ok? Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808286 Share on other sites More sharing options...
ratcateme Posted April 13, 2009 Share Posted April 13, 2009 looking at that and the PM i still can't see any reasons why it wont update. the only thing i can think of done but have you tired the echo mysql_affected_rows also are there any other if's around the update section that could stop the update from happening? they might need rechecking also try to add say echo "UPDATING NOW"; on the line after the query to make sure it gets to that line? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808288 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 the only ifs i have are: if (!$con) { die('Could not connect: ' . mysql_error()); } in the connection variable though between my connection part, and the echo part there is a function i am not sure, if needed. i will signify with wrapping --------- around it. mysql_select_db("stonersg_darkfamily", $con); ------------------------------------------------------------------ $result = mysql_query("SELECT * FROM available WHERE id='1'"); ------------------------------------------------------------------ echo "Recruitment Table:<br><br>"; ?> <div id="class" div align="left"> <?php while($row = mysql_fetch_array($result)) { echo "<tr><img src='classimg/deathknight_small.gif'> Death Knight:"; echo "<td><font color='green'> ". $row['deathknight'] . "<br></font></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808502 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 woah i accidently echoed it within the wrong document, the one that is ment to have the words change once it echos from the database, though i had nothing change when i echoed here echo "<tr><img src='classimg/warrior_small.gif'> Warrior:"; echo "<td><font color='green'> " . $row['warrior'] . "<br></font></td>"; echo "Updating Now Inside"; echo "</tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808503 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 though i may have forgot the <p> tags there, though i tried in process.php here and i am not getting any sort of output...just a blank screen like usual. <?php //Deathknight Available-Not Available $con = mysql_connect("localhost","stonersg_dfadmin","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("stonersg_darkfamily", $con); mysql_query("UPDATE available SET deathknight='Available' WHERE id = '1'", echo "<p>Hi</p>";$con) or die(mysql_error($con)); mysql_close($con); echo "<p>Vye</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808504 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 Any thoughts mate? Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808508 Share on other sites More sharing options...
ratcateme Posted April 13, 2009 Share Posted April 13, 2009 also what is error reporting set to? it looks to me like maybe error reporting is not set to show errors check you php.ini file but i dont think that is the problem because you got a error printed out but check it anyway Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808509 Share on other sites More sharing options...
PFMaBiSmAd Posted April 13, 2009 Share Posted April 13, 2009 The posted code contains a fatal parse error, because you cannot put echo statements inside of other statements. You must follow the syntax that each statement requires. You should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini (stop and start your web server to get any change made to php.ini to take effect.) By doing this, your blank page will instead show the fatal parse error that is preventing it from executing. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808510 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 display errrors_on also in my error log there is no error which are displayed for today. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808512 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 actually...mines not displaying any kind of error, not even in my error log...and the display errors_on in php.ini is set to on. lol i just echoed anywhere just to try and display some kind of error or an echoed statement as its not displaying else. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808513 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 also i found error_reporting = E_ALL & ~E_NOTICE Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808515 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 So what could be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808522 Share on other sites More sharing options...
PFMaBiSmAd Posted April 13, 2009 Share Posted April 13, 2009 What does a phpinfo() statement show for the error_reporting and display_errors settings? Error_reporting should be E_ALL. Get rid of the & ~E_NOTICE Also, is the php.ini that you are looking at the same one that php is using? What does the phpinfo() show for Loaded Configuration File? Edit: There is no setting display errors_on. It's display_errors Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808524 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 sorry i lost you there, all i have is a php.ini file...i dont have a cllue that the phpinfo() is. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808532 Share on other sites More sharing options...
PFMaBiSmAd Posted April 13, 2009 Share Posted April 13, 2009 <?php phpinfo(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808535 Share on other sites More sharing options...
lewisstevens1 Posted April 13, 2009 Author Share Posted April 13, 2009 Parse error: syntax error, unexpected T_VARIABLE in /home/stonersg/public_html/darkfamily/process.php on line 11 line 11: mysql_query("UPDATE available SET deathknight='Available' WHERE id = '1'"$con) or die(mysql_error($con)); Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808587 Share on other sites More sharing options...
premiso Posted April 13, 2009 Share Posted April 13, 2009 mysql_query("UPDATE available SET deathknight='Available' WHERE id = '1'", $con) or die(mysql_error()); You were missing the , before $con in the mysql_query portion. Quote Link to comment https://forums.phpfreaks.com/topic/153787-solved-update-field-help-please/#findComment-808591 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.