Jump to content

my form data is not making it into my sql table but records are created!


Michael_Baxter
Go to solution Solved by mac_gyver,

Recommended Posts

<?php
error_reporting(E_ALL);
ini_set("display_errors",1);

    if (isset($_POST['submit'] ) ) {
        $host_name  = "localhost";
        $database   = "DB name";
        $user_name  = "user name";
        $password   = "my p/w";
          
        $db = mysqli_connect( $host_name, $user_name, $password, $database );   
          
        if (!$db)   
        {   
            die("ERROR please try reloading or email mike@mnvb.co.uk: " . mysql_error());   
        }
        
        // example of inserting data into that table: 
        $sql = "INSERT INTO minis(name, score) " 
             . " VALUES( ?, ? )"; 
        
        $stmt = $db->prepare( $sql ); 
        if (!$stmt) 
        { 
            die("Failed to prepare statement: " . $sql); 
        } 
        
        // Get Values
        $name=$_POST['name'];
	$score="0";
        
        $stmt->bind_param("ss", $name, $score); 
        
        if ( ! $stmt->execute() ) 
        { 
            die("Execution of bound statement failed: " . $stmt->error); 
        }
        
        echo "Inserted {$stmt->affected_rows} correctly.<hr/>"; 
        
        $db->close();
    }
?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Music Cafe Minis</title>
    </head>
    
    <body>
    <div align="left">
        <form name="minis" action=""  method="post">
            <table width="274" border="0" align="center" cellpadding="2" cellspacing="0">
                <tr>
                    <td width="95"><div align="right">Name:</div></td>
                    <td width="171"><input type="text" name="name" /></td>
                </tr>
                
		<tr>
		<input type="hidden" name="score" value="0">
		</tr>
		
                <tr>
                    <td><div align="right"></div></td>
                    <td><input name="submit" type="submit" value="Submit" /></td>
                </tr>
            </table>
        </form>
        
        
        
    </body>
</html> 

I find this a little bazar ,

after all the help and work I have done using this forum in the past I have over come many hurdles but no matter how long I sit staring at my coding I cant see nothing to obvious I have error reporting turned on and I am also getting my message returned that 1 record was created successfully but when I go to phpmyadmin or my out put page the record is indeed there but the record is not showing the input data from my form as you will see in my codes my form consists of a text field labelled: name and a submit button,

once submitted I check my table records and the value inserted is 0 even though I type a name into the text field.......

so here is the codes:

Edited by Michael_Baxter
Link to comment
Share on other sites

haha lol ok that's so funny it made me laugh so hard my ribs hurt :)

I had already been into all those section of phpmyadmin join the day today just looking around for a possible answer and totally over looked that possibility,

but YES you were 100% right there I had left it set as a INT,

I've changed the type to a VARCHAR now this should allow alphanumeric input right?

and TADA just like a peace of magic its all fixed LOL,

as soon as I changed and save my table I went back to my form submitted a record  opened the output page and there it was 4 records of 0 values and then a 5th with my name in place.......

thank you mac_gyver,

 

P.S

     that's just the beginning of this extension project of my site i'm sure I have new things to need to learn to make the end product viable

and then I have to look through all of this and add some extra security files to stop hacking and spam injection

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.