0

I'm fetching data from database but problem is if i leave my field blank then result is shown like attached file...

I want that if field is empty then auto value set into "N/A" .

Is it possible from phpMyAdmin-2.11.10.

Please reply

Thanks
Farhan.

Attachments farhan.JPG 56.9 KB
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Nyight
0

add a default when creating a new table in mysql in phpmyadmin

ex

CREATE TABLE IF NOT EXISTS `foo`.`example_01` (
 `field_1` VARCHAR(255) NOT NULL DEFAULT 'N/A'
)

note that if you enter an empty string in PHP, ex $_POST=''; it will save as an empty string.

also it'll help us understand more if you post a bit of your code where the data is being fetched

Edited by qazplm114477: n/a

0

add a default when creating a new table in mysql in phpmyadmin

ex

CREATE TABLE IF NOT EXISTS `foo`.`example_01` (
 `field_1` VARCHAR(255) NOT NULL DEFAULT 'N/A'
)

note that if you enter an empty string in PHP, ex $_POST=''; it will save as an empty string.

also it'll help us understand more if you post a bit of your code where the data is being fetched

<?php
$code=$_REQUEST['code'];
$name=$_REQUEST['name'];
$qualification=$_REQUEST['qualification'];
$gender=$_REQUEST['gender'];
$major=$_REQUEST['major'];
$institute=$_REQUEST['institute'];
$contact=$_REQUEST['contact'];
$email=$_REQUEST['email'];
$current_emp=$_REQUEST['current_emp'];
$current_desig=$_REQUEST['current_desig'];
$current_exp=$_REQUEST['current_exp'];
$total_exp=$_REQUEST['total_exp'];

if (($name) == '' || ($code) == '' ||($qualification) == '' || ($institute) == '' || ($total_exp) == '') {
echo "Field Is Empty Please Fill Complete Form !<br>";
echo "<a href=resume_upload.html>Go Back</a>";
}
else 
{
echo


mysql_connect("localhost","<username>","<password>"); 
mysql_select_db("corporat_kesc") or die("Unable to select database");  

$sql="INSERT INTO data(
code,
candidate_name,
gender,
l_qualification,
major,
l_institute,
contact,email,
current_employer,
current_designation,
current_experience,
total_experirence)

VALUES(
'$code',
'$name',
'$gender',
'$qualification',
'$major',
'$institute',
'$contact',
'$email',
'$current_emp',
'$current_desig',
'$current_exp',
'$total_exp')";
//var_dump($sql);
$result=mysql_query($sql);

echo "<br>Data Has Been Saved.<br>";
echo "<a href=resume_upload.html>Go Back</a>";
}

?>

Here is the code: im saving data through this handler.

please let me know is it right?

and how can I change the auto N/A value in phpmyadmin.

Edited by Dani: Edited to remove username/password

0

That's inserting, not selecting (or fetching as previously mentioned).

Why not just add those fields into your checks on line 15? Though the response that qazplm114477 gave should do the same though I'll reiterate what he stated. If you insert the field into the database with an empty string, it will not be N/A, it will be '' as '' is an empty string and an empty string is not null.

Btw... never post the password/username combo that connects to your database. Please, for your security, always replace it with a uniform set of characters. This lets us know you HAVE a password but are hiding it.

Another thing you could do is when you go to display it, put a check into the display algorithm you're using:

if(fieldname==""){echo"N/A";}else{echo fieldname;}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.