Jump to content


Photo

FORM not posting - help me, please


  • Please log in to reply
12 replies to this topic

#1 phppup

phppup
  • Members
  • PipPipPip
  • Advanced Member
  • 286 posts

Posted 10 May 2018 - 10:16 PM

My form is not posting data to table.

I removed all validation to simplification purposes, yet onSubmit only provides a blank page.

 

I have used a script and verified connectivity to the db, and feel as if there is something wrong with my INSERT statement.

 

Here is my code:

 

my_form.php

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="POST" action="insert_file.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

insert_file.php

<?php

$host="localhost"; // Host name
$username="provided"; // Mysql username
$password="provided"; // Mysql password
$db_name="provided"; // Database name
$tbl_name="provided"; // Table name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

                 
// Get values from form
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];

   
// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";

}

else {
echo "ERROR";
}

// close connection
mysql_close();

?>

Do you see something that I've missed??

 



#2 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,874 posts
  • LocationWA

Posted 10 May 2018 - 10:33 PM

Find your php.ini and set
error_reporting = -1
display_errors = on
Then restart your web server and try the form again.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer

#3 phppup

phppup
  • Members
  • PipPipPip
  • Advanced Member
  • 286 posts

Posted 10 May 2018 - 11:07 PM

I added this immedately after my <? but got nothing.



#4 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,874 posts
  • LocationWA

Posted 10 May 2018 - 11:26 PM

Not the same thing. Gotta put it in php.ini.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer

#5 phppup

phppup
  • Members
  • PipPipPip
  • Advanced Member
  • 286 posts

Posted 11 May 2018 - 12:53 AM

I'm lost. Please be more specific with detailed instructions, if you would.

#6 phppup

phppup
  • Members
  • PipPipPip
  • Advanced Member
  • 286 posts

Posted 11 May 2018 - 02:10 AM

Note: My hosting service has said the server is fine and the problem is within my code. Does anyone see an issue or have any suggestions?

#7 NotionCommotion

NotionCommotion
  • Members
  • PipPipPip
  • Advanced Member
  • 1,601 posts

Posted 11 May 2018 - 02:16 AM

I'm lost. Please be more specific with detailed instructions, if you would.

http://php.net/manua...ration.file.php

 

This is where you change how you wish PHP to react to various events.  requinix (and so do I) recommends when developing that you set it up to blatantly tell you why you are getting errors.  Some of these settings must be set up in this file, yet others can also be set up on the fly.


NotionCommotion

#8 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,874 posts
  • LocationWA

Posted 11 May 2018 - 02:25 AM

Note: My hosting service has said the server is fine and the problem is within my code. Does anyone see an issue or have any suggestions?

Besides what I said? Not yet.

Your hosting provider should have given you some way to change PHP settings that doesn't involve code. Maybe it's with a .htaccess. Maybe it is in fact a php.ini file. Maybe it's something else.
Find it and make the changes I said.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer

#9 dodgeitorelse3

dodgeitorelse3
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationMassena, NY

Posted 11 May 2018 - 02:36 AM

should mysql_connect really have quotes around variables?



#10 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,194 posts
  • LocationVoorheesville NY

Posted 11 May 2018 - 02:49 AM

Should the OP even be USING the MySQL interface to his db? That said - does the content of '$tbl_name' contain a space char? YOu didn't wrap that in "" so that may be a problem.

And if you are going to use the MySQL functions, look up how to use the MySQL_error (?) function when trapping the results of your query call. Read The Manual - it is a great way to understand what you are doing and learn.
JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#11 irkevin

irkevin
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts
  • LocationMauritius

Posted 11 May 2018 - 09:02 AM

I believe it must be a typo somewhere in the declared variables. Either way, it will be hard to help without actually having a proper error message being displayed.

That being said, add the code below just after the opening PHP tag, and try submitting the form again

error_reporting(E_ALL);
ini_set('display_errors', '1');

PHP/MySQL Expert

Symfony Developer

 

Coding is F.U.N


#12 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,194 posts
  • LocationVoorheesville NY

Posted 11 May 2018 - 01:43 PM

Do what Irkevin says to turn on error checking since there doesn't seem to be any fatal errors stopping your script.

Then add some echo statements to display your script's progress. Show the input values; show the query statement also and be sure it is EXACTLY what you are expecting.
JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#13 phppup

phppup
  • Members
  • PipPipPip
  • Advanced Member
  • 286 posts

Posted 12 May 2018 - 11:20 PM

Got it working. Thanks for all the support.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users