TheCatapult Posted March 18, 2012 Share Posted March 18, 2012 Sorry guys if I have asked many basics questions, simultaneously. Hi! I made an HTML form for the Update page. Here's the code. <form action="djselect.php" method="post">current dj: <input type="text" name="iselectdj" /><input type="submit" /></form> Here's the djselect.php. <?$con = mysql_connect("","","");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("", $con);mysql_query("UPDATE diskjockey1 SET jockey=$_POST['iselectdj']WHERE id=0");mysql_close($con);?> It has a problem. When I remove the [ and ], it works but it does not write the one I put in the HTML form in database. Please help me. Many thanks! Link to comment Share on other sites More sharing options...
Don E Posted March 18, 2012 Share Posted March 18, 2012 One thing you can do is take what's in $_POST['iselectedj']; and assign it to a variable:$selected = $_POST['iselectedj'];Then with your query have something like this: "UPDATE diskjockey1 SET jockey = '$selected' WHERE id=0" Link to comment Share on other sites More sharing options...
birbal Posted March 18, 2012 Share Posted March 18, 2012 ...or you can also interpolate the array inside double quotesmysql_query("UPDATE diskjockey1 SET jockey={$_POST['iselectdj']}WHERE id=0"); Link to comment Share on other sites More sharing options...
TheCatapult Posted March 18, 2012 Author Share Posted March 18, 2012 <?$con = mysql_connect("","","");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("", $con);$selected = $_POST['iselectedj'];mysql_query("UPDATE diskjockey1 SET jockey='$selected'WHERE id=0");mysql_close($con);?> Here's the new code.No text is written in my database. Why? Thanks! Link to comment Share on other sites More sharing options...
birbal Posted March 18, 2012 Share Posted March 18, 2012 make sure $_POST['isselected'] have value. echo it to test itif it is ok check mysql_query() is successing or not and if failing print out the reason using mysql_error() to debug. $res=mysql_query("UPDATE diskjockey1 SET jockey='$selected'WHERE id=0");if(!$res)echo mysql_error(); Link to comment Share on other sites More sharing options...
Starfall Posted March 18, 2012 Share Posted March 18, 2012 Use concatenation or sprintf. <?$con = mysql_connect("","","");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("", $con);$query=sprintf("UPDATE diskjockey1 SET jockey='%s' WHERE id=0",$_POST['iselectdj']);mysql_query($query);mysql_close($con);?> If it still does not work, something is wrong with your database connection. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.