Jump to content

Help: Cant insert data into table


Recommended Posts

:blushing:

Hi,

I was wondering if someone knows the answer.

I just installed Wamp with: Apache Version : 2.2.8 PHP Version : 5.2.5 and

phpMyAdmin - 2.11.5 with MySQL client version: 5.0.45 and Used PHP extensions: mysqli.

I want to insert data in a table. The table exist in mysql!

I do everything correct but i keep getting this error:

Couldn’t execute query

This is the code:

connect.php

<?php

//connect to database

$server='localhost';

$host='127.0.0.1';

$user='root';

$password='';

$dbname = 'tester';

$cxn = mysqli_connect($host,$user,$password,$dbname)

or die ('Couldn’t connect to server.');

$username = $_POST["username"];

$passwrd = $_POST["passwrd"];

$adres = $_POST["adres"];

$query = 'INSERT INTO test1 (username, passwrd, adres) VALUES ($username, $passwrd, $adres)';

$result = mysqli_query($cxn,$query) or die ('Couldn’t execute query.');

echo "Data inserted in table " . ;

?>

</body>

</html

This is the code for the form: add.php

<html>

<head>

<title> add</title>

</head>

<body>

<form action="adduser.php" method="post">

<table width="400" border="0" cellspacing="1" cellpadding="2">

<tr>

<td width="100">User</td>

<td><input name="username" type="text" id="username"></td>

</tr>

<tr>

<td width="100">Password</td>

<td><input name="passwrd" type="text" id="passwrd"></td>

</tr>

<tr>

<td width="100">adres</td>

<td><input name="adres" type="text" id="adres"></td>

</tr>

<tr>

<td width="100"> </td>

<td> </td>

</tr>

<tr>

<td width="100"> </td>

<td><input name="add" type="submit" id="add" value="Add New User"></td>

</tr>

</table>

</form>

</body>

</html>

Hope to get help! :blushing:

Thanks

Acer

Link to comment
Share on other sites


Well, I'm embarred to say that I had made a little mistake :blushing: .

The first variable was numeric, so the quotes ("username") where wrong. And the rest should have been :

"$passwrd", "$adres")

You can say I solved the problem myself :lol:

:wacko: thanks anyway.

acer :ph34r:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...