Forum Moderators: coopster
It'd be great if someone can tell me where I went wrong.
<?php
$name=$_POST['name'];
$link=$_POST['link'];
$email=$_POST['email'];
$location="localhost";
$username="username";
$password="password";
$database="clickomatic";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");//Create the query
$sql = 'INSERT INTO koc ( id , link , name , email ) '
. ' VALUES ( \"\", \"$link\", \"$name\", \"$email\" );'
. ' ';
//Execute the query
$rs=mysql_query($sql,$conn);
//Confirm the added record details
if($rs) { echo ("Record added: $id $link $name $email"); }
echo "$name $link $email";
?>
//Execute the query
echo "<p>query: ",$sql,"<p>";
$rs=mysql_query($sql,$conn) or die (mysql_error() [ca.php.net]);
This one may fare better:
$sql = 'INSERT INTO koc ( id , link , name , email ) VALUES ( \"\", \"$link\", \"$name\", \"$email\" );';
I do it the opposite(quote-wise):
$sql = "INSERT INTO koc ( id , link , name , email ) VALUES ( '', '" . $link . "', '" . $name' . ", '" . $email . "' )";
Basically, everything between double-quotes is treated as a string and everything between the periods " . $here . " are your PHP vars.
query: INSERT INTO koc ( id , link , name , email ) VALUES ( \"\", \"$link\", \"$name\", \"$email\" );
You have an error in your SQL syntax near '\"\", \"$link\", \"$name\", \"$email\" ); ' at line 1
-------------------------------------------------------
Here is the error using Birdman's query:
query: INSERT INTO koc ( id , link , name , email ) VALUES ( '', 'http://www.kingsofchaos.com/recruit.php?uniqid=e552ufub', 'Rodnak'', 'user@domain.com' )
You have an error in your SQL syntax near 'user@domain.com' )' at line 1
Code for insert.php:
--------------------
<?php
$name=$_POST['name'];
$link=$_POST['link'];
$email=$_POST['email'];
$location="localhost";
$username="username";
$password="password";
$database="databasename";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");//Select the database
$rs = @mysql_select_db("$database", $conn) or die (mysql_error());
//Create the query
$sql = "INSERT INTO koc ( id , link , name , email ) VALUES ( '', ' $link ', ' $name ', ' $email ' )";
//Execute the query
echo "<p>query: ",$sql,"<p>";
$rs=mysql_query($sql,$conn) or die (mysql_error());
//$rs=mysql_query($sql,$conn);
//Confirm the added record details
if($rs) { echo ("Record added: $id $link $name $email"); }
//This is old stuff that didn't work
//mysql_select_db($database,$conn) or die ("Could not open database");
//$query = "INSERT INTO table_name(id,name,link,email VALUES(\"\",\"$name\",\"$link\",\"$email\"))";
// $result=mysql_query($query);
// mysql_close();
echo "$name $link $email";
?>
Code for add.php:
--------------------
<html>
<head>
<title>Add your link</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body>
<form action="insert.php" method="post">
<table width="90%" border="0">
<tr>
<td width="7%">Name: </td>
<td width="93%"><input type="text" name="name" size="30"></td>
</tr>
<tr>
<td>Link: </td>
<td><input type="text" name="link" size="30"></td>
</tr>
<tr>
<td>Email: </td>
<td><input type="text" name="email" size="30"></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="Submit">
</p>
</form>
</body>
</html>