spode Posted May 25, 2007 Share Posted May 25, 2007 I'm getting this error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in crud.php on line 13 Heres the script (i'm only working on the first case...thats why it's incomplete) <?php $host = "********"; $username = "********"; $password = "*********"; $dbc = mysql_connect($host, $username, $password) or die (mysql_error()); $select = mysql_select_db('colsim0_mysql'); switch($action) { case "edit": if (isset($_POST['submit'])) { $insertinfo = "UPDATE tbl_users SET username=$_POST['uname'],password=$_POST['npass'] WHERE uid=$uid"; if (mysql_query($insertinfo)) { echo "Information successfully updated!"; } else { echo "Information failed to update because " . mysql_error(); } } else { echo "<h1>Edit Information</h1> <form action=\"crud.php\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"uname\" size=\"20\"></td> </tr> <tr> <td>Current Password:</td> <td><input type=\"text\" name=\"cpass\" size=\"20\"></td> </tr> <tr> <td>New Password:</td> <td><input type=\"text\" name=\"npass\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Update\"> </form> </table>"; } break; } //case "delete": ?> Thanks for the help. If I need to include the file that comes before this...just let me know. Quote Link to comment Share on other sites More sharing options...
Caesar Posted May 26, 2007 Share Posted May 26, 2007 <?php $insertinfo = "UPDATE tbl_users SET username=$_POST['uname'],password=$_POST['npass'] WHERE uid=$uid"; ?> <?php $username = $_POST['uname']; $password = $_POST['npass']; $insertinfo = "UPDATE tbl_users SET username='$username',password='$password' WHERE uid='$uid'"; ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted May 26, 2007 Share Posted May 26, 2007 <?php $host = "********"; $username = "********"; $password = "*********"; $dbc = mysql_connect($host, $username, $password) or die (mysql_error()); $select = mysql_select_db('colsim0_mysql'); switch($action) { case "edit": if (isset($_POST['submit'])) { $insertinfo = "UPDATE tbl_users SET username=" . $_POST['uname'] . ",password=" . $_POST['npass'] . " WHERE uid=$uid"; if (mysql_query($insertinfo)) { echo "Information successfully updated!"; } else { echo "Information failed to update because " . mysql_error(); } } else { echo "<h1>Edit Information</h1> <form action=\"crud.php\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"uname\" size=\"20\"></td> </tr> <tr> <td>Current Password:</td> <td><input type=\"text\" name=\"cpass\" size=\"20\"></td> </tr> <tr> <td>New Password:</td> <td><input type=\"text\" name=\"npass\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Update\"> </form> </table>"; } break; } //case "delete": ?> Array values, when referring to them you need to concat them. The above should work now. Quote Link to comment Share on other sites More sharing options...
spode Posted May 26, 2007 Author Share Posted May 26, 2007 Ok, now whenever I submit the form...I get a blank page...any ideas? ??? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 Where is $action defined at? Quote Link to comment Share on other sites More sharing options...
spode Posted May 26, 2007 Author Share Posted May 26, 2007 On the previous page...there are two buttons Edit and Delete...the link for edit is crud.php?uid={$list['uid']}&action=edit Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 are you sure that it's being passed from page to page correctly? Place a "default" on your select statement... switch($action) { case "edit": ............. break; } case "delete": ............ break; default: echo 'Action not found...'; } Quote Link to comment Share on other sites More sharing options...
spode Posted May 26, 2007 Author Share Posted May 26, 2007 Ok the 'Action not found' came up after I hit submit this time...Here's the file that you visit first: <?php $dbc = mysql_connect($host, $username, $password) or die (mysql_error()); $dbselect = mysql_select_db('colsim0_mysql') or die (mysql_error()); $retrieve = 'SELECT uid, username, password FROM tbl_users'; $result = mysql_query($retrieve); while($list = mysql_fetch_array($result)) { echo "<p><a href=\"crud.php?uid={$list['uid']}&action=edit\">Edit Password</a> <a href=\"crud.php?uid={$list['uid']}&action=delete\">Delete</a> {$list['username']}</p>"; } echo '<br /><br />'; echo "<p>Don't have an account? Register by clicking <a href=\"crud.php?action=new\">here</a></p>"; mysql_close(); ?> And here's the one after it (the one we've been looking at.) <?php $dbc = mysql_connect($host, $username, $password) or die (mysql_error()); $select = mysql_select_db('colsim0_mysql'); switch($action) { case "edit": if (isset($_POST['submit'])) { $insertinfo = "UPDATE tbl_users SET username=" . $_POST['uname'] . ",password=" . $_POST['npass'] . " WHERE uid=$uid"; if (mysql_query($insertinfo)) { echo "Information successfully updated!"; } else { echo "Information failed to update because " . mysql_error(); } } else { echo "<h1>Edit Information</h1> <form action=\"crud.php\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"uname\" size=\"20\"></td> </tr> <tr> <td>Current Password:</td> <td><input type=\"text\" name=\"cpass\" size=\"20\"></td> </tr> <tr> <td>New Password:</td> <td><input type=\"text\" name=\"npass\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Update\"> </form> </table>"; } break; default: echo "Action not found."; break; } ?> hmmm Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 First, remove your connection credentials for mysql. Your server probably has register globals turned off. Try assigning the value to $acstion... $action = $_GET['action']; Quote Link to comment Share on other sites More sharing options...
spode Posted May 26, 2007 Author Share Posted May 26, 2007 Action not found...i'm stumped. is my syntax wrong when i'm linking the pages for assigning the variables? Quote Link to comment Share on other sites More sharing options...
spode Posted May 26, 2007 Author Share Posted May 26, 2007 Problem solved. The variable action wasnt defined the second time through. So in the form the action was simply crud.php. When it needed to be crud.php?action=edit Thanks 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.