Form Submit help! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Form Submit help!

I made a video of the problem you can watch it here: http://metrikcorp.com/test/rate/video/ 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: http://www.metrikcorp.com/test/rate <!DOCTYPE html> <html> <head> <title>Image Rating</title> <script> function validateForm() { var x = document.forms["Rating"]["rating_number"].value; if (x

27th Nov 2016, 5:14 PM
Metrik 🕵
Metrik 🕵 - avatar
10 Answers
+ 5
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?
27th Nov 2016, 6:02 PM
Metrik 🕵
Metrik 🕵 - avatar
+ 4
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: http://metrikcorp.com/test/rate/video/
27th Nov 2016, 5:13 PM
Metrik 🕵
Metrik 🕵 - avatar
+ 3
What do you want actually, print error message if text field is empty, right?
27th Nov 2016, 5:28 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
Aditya kumar pandey: ya thats fine. as long as it stops the form from submiting blank info when load or refreshed.
27th Nov 2016, 5:34 PM
Metrik 🕵
Metrik 🕵 - avatar
+ 3
what? I did not understand it.
27th Nov 2016, 5:36 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
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?
27th Nov 2016, 7:36 PM
Metrik 🕵
Metrik 🕵 - avatar
+ 3
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
28th Nov 2016, 2:38 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
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"; ?>
29th Nov 2016, 10:27 PM
Metrik 🕵
Metrik 🕵 - avatar
+ 2
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 😭😭😭
3rd Dec 2016, 10:25 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
when you click on the play video image nothing will show its blank.i thought it should be image only or img ??
27th Nov 2016, 7:29 PM
Chibu Nathy
Chibu Nathy - avatar