Jump to content

Input two words...


Worqy

Recommended Posts

Hi. I have made a system for a company where the user shall fill in there name, adress etc...

Now I tested to write in 1,2,3,4 etc.. in the fields, and everything worked fine.

But when I tested to write in a name, like Paul Andersson, it gives a syntax error.

Why?

// Worqy

 

The fields in the database are "TEXT" so they can store more than 10 letters for example.

Link to comment
https://forums.phpfreaks.com/topic/204851-input-two-words/
Share on other sites

Okey.

<?php
/*
File: invite.php
Maker: ******
Date: 15.6.2010
*/
date_default_timezone_set('Europe/Helsinki');

$host = "************";
$username = "**********";
$password = "***";
$database = "********";
Session_start();
//include 'config.php';

// Connect to MySQL server
$con = mysql_connect($host, $username, $password);
if(!$con) 
{
echo "Error connecting to database";
}
// Select MySQL database
$db = mysql_select_db($database, $con);
if(!$db)
{
echo "Error selecting database";
}

//Impoort all values
$namn=$_POST['txtnamn'];
$adress=$_POST['txtadress'];
$postnummer=$_POST['txtpostnummer'];
$ort=$_POST['txtort'];
$land=$_POST['txtland'];
$foretag=$_POST['txtföretag'];
$mail=$_POST['txtmail'];
$telefon=$_POST['txttelefon'];
$ålder=$_POST['txtålder'];
$text=$_POST['txttext'];
$allergier=$_POST['txtallergier'];
$ovrigt=$_POST['txtöverigt'];


// Set date
$date = date("j. n. Y");                    

mysql_query("INSERT INTO invite (Namn, Adress, Postnummer, Ort, Land, Företag, Mail, Telefon, Ålder, Text, Allergier, Ovrigt, Datum) VALUES($namn, $adress, $postnummer, $ort, $land, $foretag, $mail, $telefon, $ålder, $text, $allergier, $ovrigt, $date) ") or die(mysql_error());  

header("Location:done.php");
exit;

?>

Link to comment
https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072568
Share on other sites

You need to put single quotes around all text data in your query:

<?php
mysql_query("INSERT INTO invite (Namn, Adress, Postnummer, Ort, Land, Företag, Mail, Telefon, Ålder, Text, Allergier, Ovrigt, Datum) VALUES('$namn', '$adress', '$postnummer', '$ort', '$land', '$foretag', '$mail', '$telefon', '$ålder', '$text', '$allergier', '$ovrigt', '$date') ") or die(mysql_error());
?>

 

Ken

 

Link to comment
https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072571
Share on other sites

Okey. Thank you.

Now can you tell me why this isn't working. I get the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a7838708/public_html/Kampanj/load.php  on line 29

 

<?php
/*
File: load.php
Maker: ****
Date: 15.6.2010
*/

$pass=$_POST['txtpass'];
if($pass == "****")
{

include '***.php';

// Connect to MySQL server
$con = mysql_connect($host, $username, $password);
if(!$con) 
{
echo "Error connecting to database";
}
// Select MySQL database
$db = mysql_select_db($database, $con);
if(!$db)
{
echo "Error selecting database";
}

$sql="SELECT * FROM $database WHERE";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result))
{
?>
<html>
<body>
<table>
<tr>
<td>Namn:</td>
<td><?php echo $rows['Namn']; ?></td>
</tr>
<tr>
<td>Adress:</td>
</tr>
<tr>
<td>Postnummer:</td>
</tr>
<tr>
<td>Ort:</td>
</tr>
<tr>
<td>Land:</td>
</tr>
<tr>
<td>Ev.företag:</td>
</tr>
<tr>
<td>E-mail:</td>
</tr>
<tr>
<td>Telefon:</td>
</tr>
<tr>
<td>Ålder:</td>
</tr>
<tr>
<td>Varför vill du komma:</td>
</tr>
<tr>
<td>Alleriger:</td>
</tr>
<tr>
<td>Övrigt:</td>
</tr>
</table>
</body>
</html>
<?php
}



}else{
header("Location:login.php");
exit;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072583
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.