Dear friend, I am Just Creating News Page in my website so i create html form with only one textarea and i also create database one text field, i want to know how can i insert data into mysql databse and how can i update it, i want to insert data only first time when databse is blank, other time i want to only update same data, i dont want to create second row, so plz help if anybody have idea. Thanks
For example: <form method='post' action='form.php'> <input type='text' name='username' maxlength='20'> <input type='submit' value='Submit'> </form> Form.php: <?php $username=funtion($_POST[username]); if(empty($username)){ echo 'Some field is empty.'; }else{ // here query // you can make a query in your phpmyadmin en change this with $username } ?> Mind: you have to make function "function"... (see php.net) Chamaro
That's totally wrong, if you don't know the answer to a question then do not attempt to answer it. @op can we see the orginal form so we can make code that will work for you without you editing it ? also a description of the database would be good, or a dump from phpmyadmin even better.
Friend now i add the record by following way, record added successfully but my problem is different that i want to add new record if database is blank otherwise any record is present i want to update "present record" it. it means i want to handle only single record how can i do it? <? $host = "localhost"; $username="dbusername"; $password="dbpassword"; $database="dbname"; $con = mysql_connect($host, $username, $password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); $sql="INSERT INTO home (content) VALUES ('$_POST[homecontent]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?>