Jump to content

Posting data to mysql using a form


chaddsuk

Recommended Posts

Hi im probably going stupidly wrong with this but i cant seem to post data using the form below, the table shows ok and works fine i just cant add data to the table using the form.

 

am i doing something really stupid?

 

thanks

 

chris

 

 

<?php
     require "config.php";
?>


<form action="<?php mysql_query("INSERT INTO users (autoID, name)");?>" method="post">
name: <input type="text" name="name" />

<input type="submit" />
</form>





<?php

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT name FROM users")
or die(mysql_error());  

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry 

      

// just some random data in an array
$age = "27";
$data = array('an','example','to','show','the','alternating','row','colors');
$rows = count($data);
// the two colors to switch between
$rowcolor1 = '#F0F0F2';
$rowcolor2 = '#FFFFFF';
// the background colors on mouseover
$hovercolor1 = '#BAD4EB';
$hovercolor2 = '#DCE9F4';


echo '
<center><table style="caption-side: top; 
border: 0.1em solid #eee;
border-collapse: collapse; 
margin: 1em; 
width: 30em;">
<caption style="font-weight: bold;">Demonstration of alternate row colors</caption>';
for($n = 0; $n < $rows; $n++)
{
// this is where the magic happens

			 if($n % 2 == 1)

			     {

			         // add more things to swop with each cycle

			         $style = $rowcolor1;

			         $hoverstyle = $hovercolor1;

		  }else{

			         $style = $rowcolor2; 

			         $hoverstyle = $hovercolor2;

			     }

			  

			     echo '

			    <tr id="row'.$n.'" style="background:'.$style.';"

			         onmouseover="this.style.background=\''.$hoverstyle.'\'"

			         onmouseout="this.style.background=\''.$style.'\'">

			         <td style="padding: 0.3em 1em;">'.$row[$n].'</td>

			     </tr>';

			 }

			  

			 echo '

			 </table></center>';

?>

 

Use

 tags - roopurt18[/b]
Link to comment
Share on other sites

Oh dear.

 

action="<?php mysql_query("INSERT INTO users (autoID, name)");?>" 

action is an HTML attribute that tells the browser which URL to submit the form to.  You do not put a call to mysql_query() as the action for a form.

 

Also, your MySQL statement is incorrect.

 

Try reading the tutorial that was linked to in the previous post.

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.