2

I am new to PHP in Ubuntu 13.10. But I am pretty much able to handle Ubuntu. However my question is that I can't add any data to phpmyadmin through a PHP code, though my code is perfect. Because I have the same code in WAMP server, and it worked perfectly. But in Ubuntu I just can't add any data to the database. Below seen is the the code of php file;

<?php
$db_name="mydb";
$table_name="student";
$con=@mysql_connect("localhost",root);
$db=@mysql_select_db($db_name,$con);
$sql="insert into $table_name (name,course,mobile,address)"."values ('$_POST[n1]','$_POST[n2]',$_POST[n3],'$_POST[n4]')";
$r=@mysql_query($sql,$con);
echo "----Insert successfull----,<br><br><hr/>";
echo "<a href=index.html>Back</a>";
?>

Please tell me whether I am wrong or is there is any bug/problem in phpmyadmin.

AzkerM
  • 10,390

4 Answers4

0

I'd try to use the mysql_pconnect(host,user,password) function to connect to the server. About your second problem it sounds to me the php library for apache is not installed or configured correctly. open synaptic and look for any apache-php missing library and as minimum try to (re)install libapache2-mod-php5

Hope it'll help

G.

Januz
  • 74
0

is $_POST[n2] value integer.if not then try to use $_POST['n2']

sohel4r
  • 494
0

in deed that was my fault,when i was trying to input data in the database,in mysql table i typed "First Name","Last Name" but after a certain time i thought the database may not be take spaces in variable name and i type "First_Name","Last_name" and it worked.and i was trying to execute the php file directly as i told before.now i have solved it the file have to execute by localhost. anyways thank you guys,

0

Try Changing your SQL query to this:

$sql = "insert into $table_name ('First Name','Last Name','Course','Address','Mobile','Date of Birth','Email') values ('".$_POST['n2']."','".$_POST['n3']."','".$_POST['n4']."','".$_POST['n5']."','".$_POST['n6']."','".$_POST['n7']."','".$_POST['n8']."')";
Parto
  • 15,647