Forum Moderators: coopster
I tried pulling out a small one inside other php that pulls items out of a database but pulling a php function out instead of just text didn't work. Can it be done? For instance how do people fill out new forms and such if a certain something is triggered and so on?
Thank you very much.
Are you talking about conditional control structures [us3.php.net]? Something like this:
if($name == "Bob") {
//do bob-related task
}
else if($name == "Smith") {
//do smith=related task
}
[edited by: eelixduppy at 5:28 am (utc) on Dec. 31, 2006]
So on the web page there is the form field with text from the database already in it. How can I change that form field to something else and then add it back into the database. I don't know how to
take the print command above and make it into a query insert.
//connect to database
if(empty($_POST['new_value'])) {
//get info from database: ie SELECT * FROM table
echo "<input type='text' value='".$row[col_name]."' size=12 name='new_value' />";
exit();
}
$new_value = $_POST['new_value'];
$query = "UPDATE table_name SET col_name = '".mysql_real_escape_string($new_value)."' WHERE some_col = 'something'";
//run query
Now you must look at the WHERE clause in the above query. It should only match ONE row so you have to decide how you are going to do that. I'm not sure if you have a unique id for each row, or you want to base it on something else? But whatever you choose, make sure that a user cannot change who the field changes for, otherwise you are creating a security issue.
I hope this explains something :)
Good luck!
That's pretty much what I had in mind, just didn't write it all out
Glad you got it! :)