Update MySQL DB from a form
Moderator: General Moderators
Update MySQL DB from a form
Hi guys,
I am now trying to update a MySQL DB from a form.
The L_ID is the name of the row in the DB and the name of the value from the <select> tag.
Can you help?
$myrow = ($_POST['L_ID']);
mysql_query("UPDATE login SET level = '2' WHERE L_ID = ". $myrow["L_ID"] .";");
I am now trying to update a MySQL DB from a form.
The L_ID is the name of the row in the DB and the name of the value from the <select> tag.
Can you help?
$myrow = ($_POST['L_ID']);
mysql_query("UPDATE login SET level = '2' WHERE L_ID = ". $myrow["L_ID"] .";");
Re: Update MySQL DB from a form
Have also tried this but this doesn't work either.
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. ";");
header('Location: admin2.php');
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. ";");
header('Location: admin2.php');
Re: Update MySQL DB from a form
try this to see if it works..
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
header('Location: admin2.php');
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
header('Location: admin2.php');
Re: Update MySQL DB from a form
No sorry
The database doesn't change to a 2
The database doesn't change to a 2
Re: Update MySQL DB from a form
did you get any errors ? or it just doesnt do anything?
Re: Update MySQL DB from a form
doesn't do anything, just goes back to the page admin2.php
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
header('Location: admin2.php');
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
header('Location: admin2.php');
Re: Update MySQL DB from a form
show me your html post form. Maybe you get the value from the form wrong and thats why the query doesnt work. Do you put all the values from the form into an array called "L_ID"
Re: Update MySQL DB from a form
HTML Page but the <select> tag is populated by the DB. L_ID is the name of one of the rows in the DB
admin2.php
$sql = ("SELECT firstName FROM login order by firstName");
$result = mysql_query($sql, $link);
?>
<form name="level" method="post" action="levelSQL.php">
<select name="L_ID">
<?
while($myrow = mysql_fetch_array($result)) {
echo "<option value=" . $myrow["L_ID"] . ">" . $myrow["firstName"]. "</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td width="127"> </td>
</tr>
<tr>
<td><input name="submit2" type="submit" value="Upload Level"></td>
</tr>
</form>
levelSQL.php
mysql_query("UPDATE login SET access = 2 WHERE L_ID = " .$_POST['L_ID']. "\"");
header('Location: admin2.php');
admin2.php
$sql = ("SELECT firstName FROM login order by firstName");
$result = mysql_query($sql, $link);
?>
<form name="level" method="post" action="levelSQL.php">
<select name="L_ID">
<?
while($myrow = mysql_fetch_array($result)) {
echo "<option value=" . $myrow["L_ID"] . ">" . $myrow["firstName"]. "</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td width="127"> </td>
</tr>
<tr>
<td><input name="submit2" type="submit" value="Upload Level"></td>
</tr>
</form>
levelSQL.php
mysql_query("UPDATE login SET access = 2 WHERE L_ID = " .$_POST['L_ID']. "\"");
header('Location: admin2.php');
Re: Update MySQL DB from a form
OK, I noticed once I paste the code in here that I hadn't added L_ID into the Select firstName from... code.
This then changed the 1 to a 2 but then when I selected another name, it didn't change it
This then changed the 1 to a 2 but then when I selected another name, it didn't change it
Re: Update MySQL DB from a form
try to print the an array $_POST to see if you can get any value..
print_r($_POST);
put this line in the file levelSQL.php
print_r($_POST);
put this line in the file levelSQL.php
Re: Update MySQL DB from a form
No error 
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
print_r($_POST);
header('Location: admin2.php');
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
print_r($_POST);
header('Location: admin2.php');
Re: Update MySQL DB from a form
you mean you don't get any value from the form?
Re: Update MySQL DB from a form
Sorry, just copy the code below and paste into your file levelSQL.php
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
print_r($_POST);
//header('Location: admin2.php');
because you didn't put 2 slashes infront of header before, thats why it redirect you to admin2 page
mysql_query("UPDATE login SET access = 2 WHERE firstName = " .$_POST['firstName']. "\"");
print_r($_POST);
//header('Location: admin2.php');
because you didn't put 2 slashes infront of header before, thats why it redirect you to admin2 page
Re: Update MySQL DB from a form
Array ( [L_ID] => 32 [submit2] => Upload Level )
whatever that means lol
whatever that means lol
Re: Update MySQL DB from a form
yep
, lets try this then..
$myrow = $_POST['L_ID'];
mysql_query("UPDATE login SET level = 2 WHERE L_ID = \"$myrow\" ");
$myrow = $_POST['L_ID'];
mysql_query("UPDATE login SET level = 2 WHERE L_ID = \"$myrow\" ");