 |
|
 |
Main Menu |
|
 |
Forums |
|
 |
Programming Contest |
|
 |
Documentation
|
|
 |
Partner
Sites |
|
 |
Sponsors |
|
 |
|
|
Register •
FAQ
• Search • Login
|
|
Page 1 of 1
|
[ 2 posts ] |
|
problem in inserting radio button values in mysql using php
Author |
Message |
prashantkadam9
Junior Member
Joined: Sun Oct 25, 2009 1:04 am Posts: 14
|
 problem in inserting radio button values in mysql using php
Dear Sir, I want to insert radio button value in mysql table from php form but it give error " Column count doesn't match value count at row 1 ". can anybody help me insolving problem. login.sql following column userid varchar(6) username varchar(255) email varchar(255) password varchar(255) status varchar(15) in above table status column take value from one selected ou of six radio button value. php file as below register.php <?PHP error_reporting(E_ALL & ~E_NOTICE); include("connect.php"); if(isset($_POST["submit"])) { //begin of if($submit). // Set global variables to easier names // and pervent sql injection and apostrophe to break the db. $userid = mysql_escape_string($_POST['userid']); $username = mysql_escape_string($_POST['username']); $email = mysql_escape_string($_POST['email']); $password = md5($_POST['password']); $status = $_POST['status']; switch($status){ case "Administrator": $status = "Administrator"; break; case "Recruitment": $status = "Recruitment"; break; case "Appraisal": $status = "Appraisal"; break; case "Leave": $status = "Leave"; break; case "Payroll": $status = "Payroll"; break; default: $status = "Employee"; break; } // lets check to see if the username already exists $checkuser = mysql_query("SELECT userid FROM login WHERE userid='$userid'"); $userid_exist = mysql_num_rows($checkuser); if($userid_exist > 0){ echo "I'm sorry but the userid you specified has already been taken. Please pick another one."; unset($userid); include "register.php"; exit(); } // lf no errors present with the username // use a query to insert the data into the database. $query = "INSERT INTO login(userid, username, email, password, status) VALUES('$userid, $username', '$email', '$password', '$status')"; mysql_query($query) or die(mysql_error()); mysql_close(); echo "You have successfully Registered"; echo "<meta http-equiv=Refresh content=4;url=index.php>"; }//end of if($submit). // If the form has not been submitted, display it! else { //beginn of else ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <form name="login" method="post" action="<?php echo $PHP_SELF ?>"> <table border="0" width="400" align="center" > <tr> <td width="600" bgcolor="#999999"> <p align="center"><font color="blue"><span style="font-size:20pt;"><b>Registration</b></span></font></p> </td> </tr> <tr> <td width="219"> <table border="0" width="325" align="center"> <tr> <td width="116"><span style="font-size:12pt; color:blue;">User ID</span></td> <td width="200"><input type="text" name="userid" maxlength="100"></td> </tr> <tr> <td width="116"><span style="font-size:12pt; color:blue;">User Name</span></td> <td width="200"><input type="text" name="username" maxlength="100"></td> </tr> <tr> <td width="116"><span style="font-size:12pt; color:blue;"">E-mail</span></td> <td width="200"><input type="text" name="email"></td> </tr> <tr> <td width="116"><span style="font-size:12pt; color:blue;">Password</span></td> <td width="200"><input type="password" name="password"></td> </tr> <td width="116"> <span style="font-size:12pt; color:blue;"">User Rights </span></td> <td width="200"><input type="radio" name="status" value="Administrator" //<?php if ($status=="Administrator" || !isset($status)) echo "checked"; ?> > <span style="font-size:12pt; color:blue;"">Administrator </span></td> </tr> <tr> <td width="116"> </td> <td width="200"><input type="radio" name="status" value="Recruitment" // <?php if ($status=="Recruitment" || !isset($status)) echo "checked"; ?> > <span style="font-size:12pt; color:blue;">Recruitment </span></td> </tr> <tr> <td width="116"> </td> <td width="200"><input type="radio" name="status" value="Appraisal" //<?php if ($status=="Appraisal" || !isset($status)) echo "checked"; ?> > <span style="font-size:12pt; color:blue;"">Appraisal </span></td> </tr> <tr> <td width="116"> </td> <td width="200"><input type="radio" name="status" value="Leave" //<?php if ($status=="Leave" || !isset($status)) echo "checked"; ?> > <span style="font-size:12pt; color:blue;"">Leave </span></td> </tr> <tr> <td width="116"> </td> <td width="200"><input type="radio" name="status" value="Payroll" //<?php if ($status=="Payroll" || !isset($status)) echo "checked"; ?> > <span style="font-size:12pt; color:blue;"">Payroll </span></td> </tr> <tr> <td width="116"> </td> <td width="200"><input type="radio" name="status" value="Employee" //<?php if ($status=="Employee") echo "checked"; ?> > <span style="font-size:12pt; color:blue;"">Employee </span></td> </tr> <tr> <td width="116"> </td> <td width="200"> <p align="right"><input type="submit" name="submit" value="S u b m i t"></p> </td> </tr> </table> </td> </tr> <tr> <td width="600" bgcolor="#999999"> </td> </tr> </table> </form> </HTML> <?php }//end of else ?> thanks in advance. regards, Prashant Kadam
|
Tue Dec 22, 2009 2:41 am |
|
 |
phprogue
Junior Member
Joined: Tue Dec 01, 2009 8:34 pm Posts: 7 Location: Ohio, USA
|
The following line is missing a single quote after $userid and a single quote before $username. Mysql will see '$userid, $username' as one field.
$query = "INSERT INTO login(userid, username, email, password, status) VALUES('$userid, $username', '$email', '$password', '$status')";
_________________ phpRogue - PHP, MySQL, HTML, CSS, Javascript (+ Ajax) HackWorks: PHP game development blog and forum Sandstorm Media: Web applications development
|
Wed Dec 23, 2009 11:01 am |
|
 |
|
|
Page 1 of 1
|
[ 2 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
|
|