Worqy Posted June 15, 2010 Share Posted June 15, 2010 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 More sharing options...
Bottyz Posted June 15, 2010 Share Posted June 15, 2010 I think we'd need to see code to know whats wrong. Link to comment https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072375 Share on other sites More sharing options...
Worqy Posted June 15, 2010 Author Share Posted June 15, 2010 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 More sharing options...
kenrbnsn Posted June 15, 2010 Share Posted June 15, 2010 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 More sharing options...
Worqy Posted June 15, 2010 Author Share Posted June 15, 2010 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 More sharing options...
kenrbnsn Posted June 15, 2010 Share Posted June 15, 2010 You have an error in the query. If this is the query in question: <?php $sql="SELECT * FROM $database WHERE"; ?> the "where" clause needs a condition. Ken Link to comment https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072588 Share on other sites More sharing options...
Worqy Posted June 15, 2010 Author Share Posted June 15, 2010 How do I solve this then? I tried to remove the WHERE but it didn't help. I just wan't it to select all of them.. Link to comment https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072597 Share on other sites More sharing options...
kenrbnsn Posted June 15, 2010 Share Posted June 15, 2010 Always check for errors on a mysql_query statement: <?php $sql="SELECT * FROM $database WHERE"; $result=mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); ?> BTW, you select from a table not a database. Ken Link to comment https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072601 Share on other sites More sharing options...
Worqy Posted June 15, 2010 Author Share Posted June 15, 2010 Hahaha That was a big misstake/fail from me. Now it works. Thank you! Link to comment https://forums.phpfreaks.com/topic/204851-input-two-words/#findComment-1072602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.