Help - Search - Members - Calendar
Full Version: Help: Cant insert data into table
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
acer2
blushing.gif
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">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><input name="add" type="submit" id="add" value="Add New User"></td>
</tr>
</table>
</form>
</body>
</html>

Hope to get help! blushing.gif
Thanks
Acer
acer2
Well, I'm embarred to say that I had made a little mistake blushing.gif .
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 laugh.gif

wacko.gif thanks anyway.
acer ph34r.gif
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.