3 Replies - 1382 Views - Last Post: 06 January 2008 - 06:16 PM Rate Topic: -----

#1 linzhiyi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 08-December 07

problem in insert value into mysql through php

Posted 06 January 2008 - 02:58 AM

i have successed in connecting php with mysql, but i cannot insert value into the mysql through php. please help me.
below is my code

Quote

<?php
$username=$_POST['username'];
$pwd=$_POST['pwd'];
$repeat_pwd=$_POST['repeat_pwd'];
$name=$_POST['name'];
$email=$_POST['email'];
if(!empty($username)){
$db=@new mysqli

("linux3","zongyan.huang","zongyan.huang","zongyanhuang");

if(mysqli_connect_errno()){
echo"connect fail<br>\n";
echo mysqli_connect_error();
exit;
}

insert into t_user

('f_username','f_password','f_name','f_email') values

('$username','$password','$name','$email');

$rs=$db->query($sql);
if(!$rs){
$db->close();
echo 'insert fail';
exit;
}
echo"<font color='red'

size='5'>congulations</font><br>\n";
$db->close();
}
?>

<html>
<head>
<title>regisetr form</title>
</head>
<body>
<?php
if(!empty($username)){
echo "your information is<br>\n";
echo "username:$username<br>\n";
echo "pwd:$pwd<br>\n";
echo "repeat_pwd:$repeat_pwd<br>\n";
echo "name:$name<br>\n";
echo "email:$email<br>\n";
}
?>
<form name="frmRegister" method="post"

action="register.php">
<table width="330" border="0" align="center"

cellpadding="5" bgcolor="#eeeeee">
<tr>
<td width="40%">username</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>password</td>
<td><input name="pwd" type="password" id="pwd"></td>
</tr>
<tr>
<td>repeat password</td>
<td><input name="repeat_pwd" type="password"

id="repeat_pwd"></td>
</tr>
<tr>
<td>name</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>email</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="submit">
<input type="reset" name="reset" value="reset"></td>
</tr>
</table>
</form>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: problem in insert value into mysql through php

#2 pe_mitev  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 28-December 07

Re: problem in insert value into mysql through php

Posted 06 January 2008 - 08:08 AM

You are executing the value of $sql, but what is it?

So, when I put the code into a program, which highlight the code, it appeared immediately.

So put $sql before the text of the query:

$sql = "insert into t_user //note the "

('f_username','f_password','f_name','f_email') values

('$username','$password','$name','$email')"; //also note it here




If there are still problems, print $sql and try to execute it trough PhpMyAdmin. If still error appears, post the strucure of your SQL table and the printed value of $sql and we will try to help.

This post has been edited by pe_mitev: 06 January 2008 - 08:14 AM

Was This Post Helpful? 0
  • +
  • -

#3 dontKnowJava  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 221
  • Joined: 29-September 07

Re: problem in insert value into mysql through php

Posted 06 January 2008 - 10:26 AM

..

This post has been edited by dontKnowJava: 06 January 2008 - 10:40 AM

Was This Post Helpful? 0
  • +
  • -

#4 linzhiyi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 08-December 07

Re: problem in insert value into mysql through php

Posted 06 January 2008 - 06:16 PM

after using your code, it shows MySQL Connected,Database Selected. but after looking at phpMyAdmin, the t_user still didn't have any value, but in fact i have insert some value in the form which should pass to it. please help me. print $sql, i can only got insert into t_user ('f_username','f_password','f_name','f_email') values ('fsdg','','sdg','sdfg')
and the structure of my table is
Field Type Collation Attributes Null Default
f_username varchar(10) latin1_swedish_ci Yes NULL
f_password varchar(10) latin1_swedish_ci Yes NULL
f_name varchar(10) latin1_swedish_ci Yes NULL
f_email varchar(10) latin1_swedish_ci Yes NULL
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1