Jump to content

form w/ update php


TheCatapult

Recommended Posts

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

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

...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

<?$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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...