Form Submit help! | Sololearn: Learn to code for FREE!


Form Submit help!

I made a video of the problem you can watch it here: so i have a form and every time some one goes to it automatically submits the form blank. it will also do this if you refresh the page. How can i go about stopping this? see the form live here: <!DOCTYPE html> <html> <head> <title>Image Rating</title> <script> function validateForm() { var x = document.forms["Rating"]["rating_number"].value; if (x

11/27/2016 5:14:16 PM

Metrik 🕵

10 Answers

New Answer


when ever you go to my form it will automatically submit into mysql database (as shown in video) I do not want it to submit unless the submit button is pressed. does that make more sense?


Sandeep chatterjee: i am still seeing the issue on my end. every time i go to it or hit the refresh it adds one vote to my database and it is blank. I made a video of the problem you can watch it here:


What do you want actually, print error message if text field is empty, right?


Aditya kumar pandey: ya thats fine. as long as it stops the form from submiting blank info when load or refreshed.


what? I did not understand it.


Chibu Nathy: what do you mean? when you click on the video link nothing happens? if so what kinda browser(google, IE, firefox, ect) you using and what kinda device? desktop, mobile, tablet?


Than this problem is arise due to your SQL implementation. Please show that code. I know you want to find answer, but hey How can I help if I don't know the code. Sorry for late reply


Aditya kumar pandey: sorry for the long delay in response. Here is my code. <?php $con = mysql_connect("localhost","UserName","Password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("rateImage", $con); $sql="INSERT INTO post_rating (rating_number) VALUES ('$_POST[rating_number]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ?> <?php $Get = "select sum(rating_number) from post_rating"; $q = mysql_query($Get); $row = mysql_fetch_array($q); $NUMB = $row[0]; ?> <?php $link = mysql_connect("localhost", "UserName", "Password"); mysql_select_db("rateImage", $link); $result = mysql_query("SELECT * FROM post_rating", $link); $num_rows = mysql_num_rows($result); $NumRow = "$num_rows"; ?>


Sorry, I was forget about that. What is your PHP version of your server. If it is 5.5 or higher please use mysqli function and add i after MySQL in all function. Also, insert data only if $_POST[rating_number] is not null. Please forgive me. Sorry 😭😭😭


when you click on the play video image nothing will show its blank.i thought it should be image only or img ??