Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,003 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,369 people online right now. Registration is fast and FREE... Join Now!




problem in insert value into mysql through php

 
Reply to this topicStart new topic

problem in insert value into mysql through php

linzhiyi
6 Jan, 2008 - 01:58 AM
Post #1

New D.I.C Head
*

Joined: 8 Dec, 2007
Posts: 20


My Contributions
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>

User is offlineProfile CardPM
+Quote Post

pe_mitev
RE: Problem In Insert Value Into Mysql Through Php
6 Jan, 2008 - 07:08 AM
Post #2

D.I.C Head
Group Icon

Joined: 28 Dec, 2007
Posts: 71


Dream Kudos: 50
My Contributions
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:

CODE
$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: 6 Jan, 2008 - 07:14 AM
User is offlineProfile CardPM
+Quote Post

dontKnowJava
RE: Problem In Insert Value Into Mysql Through Php
6 Jan, 2008 - 09:26 AM
Post #3

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
..

This post has been edited by dontKnowJava: 6 Jan, 2008 - 09:40 AM
User is offlineProfile CardPM
+Quote Post

linzhiyi
RE: Problem In Insert Value Into Mysql Through Php
6 Jan, 2008 - 05:16 PM
Post #4

New D.I.C Head
*

Joined: 8 Dec, 2007
Posts: 20


My Contributions
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

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 12:26PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month